mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:27:43 +00:00
LibWeb: Base Layout::TreeBuilder decisions on CSS display property
This is one of many small steps towards being able to remove the ad-hoc Layout::Node::is_inline() in favor of honoring the CSS display value everywhere instead.
This commit is contained in:
parent
1ab7a8e0db
commit
fe03149a47
2 changed files with 12 additions and 7 deletions
|
@ -110,9 +110,9 @@ static Layout::Node& insertion_parent_for_block_node(Layout::NodeWithStyle& layo
|
||||||
return layout_parent;
|
return layout_parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TreeBuilder::insert_node_into_inline_or_block_ancestor(Layout::Node& node, AppendOrPrepend mode)
|
void TreeBuilder::insert_node_into_inline_or_block_ancestor(Layout::Node& node, CSS::Display display, AppendOrPrepend mode)
|
||||||
{
|
{
|
||||||
if (node.is_inline() && !(node.is_inline_block() && m_ancestor_stack.last().computed_values().display().is_flex_inside())) {
|
if (display.is_inline_outside() && !(display.is_flow_root_inside() && m_ancestor_stack.last().computed_values().display().is_flex_inside())) {
|
||||||
// Inlines can be inserted into the nearest ancestor.
|
// Inlines can be inserted into the nearest ancestor.
|
||||||
auto& insertion_point = insertion_parent_for_inline_node(m_ancestor_stack.last());
|
auto& insertion_point = insertion_parent_for_inline_node(m_ancestor_stack.last());
|
||||||
if (mode == AppendOrPrepend::Prepend)
|
if (mode == AppendOrPrepend::Prepend)
|
||||||
|
@ -166,14 +166,14 @@ void TreeBuilder::create_pseudo_element_if_needed(DOM::Element& element, CSS::Se
|
||||||
auto* text = document.heap().allocate<DOM::Text>(document.realm(), document, pseudo_element_content.data);
|
auto* text = document.heap().allocate<DOM::Text>(document.realm(), document, pseudo_element_content.data);
|
||||||
auto text_node = adopt_ref(*new TextNode(document, *text));
|
auto text_node = adopt_ref(*new TextNode(document, *text));
|
||||||
push_parent(verify_cast<NodeWithStyle>(*pseudo_element_node));
|
push_parent(verify_cast<NodeWithStyle>(*pseudo_element_node));
|
||||||
insert_node_into_inline_or_block_ancestor(text_node, AppendOrPrepend::Append);
|
insert_node_into_inline_or_block_ancestor(text_node, pseudo_element_display, AppendOrPrepend::Append);
|
||||||
pop_parent();
|
pop_parent();
|
||||||
} else {
|
} else {
|
||||||
TODO();
|
TODO();
|
||||||
}
|
}
|
||||||
|
|
||||||
element.set_pseudo_element_node({}, CSS::Selector::PseudoElement::Before, pseudo_element_node);
|
element.set_pseudo_element_node({}, CSS::Selector::PseudoElement::Before, pseudo_element_node);
|
||||||
insert_node_into_inline_or_block_ancestor(*pseudo_element_node, mode);
|
insert_node_into_inline_or_block_ancestor(*pseudo_element_node, pseudo_element_display, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TreeBuilder::create_layout_tree(DOM::Node& dom_node, TreeBuilder::Context& context)
|
void TreeBuilder::create_layout_tree(DOM::Node& dom_node, TreeBuilder::Context& context)
|
||||||
|
@ -194,22 +194,27 @@ void TreeBuilder::create_layout_tree(DOM::Node& dom_node, TreeBuilder::Context&
|
||||||
auto& style_computer = document.style_computer();
|
auto& style_computer = document.style_computer();
|
||||||
RefPtr<Layout::Node> layout_node;
|
RefPtr<Layout::Node> layout_node;
|
||||||
RefPtr<CSS::StyleProperties> style;
|
RefPtr<CSS::StyleProperties> style;
|
||||||
|
CSS::Display display;
|
||||||
|
|
||||||
if (is<DOM::Element>(dom_node)) {
|
if (is<DOM::Element>(dom_node)) {
|
||||||
auto& element = static_cast<DOM::Element&>(dom_node);
|
auto& element = static_cast<DOM::Element&>(dom_node);
|
||||||
element.clear_pseudo_element_nodes({});
|
element.clear_pseudo_element_nodes({});
|
||||||
VERIFY(!element.needs_style_update());
|
VERIFY(!element.needs_style_update());
|
||||||
style = element.computed_css_values();
|
style = element.computed_css_values();
|
||||||
if (style->display().is_none())
|
display = style->display();
|
||||||
|
if (display.is_none())
|
||||||
return;
|
return;
|
||||||
layout_node = element.create_layout_node(*style);
|
layout_node = element.create_layout_node(*style);
|
||||||
} else if (is<DOM::Document>(dom_node)) {
|
} else if (is<DOM::Document>(dom_node)) {
|
||||||
style = style_computer.create_document_style();
|
style = style_computer.create_document_style();
|
||||||
|
display = style->display();
|
||||||
layout_node = adopt_ref(*new Layout::InitialContainingBlock(static_cast<DOM::Document&>(dom_node), *style));
|
layout_node = adopt_ref(*new Layout::InitialContainingBlock(static_cast<DOM::Document&>(dom_node), *style));
|
||||||
} else if (is<DOM::Text>(dom_node)) {
|
} else if (is<DOM::Text>(dom_node)) {
|
||||||
layout_node = adopt_ref(*new Layout::TextNode(document, static_cast<DOM::Text&>(dom_node)));
|
layout_node = adopt_ref(*new Layout::TextNode(document, static_cast<DOM::Text&>(dom_node)));
|
||||||
|
display = CSS::Display(CSS::Display::Outside::Inline, CSS::Display::Inside::Flow);
|
||||||
} else if (is<DOM::ShadowRoot>(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 {}));
|
layout_node = adopt_ref(*new Layout::BlockContainer(document, &static_cast<DOM::ShadowRoot&>(dom_node), CSS::ComputedValues {}));
|
||||||
|
display = CSS::Display(CSS::Display::Outside::Block, CSS::Display::Inside::FlowRoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!layout_node)
|
if (!layout_node)
|
||||||
|
@ -220,7 +225,7 @@ void TreeBuilder::create_layout_tree(DOM::Node& dom_node, TreeBuilder::Context&
|
||||||
} else if (layout_node->is_svg_box()) {
|
} else if (layout_node->is_svg_box()) {
|
||||||
m_ancestor_stack.last().append_child(*layout_node);
|
m_ancestor_stack.last().append_child(*layout_node);
|
||||||
} else {
|
} else {
|
||||||
insert_node_into_inline_or_block_ancestor(*layout_node, AppendOrPrepend::Append);
|
insert_node_into_inline_or_block_ancestor(*layout_node, display, AppendOrPrepend::Append);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* shadow_root = is<DOM::Element>(dom_node) ? verify_cast<DOM::Element>(dom_node).shadow_root() : nullptr;
|
auto* shadow_root = is<DOM::Element>(dom_node) ? verify_cast<DOM::Element>(dom_node).shadow_root() : nullptr;
|
||||||
|
|
|
@ -44,7 +44,7 @@ private:
|
||||||
Append,
|
Append,
|
||||||
Prepend,
|
Prepend,
|
||||||
};
|
};
|
||||||
void insert_node_into_inline_or_block_ancestor(Layout::Node&, AppendOrPrepend);
|
void insert_node_into_inline_or_block_ancestor(Layout::Node&, CSS::Display, AppendOrPrepend);
|
||||||
void create_pseudo_element_if_needed(DOM::Element&, CSS::Selector::PseudoElement, AppendOrPrepend);
|
void create_pseudo_element_if_needed(DOM::Element&, CSS::Selector::PseudoElement, AppendOrPrepend);
|
||||||
|
|
||||||
RefPtr<Layout::Node> m_layout_root;
|
RefPtr<Layout::Node> m_layout_root;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue