1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 03:18:11 +00:00

LibWeb: Compute element style in Layout::TreeBuilder

Instead of making each Layout::Node compute style for itself, we now
compute it in TreeBuilder before even calling create_layout_node().

For non-element DOM nodes, we create the style and layout tree node
in TreeBuilder. This allows us to move create_layout_node() from
DOM::Node to DOM::Element.
This commit is contained in:
Andreas Kling 2022-02-05 13:17:01 +01:00
parent 3451673ac8
commit 7e1bf4d300
31 changed files with 48 additions and 91 deletions

View file

@ -90,7 +90,26 @@ void TreeBuilder::create_layout_tree(DOM::Node& dom_node, TreeBuilder::Context&
return;
}
auto layout_node = dom_node.create_layout_node();
auto& document = dom_node.document();
auto& style_computer = document.style_computer();
RefPtr<Layout::Node> layout_node;
if (is<DOM::Element>(dom_node)) {
auto& element = static_cast<DOM::Element&>(dom_node);
auto style = style_computer.compute_style(element);
if (style->display().is_none())
return;
element.set_specified_css_values(style);
layout_node = element.create_layout_node(move(style));
} else if (is<DOM::Document>(dom_node)) {
auto style = style_computer.create_document_style();
layout_node = adopt_ref(*new Layout::InitialContainingBlock(static_cast<DOM::Document&>(dom_node), move(style)));
} else if (is<DOM::Text>(dom_node)) {
layout_node = adopt_ref(*new Layout::TextNode(document, static_cast<DOM::Text&>(dom_node)));
} else if (is<DOM::ShadowRoot>(dom_node)) {
layout_node = adopt_ref(*new Layout::BlockContainer(document, &static_cast<DOM::ShadowRoot&>(dom_node), CSS::ComputedValues {}));
}
if (!layout_node)
return;