diff --git a/Tests/LibWeb/Layout/expected/display-contents-with-in-children.txt b/Tests/LibWeb/Layout/expected/display-contents-with-in-children.txt new file mode 100644 index 0000000000..6321bfce58 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/display-contents-with-in-children.txt @@ -0,0 +1,12 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x17.46875 [BFC] children: inline + line 0 width: 51.75, height: 17.46875, bottom: 17.46875, baseline: 13.53125 + frag 0 from TextNode start: 0, length: 7, rect: [0,0 51.75x17.46875] + "whf :^)" + InlineNode + TextNode <#text> + +ViewportPaintable (Viewport<#document>) [0,0 800x600] + PaintableWithLines (BlockContainer) [0,0 800x17.46875] + InlinePaintable (InlineNode) + TextPaintable (TextNode<#text>) diff --git a/Tests/LibWeb/Layout/input/display-contents-with-in-children.html b/Tests/LibWeb/Layout/input/display-contents-with-in-children.html new file mode 100644 index 0000000000..ce75dc0c6b --- /dev/null +++ b/Tests/LibWeb/Layout/input/display-contents-with-in-children.html @@ -0,0 +1,2 @@ +whf :^) \ No newline at end of file diff --git a/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp b/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp index 4e49093547..00069c879e 100644 --- a/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp +++ b/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp @@ -148,8 +148,15 @@ void TreeBuilder::insert_node_into_inline_or_block_ancestor(Layout::Node& node, 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()); + // Inlines can be inserted into the nearest ancestor without "display: contents". + auto& nearest_ancestor_without_display_contents = [&]() -> Layout::NodeWithStyle& { + for (auto& ancestor : m_ancestor_stack.in_reverse()) { + if (!ancestor->display().is_contents()) + return ancestor; + } + VERIFY_NOT_REACHED(); + }(); + auto& insertion_point = insertion_parent_for_inline_node(nearest_ancestor_without_display_contents); if (mode == AppendOrPrepend::Prepend) insertion_point.prepend_child(node); else