HTMLVideoElement.h 2.9 KB

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