HTMLVideoElement.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. };
  31. CachedLayoutBoxes& cached_layout_boxes(Badge<Painting::VideoPaintable>) const { return m_layout_boxes; }
  32. private:
  33. HTMLVideoElement(DOM::Document&, DOM::QualifiedName);
  34. virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
  35. virtual void visit_edges(Cell::Visitor&) override;
  36. virtual JS::GCPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>) override;
  37. virtual void on_playing() override;
  38. virtual void on_paused() override;
  39. virtual void on_seek(double, MediaSeekMode) override;
  40. JS::GCPtr<HTML::VideoTrack> m_video_track;
  41. RefPtr<Gfx::Bitmap> m_current_frame;
  42. u32 m_video_width { 0 };
  43. u32 m_video_height { 0 };
  44. // Cached state for layout
  45. Optional<CSSPixelPoint> m_mouse_position;
  46. mutable CachedLayoutBoxes m_layout_boxes;
  47. };
  48. }