mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2026-04-19 02:10:26 +00:00
Instead, compute them on demand. This affects ReplacedBox and its subclasses. This commit is centered around a new Box::auto_content_box_size method. It returns a SizeWithAspectRatio representing the natural size of a replaced element, or the size derived from attributes for text input and textarea. These values are used when the corresponding axis is auto or indefinite. Although introducing this API choke-point for sizing replaced and replaced-like elements was the main goal, it's notable that layout becomes more robust in the face of dynamic changes due to reduced potential for stale size values (at the cost of extra calculations and allocations).
60 lines
1.6 KiB
C++
60 lines
1.6 KiB
C++
/*
|
|
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibWeb/HTML/HTMLVideoElement.h>
|
|
#include <LibWeb/Layout/VideoBox.h>
|
|
#include <LibWeb/Painting/VideoPaintable.h>
|
|
|
|
namespace Web::Layout {
|
|
|
|
GC_DEFINE_ALLOCATOR(VideoBox);
|
|
|
|
VideoBox::VideoBox(DOM::Document& document, DOM::Element& element, GC::Ref<CSS::ComputedProperties> style)
|
|
: ReplacedBox(document, element, move(style))
|
|
{
|
|
document.register_viewport_client(*this);
|
|
}
|
|
|
|
void VideoBox::finalize()
|
|
{
|
|
Base::finalize();
|
|
|
|
// NOTE: We unregister from the document in finalize() to avoid trouble
|
|
// in the scenario where our Document has already been swept by GC.
|
|
document().unregister_viewport_client(*this);
|
|
}
|
|
|
|
HTML::HTMLVideoElement& VideoBox::dom_node()
|
|
{
|
|
return static_cast<HTML::HTMLVideoElement&>(*ReplacedBox::dom_node());
|
|
}
|
|
|
|
HTML::HTMLVideoElement const& VideoBox::dom_node() const
|
|
{
|
|
return static_cast<HTML::HTMLVideoElement const&>(*ReplacedBox::dom_node());
|
|
}
|
|
|
|
CSS::SizeWithAspectRatio VideoBox::natural_size() const
|
|
{
|
|
CSSPixels width = dom_node().video_width();
|
|
CSSPixels height = dom_node().video_height();
|
|
if (width > 0 && height > 0)
|
|
return { width, height, CSSPixelFraction(width, height) };
|
|
return { width, height, {} };
|
|
}
|
|
|
|
void VideoBox::did_set_viewport_rect(CSSPixelRect const&)
|
|
{
|
|
// FIXME: Several steps in HTMLMediaElement indicate we may optionally handle whether the media object
|
|
// is in view. Implement those steps.
|
|
}
|
|
|
|
GC::Ptr<Painting::Paintable> VideoBox::create_paintable() const
|
|
{
|
|
return Painting::VideoPaintable::create(*this);
|
|
}
|
|
|
|
}
|