/src/serenity/Userland/Libraries/LibWeb/Layout/VideoBox.cpp
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #include <LibWeb/HTML/HTMLVideoElement.h> |
8 | | #include <LibWeb/Layout/VideoBox.h> |
9 | | #include <LibWeb/Painting/VideoPaintable.h> |
10 | | |
11 | | namespace Web::Layout { |
12 | | |
13 | | JS_DEFINE_ALLOCATOR(VideoBox); |
14 | | |
15 | | VideoBox::VideoBox(DOM::Document& document, DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> style) |
16 | 0 | : ReplacedBox(document, element, move(style)) |
17 | 0 | { |
18 | 0 | document.register_viewport_client(*this); |
19 | 0 | } |
20 | | |
21 | | void VideoBox::finalize() |
22 | 0 | { |
23 | 0 | Base::finalize(); |
24 | | |
25 | | // NOTE: We unregister from the document in finalize() to avoid trouble |
26 | | // in the scenario where our Document has already been swept by GC. |
27 | 0 | document().unregister_viewport_client(*this); |
28 | 0 | } |
29 | | |
30 | | HTML::HTMLVideoElement& VideoBox::dom_node() |
31 | 0 | { |
32 | 0 | return static_cast<HTML::HTMLVideoElement&>(ReplacedBox::dom_node()); |
33 | 0 | } |
34 | | |
35 | | HTML::HTMLVideoElement const& VideoBox::dom_node() const |
36 | 0 | { |
37 | 0 | return static_cast<HTML::HTMLVideoElement const&>(ReplacedBox::dom_node()); |
38 | 0 | } |
39 | | |
40 | | void VideoBox::prepare_for_replaced_layout() |
41 | 0 | { |
42 | 0 | CSSPixels width = dom_node().video_width(); |
43 | 0 | set_natural_width(width); |
44 | |
|
45 | 0 | CSSPixels height = dom_node().video_height(); |
46 | 0 | set_natural_height(height); |
47 | |
|
48 | 0 | if (width != 0 && height != 0) |
49 | 0 | set_natural_aspect_ratio(width / height); |
50 | 0 | else |
51 | 0 | set_natural_aspect_ratio({}); |
52 | 0 | } |
53 | | |
54 | | void VideoBox::did_set_viewport_rect(CSSPixelRect const&) |
55 | 0 | { |
56 | | // FIXME: Several steps in HTMLMediaElement indicate we may optionally handle whether the media object |
57 | | // is in view. Implement those steps. |
58 | 0 | } |
59 | | |
60 | | JS::GCPtr<Painting::Paintable> VideoBox::create_paintable() const |
61 | 0 | { |
62 | 0 | return Painting::VideoPaintable::create(*this); |
63 | 0 | } |
64 | | |
65 | | } |