HTMLVideoElement.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Optional.h>
  8. #include <LibGfx/Forward.h>
  9. #include <LibGfx/Rect.h>
  10. #include <LibWeb/DOM/DocumentLoadEventDelayer.h>
  11. #include <LibWeb/Forward.h>
  12. #include <LibWeb/HTML/HTMLMediaElement.h>
  13. #include <LibWeb/PixelUnits.h>
  14. #include <LibWeb/WebIDL/ExceptionOr.h>
  15. namespace Web::HTML {
  16. struct VideoFrame {
  17. RefPtr<Gfx::Bitmap> frame;
  18. double position { 0.0 };
  19. };
  20. class HTMLVideoElement final : public HTMLMediaElement {
  21. WEB_PLATFORM_OBJECT(HTMLVideoElement, HTMLMediaElement);
  22. public:
  23. virtual ~HTMLVideoElement() override;
  24. Layout::VideoBox* layout_node();
  25. Layout::VideoBox const* layout_node() const;
  26. void set_video_width(u32 video_width) { m_video_width = video_width; }
  27. u32 video_width() const;
  28. void set_video_height(u32 video_height) { m_video_height = video_height; }
  29. u32 video_height() const;
  30. void set_video_track(JS::GCPtr<VideoTrack>);
  31. void set_current_frame(Badge<VideoTrack>, RefPtr<Gfx::Bitmap> frame, double position);
  32. VideoFrame const& current_frame() const { return m_current_frame; }
  33. RefPtr<Gfx::Bitmap> const& poster_frame() const { return m_poster_frame; }
  34. void set_layout_mouse_position(Badge<Painting::VideoPaintable>, Optional<CSSPixelPoint> mouse_position) { m_mouse_position = move(mouse_position); }
  35. Optional<CSSPixelPoint> const& layout_mouse_position(Badge<Painting::VideoPaintable>) const { return m_mouse_position; }
  36. struct CachedLayoutBoxes {
  37. Optional<CSSPixelRect> control_box_rect;
  38. Optional<CSSPixelRect> playback_button_rect;
  39. Optional<CSSPixelRect> timeline_rect;
  40. };
  41. CachedLayoutBoxes& cached_layout_boxes(Badge<Painting::VideoPaintable>) const { return m_layout_boxes; }
  42. private:
  43. HTMLVideoElement(DOM::Document&, DOM::QualifiedName);
  44. virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
  45. virtual void visit_edges(Cell::Visitor&) override;
  46. virtual void parse_attribute(DeprecatedFlyString const& name, DeprecatedString const& value) override;
  47. virtual void did_remove_attribute(DeprecatedFlyString const&) override;
  48. virtual JS::GCPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>) override;
  49. virtual void on_playing() override;
  50. virtual void on_paused() override;
  51. virtual void on_seek(double, MediaSeekMode) override;
  52. WebIDL::ExceptionOr<void> determine_element_poster_frame(Optional<StringView> const& poster);
  53. JS::GCPtr<HTML::VideoTrack> m_video_track;
  54. VideoFrame m_current_frame;
  55. RefPtr<Gfx::Bitmap> m_poster_frame;
  56. u32 m_video_width { 0 };
  57. u32 m_video_height { 0 };
  58. JS::GCPtr<Fetch::Infrastructure::FetchController> m_fetch_controller;
  59. Optional<DOM::DocumentLoadEventDelayer> m_load_event_delayer;
  60. // Cached state for layout
  61. Optional<CSSPixelPoint> m_mouse_position;
  62. mutable CachedLayoutBoxes m_layout_boxes;
  63. };
  64. }