ladybird/Libraries/LibWeb/Layout/ReplacedBox.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

34 lines
918 B
C++

/*
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/DOM/Element.h>
#include <LibWeb/Layout/Box.h>
namespace Web::Layout {
class ReplacedBox : public Box {
GC_CELL(ReplacedBox, Box);
public:
ReplacedBox(DOM::Document&, GC::Ptr<DOM::Element>, GC::Ref<CSS::ComputedProperties>);
virtual ~ReplacedBox() override;
GC::Ptr<DOM::Element const> dom_node() const { return as<DOM::Element>(Node::dom_node()); }
GC::Ptr<DOM::Element> dom_node() { return as<DOM::Element>(Node::dom_node()); }
virtual bool can_have_children() const override { return false; }
private:
virtual bool is_replaced_box() const final { return true; }
virtual bool has_auto_content_box_size() const override { return true; }
};
template<>
inline bool Node::fast_is<ReplacedBox>() const { return is_replaced_box(); }
}