HTMLVideoElement.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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/Forward.h>
  10. #include <LibWeb/HTML/HTMLMediaElement.h>
  11. namespace Web::HTML {
  12. class HTMLVideoElement final : public HTMLMediaElement {
  13. WEB_PLATFORM_OBJECT(HTMLVideoElement, HTMLMediaElement);
  14. public:
  15. virtual ~HTMLVideoElement() override;
  16. Layout::VideoBox* layout_node();
  17. Layout::VideoBox const* layout_node() const;
  18. void set_video_width(u32 video_width) { m_video_width = video_width; }
  19. u32 video_width() const;
  20. void set_video_height(u32 video_height) { m_video_height = video_height; }
  21. u32 video_height() const;
  22. void set_video_track(JS::GCPtr<VideoTrack>);
  23. void set_current_frame(Badge<VideoTrack>, RefPtr<Gfx::Bitmap> frame);
  24. RefPtr<Gfx::Bitmap> const& current_frame() const { return m_current_frame; }
  25. void set_layout_mouse_position(Badge<Painting::VideoPaintable>, Optional<CSSPixelPoint> mouse_position) { m_mouse_position = move(mouse_position); }
  26. Optional<CSSPixelPoint> const& layout_mouse_position(Badge<Painting::VideoPaintable>) const { return m_mouse_position; }
  27. struct CachedLayoutBoxes {
  28. Optional<CSSPixelRect> control_box_rect;
  29. Optional<CSSPixelRect> playback_button_rect;
  30. Optional<CSSPixelRect> timeline_rect;
  31. };
  32. CachedLayoutBoxes& cached_layout_boxes(Badge<Painting::VideoPaintable>) const { return m_layout_boxes; }
  33. private:
  34. HTMLVideoElement(DOM::Document&, DOM::QualifiedName);
  35. virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
  36. virtual void visit_edges(Cell::Visitor&) override;
  37. virtual JS::GCPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>) override;
  38. virtual void on_playing() override;
  39. virtual void on_paused() override;
  40. virtual void on_seek(double, MediaSeekMode) override;
  41. JS::GCPtr<HTML::VideoTrack> m_video_track;
  42. RefPtr<Gfx::Bitmap> m_current_frame;
  43. u32 m_video_width { 0 };
  44. u32 m_video_height { 0 };
  45. // Cached state for layout
  46. Optional<CSSPixelPoint> m_mouse_position;
  47. mutable CachedLayoutBoxes m_layout_boxes;
  48. };
  49. }