1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 06:37:35 +00:00

LibWeb: Add support for "display: contents"

This change makes tree builder omit elements with "display: contents"
from the layout tree during construction. Their child elements are
instead directly appended to the parent element in layout tree.
This commit is contained in:
Aliaksandr Kalenik 2023-07-27 23:31:42 +02:00 committed by Andreas Kling
parent b91af3c6a0
commit 0e8a0a8191
5 changed files with 31 additions and 3 deletions

View file

@ -5327,8 +5327,7 @@ ErrorOr<RefPtr<StyleValue>> Parser::parse_display_value(Vector<ComponentValue> c
// display-box
case ValueID::Contents:
// FIXME this should be Display::Short::Contents but contents is currently not implemented
return Display::from_short(Display::Short::Flow);
return Display::from_short(Display::Short::Contents);
case ValueID::None:
return Display::from_short(Display::Short::None);

View file

@ -347,7 +347,7 @@ JS::GCPtr<Layout::Node> Element::create_layout_node_for_display_type(DOM::Docume
if (display.is_flex_inside() || display.is_grid_inside())
return document.heap().allocate_without_realm<Layout::Box>(document, element, move(style));
if (display.is_flow_inside() || display.is_flow_root_inside())
if (display.is_flow_inside() || display.is_flow_root_inside() || display.is_contents())
return document.heap().allocate_without_realm<Layout::BlockContainer>(document, element, move(style));
dbgln("FIXME: CSS display '{}' not implemented yet.", display.to_string().release_value_but_fixme_should_propagate_errors());

View file

@ -129,6 +129,9 @@ static Layout::Node& insertion_parent_for_block_node(Layout::NodeWithStyle& layo
void TreeBuilder::insert_node_into_inline_or_block_ancestor(Layout::Node& node, CSS::Display display, AppendOrPrepend mode)
{
if (node.display().is_contents())
return;
if (display.is_inline_outside()) {
// Inlines can be inserted into the nearest ancestor.
auto& insertion_point = insertion_parent_for_inline_node(m_ancestor_stack.last());
@ -141,6 +144,8 @@ void TreeBuilder::insert_node_into_inline_or_block_ancestor(Layout::Node& node,
// Non-inlines can't be inserted into an inline parent, so find the nearest non-inline ancestor.
auto& nearest_non_inline_ancestor = [&]() -> Layout::NodeWithStyle& {
for (auto& ancestor : m_ancestor_stack.in_reverse()) {
if (ancestor->display().is_contents())
continue;
if (!ancestor->display().is_inline_outside())
return ancestor;
if (!ancestor->display().is_flow_inside())