diff --git a/Libraries/LibWeb/DOM/Node.cpp b/Libraries/LibWeb/DOM/Node.cpp index 2b8c4f708eb..be20b94fc6c 100644 --- a/Libraries/LibWeb/DOM/Node.cpp +++ b/Libraries/LibWeb/DOM/Node.cpp @@ -1634,8 +1634,19 @@ void Node::set_needs_layout_tree_update(bool value, SetNeedsLayoutTreeUpdateReas break; ancestor->m_child_needs_layout_tree_update = true; } - if (auto layout_node = this->layout_node()) + if (auto layout_node = this->layout_node()) { layout_node->set_needs_layout_update(SetNeedsLayoutReason::LayoutTreeUpdate); + + // If the layout node has an anonymous parent, rebuild from the nearest non-anonymous ancestor. + // FIXME: This is not optimal, and we should figure out how to rebuild a smaller part of the tree. + if (layout_node->parent() && layout_node->parent()->is_anonymous()) { + GC::Ptr ancestor = layout_node->parent(); + while (ancestor && ancestor->is_anonymous()) + ancestor = ancestor->parent(); + if (ancestor) + ancestor->dom_node()->set_needs_layout_tree_update(true, reason); + } + } } } diff --git a/Tests/LibWeb/Layout/expected/layout-tree-update/inline-element-position-change.txt b/Tests/LibWeb/Layout/expected/layout-tree-update/inline-element-position-change.txt new file mode 100644 index 00000000000..8adc9cffc43 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/layout-tree-update/inline-element-position-change.txt @@ -0,0 +1,26 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x79.875 [BFC] children: not-inline + BlockContainer at (8,21.4375) content-size 784x37 children: not-inline + BlockContainer <(anonymous)> at (8,21.4375) content-size 784x0 children: inline + InlineNode + InlineNode + BlockContainer <(anonymous)> at (8,21.4375) content-size 784x37 children: not-inline continuation + BlockContainer

at (8,21.4375) content-size 784x37 children: inline + frag 0 from TextNode start: 0, length: 4, rect: [8,21.4375 63.5625x37] baseline: 28.09375 + "test" + TextNode <#text> + BlockContainer <(anonymous)> at (8,79.875) content-size 784x0 children: inline + InlineNode continuation + TextNode <#text> + +ViewportPaintable (Viewport<#document>) [0,0 800x600] + PaintableWithLines (BlockContainer) [0,0 800x79.875] + PaintableWithLines (BlockContainer) [8,21.4375 784x37] + PaintableWithLines (BlockContainer(anonymous)) [8,21.4375 784x0] + PaintableWithLines (InlineNode) + PaintableWithLines (InlineNode#foo) + PaintableWithLines (BlockContainer(anonymous)) [8,21.4375 784x37] + PaintableWithLines (BlockContainer

) [8,21.4375 784x37] + TextPaintable (TextNode<#text>) + PaintableWithLines (BlockContainer(anonymous)) [8,79.875 784x0] + PaintableWithLines (InlineNode) diff --git a/Tests/LibWeb/Layout/input/layout-tree-update/inline-element-position-change.html b/Tests/LibWeb/Layout/input/layout-tree-update/inline-element-position-change.html new file mode 100644 index 00000000000..78bc02359a1 --- /dev/null +++ b/Tests/LibWeb/Layout/input/layout-tree-update/inline-element-position-change.html @@ -0,0 +1,14 @@ + +

test