HTMLVideoElement.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. GC_DECLARE_ALLOCATOR(HTMLVideoElement);
  21. public:
  22. virtual ~HTMLVideoElement() override;
  23. Layout::VideoBox* layout_node();
  24. Layout::VideoBox const* layout_node() const;
  25. void set_video_width(u32 video_width) { m_video_width = video_width; }
  26. u32 video_width() const;
  27. void set_video_height(u32 video_height) { m_video_height = video_height; }
  28. u32 video_height() const;
  29. void set_video_track(GC::Ptr<VideoTrack>);
  30. void set_current_frame(Badge<VideoTrack>, RefPtr<Gfx::Bitmap> frame, double position);
  31. VideoFrame const& current_frame() const { return m_current_frame; }
  32. RefPtr<Gfx::Bitmap> const& poster_frame() const { return m_poster_frame; }
  33. // FIXME: This is a hack for images used as CanvasImageSource. Do something more elegant.
  34. RefPtr<Gfx::Bitmap> bitmap() const
  35. {
  36. return current_frame().frame;
  37. }
  38. private:
  39. HTMLVideoElement(DOM::Document&, DOM::QualifiedName);
  40. virtual void initialize(JS::Realm&) override;
  41. virtual void finalize() override;
  42. virtual void visit_edges(Cell::Visitor&) override;
  43. virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_) override;
  44. // https://html.spec.whatwg.org/multipage/media.html#the-video-element:dimension-attributes
  45. virtual bool supports_dimension_attributes() const override { return true; }
  46. virtual GC::Ptr<Layout::Node> create_layout_node(CSS::StyleProperties) override;
  47. virtual void adjust_computed_style(CSS::StyleProperties&) override;
  48. virtual void on_playing() override;
  49. virtual void on_paused() override;
  50. virtual void on_seek(double, MediaSeekMode) override;
  51. WebIDL::ExceptionOr<void> determine_element_poster_frame(Optional<String> const& poster);
  52. GC::Ptr<HTML::VideoTrack> m_video_track;
  53. VideoFrame m_current_frame;
  54. RefPtr<Gfx::Bitmap> m_poster_frame;
  55. u32 m_video_width { 0 };
  56. u32 m_video_height { 0 };
  57. GC::Ptr<Fetch::Infrastructure::FetchController> m_fetch_controller;
  58. Optional<DOM::DocumentLoadEventDelayer> m_load_event_delayer;
  59. };
  60. }