ladybird/Libraries/LibWeb/Layout/VideoBox.h
Jonathan Gamble ec50525675 LibWeb/Layout: Don't inject natural size in prepare_for_replaced_layout
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).
2026-02-02 14:36:49 +00:00

40 lines
967 B
C++

/*
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/DOM/Document.h>
#include <LibWeb/Forward.h>
#include <LibWeb/Layout/ReplacedBox.h>
namespace Web::Layout {
class VideoBox final
: public ReplacedBox
, public DOM::Document::ViewportClient {
GC_CELL(VideoBox, ReplacedBox);
GC_DECLARE_ALLOCATOR(VideoBox);
public:
static constexpr bool OVERRIDES_FINALIZE = true;
HTML::HTMLVideoElement& dom_node();
HTML::HTMLVideoElement const& dom_node() const;
virtual GC::Ptr<Painting::Paintable> create_paintable() const override;
private:
VideoBox(DOM::Document&, DOM::Element&, GC::Ref<CSS::ComputedProperties>);
virtual CSS::SizeWithAspectRatio natural_size() const override;
// ^Document::ViewportClient
virtual void did_set_viewport_rect(CSSPixelRect const&) final;
// ^JS::Cell
virtual void finalize() override;
};
}