1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 05:17:34 +00:00

LibWeb: Improve how layout nodes decide whether they have definite sizes

1. Make this decision *after* we've inserted the layout node into the
   layout tree. Otherwise, we can't reach its containing block!
2. Per css-sizing-3, consider auto-sized blocks whose sizes resolve
   solely against other definite sizes as definite themselves.

In particular, (2) makes us consider width:auto block children of a
definite-size containing block as having definite size. This becomes
very important in flex layout.
This commit is contained in:
Andreas Kling 2022-03-12 13:24:58 +01:00
parent d201378750
commit 12ac6861e3
3 changed files with 47 additions and 25 deletions

View file

@ -96,18 +96,19 @@ void TreeBuilder::create_layout_tree(DOM::Node& dom_node, TreeBuilder::Context&
auto& document = dom_node.document();
auto& style_computer = document.style_computer();
RefPtr<Layout::Node> layout_node;
RefPtr<CSS::StyleProperties> style;
if (is<DOM::Element>(dom_node)) {
auto& element = static_cast<DOM::Element&>(dom_node);
element.clear_pseudo_element_nodes({});
auto style = style_computer.compute_style(element);
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));
layout_node = element.create_layout_node(*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)));
style = style_computer.create_document_style();
layout_node = adopt_ref(*new Layout::InitialContainingBlock(static_cast<DOM::Document&>(dom_node), *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)) {
@ -150,6 +151,9 @@ void TreeBuilder::create_layout_tree(DOM::Node& dom_node, TreeBuilder::Context&
insert_node_into_inline_or_block_ancestor(layout_node);
}
if (layout_node->has_style() && style)
static_cast<Layout::NodeWithStyle&>(*layout_node).did_insert_into_layout_tree(*style);
auto* shadow_root = is<DOM::Element>(dom_node) ? verify_cast<DOM::Element>(dom_node).shadow_root() : nullptr;
if ((dom_node.has_children() || shadow_root) && layout_node->can_have_children()) {