/src/serenity/Userland/Libraries/LibWeb/HTML/HTMLVideoElement.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2020, the SerenityOS developers. |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <AK/Optional.h> |
10 | | #include <LibGfx/Forward.h> |
11 | | #include <LibWeb/DOM/DocumentLoadEventDelayer.h> |
12 | | #include <LibWeb/Forward.h> |
13 | | #include <LibWeb/HTML/HTMLMediaElement.h> |
14 | | #include <LibWeb/WebIDL/ExceptionOr.h> |
15 | | |
16 | | namespace Web::HTML { |
17 | | |
18 | | struct VideoFrame { |
19 | | RefPtr<Gfx::Bitmap> frame; |
20 | | double position { 0.0 }; |
21 | | }; |
22 | | |
23 | | class HTMLVideoElement final : public HTMLMediaElement { |
24 | | WEB_PLATFORM_OBJECT(HTMLVideoElement, HTMLMediaElement); |
25 | | JS_DECLARE_ALLOCATOR(HTMLVideoElement); |
26 | | |
27 | | public: |
28 | | virtual ~HTMLVideoElement() override; |
29 | | |
30 | | Layout::VideoBox* layout_node(); |
31 | | Layout::VideoBox const* layout_node() const; |
32 | | |
33 | 0 | void set_video_width(u32 video_width) { m_video_width = video_width; } |
34 | | u32 video_width() const; |
35 | | |
36 | 0 | void set_video_height(u32 video_height) { m_video_height = video_height; } |
37 | | u32 video_height() const; |
38 | | |
39 | | void set_video_track(JS::GCPtr<VideoTrack>); |
40 | | |
41 | | void set_current_frame(Badge<VideoTrack>, RefPtr<Gfx::Bitmap> frame, double position); |
42 | 0 | VideoFrame const& current_frame() const { return m_current_frame; } |
43 | 0 | RefPtr<Gfx::Bitmap> const& poster_frame() const { return m_poster_frame; } |
44 | | |
45 | | // FIXME: This is a hack for images used as CanvasImageSource. Do something more elegant. |
46 | | RefPtr<Gfx::Bitmap> bitmap() const |
47 | 0 | { |
48 | 0 | return current_frame().frame; |
49 | 0 | } |
50 | | |
51 | | private: |
52 | | HTMLVideoElement(DOM::Document&, DOM::QualifiedName); |
53 | | |
54 | | virtual void initialize(JS::Realm&) override; |
55 | | virtual void finalize() override; |
56 | | virtual void visit_edges(Cell::Visitor&) override; |
57 | | |
58 | | virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value) override; |
59 | | |
60 | | // https://html.spec.whatwg.org/multipage/media.html#the-video-element:dimension-attributes |
61 | 0 | virtual bool supports_dimension_attributes() const override { return true; } |
62 | | |
63 | | virtual JS::GCPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>) override; |
64 | | |
65 | | virtual void on_playing() override; |
66 | | virtual void on_paused() override; |
67 | | virtual void on_seek(double, MediaSeekMode) override; |
68 | | |
69 | | WebIDL::ExceptionOr<void> determine_element_poster_frame(Optional<String> const& poster); |
70 | | |
71 | | JS::GCPtr<HTML::VideoTrack> m_video_track; |
72 | | VideoFrame m_current_frame; |
73 | | RefPtr<Gfx::Bitmap> m_poster_frame; |
74 | | |
75 | | u32 m_video_width { 0 }; |
76 | | u32 m_video_height { 0 }; |
77 | | |
78 | | JS::GCPtr<Fetch::Infrastructure::FetchController> m_fetch_controller; |
79 | | Optional<DOM::DocumentLoadEventDelayer> m_load_event_delayer; |
80 | | }; |
81 | | |
82 | | } |