1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:58:11 +00:00

LibWeb: Start making our layout system "transactional"

This patch adds a map of Layout::Node to FormattingState::NodeState.
Instead of updating layout nodes incrementally as layout progresses
through the formatting contexts, all updates are now written to the
corresponding NodeState instead.

At the end of layout, FormattingState::commit() is called, which
transfers all the values from the NodeState objects to the Node.

This will soon allow us to perform completely non-destructive layouts
which don't affect the tree.

Note that there are many imperfections here, and still many places
where we assign to the NodeState, but later read directly from the Node
instead. I'm just committing at this stage to make subsequent diffs
easier to understand.
This commit is contained in:
Andreas Kling 2022-02-20 15:51:24 +01:00
parent 561612f219
commit c9700e100e
27 changed files with 754 additions and 571 deletions

View file

@ -11,7 +11,7 @@
namespace Web::Layout {
SVGFormattingContext::SVGFormattingContext(FormattingState& state, Box& box, FormattingContext* parent)
SVGFormattingContext::SVGFormattingContext(FormattingState& state, Box const& box, FormattingContext* parent)
: FormattingContext(Type::SVG, state, box, parent)
{
}
@ -20,20 +20,22 @@ SVGFormattingContext::~SVGFormattingContext()
{
}
void SVGFormattingContext::run(Box& box, LayoutMode)
void SVGFormattingContext::run(Box const& box, LayoutMode)
{
box.for_each_in_subtree_of_type<SVGBox>([&](auto& descendant) {
box.for_each_in_subtree_of_type<SVGBox>([&](auto const& descendant) {
if (is<SVGGeometryBox>(descendant)) {
auto& geometry_box = static_cast<SVGGeometryBox&>(descendant);
auto& path = geometry_box.dom_node().get_path();
auto const& geometry_box = static_cast<SVGGeometryBox const&>(descendant);
auto& path = const_cast<SVGGeometryBox&>(geometry_box).dom_node().get_path();
auto bounding_box = path.bounding_box();
// Stroke increases the path's size by stroke_width/2 per side.
auto stroke_width = geometry_box.dom_node().stroke_width().value_or(0);
bounding_box.inflate(stroke_width, stroke_width);
geometry_box.set_offset(bounding_box.top_left());
geometry_box.set_content_size(bounding_box.size());
auto& geometry_box_state = m_state.ensure(geometry_box);
geometry_box_state.offset = bounding_box.top_left();
geometry_box_state.content_width = bounding_box.width();
geometry_box_state.content_height = bounding_box.height();
}
return IterationDecision::Continue;