LibWeb: Allow partial update of SVG subtrees in layout tree

We were incorrectly always appending to the nearest ancestor in the
partial update case, even when the node was eligible for replacement.
This commit is contained in:
Andreas Kling 2025-01-20 21:45:46 +01:00 committed by Andreas Kling
commit 7ae46bf8b7
Notes: github-actions[bot] 2025-01-20 23:09:17 +00:00
3 changed files with 31 additions and 5 deletions

View file

@ -402,17 +402,20 @@ void TreeBuilder::update_layout_tree(DOM::Node& dom_node, TreeBuilder::Context&
if (dom_node.is_document()) {
m_layout_root = layout_node;
} else if (layout_node->is_svg_box()) {
m_ancestor_stack.last()->append_child(*layout_node);
} else if (should_create_layout_node) {
// Decide whether to replace an existing node (partial tree update) or insert a new one appropriately.
if (must_create_subtree == MustCreateSubtree::No
bool const may_replace_existing_layout_node = must_create_subtree == MustCreateSubtree::No
&& old_layout_node
&& old_layout_node->parent()
&& old_layout_node != layout_node) {
&& old_layout_node != layout_node;
if (may_replace_existing_layout_node) {
old_layout_node->parent()->replace_child(*layout_node, *old_layout_node);
} else {
insert_node_into_inline_or_block_ancestor(*layout_node, display, AppendOrPrepend::Append);
if (layout_node->is_svg_box()) {
m_ancestor_stack.last()->append_child(*layout_node);
} else {
insert_node_into_inline_or_block_ancestor(*layout_node, display, AppendOrPrepend::Append);
}
}
}