Skip to content

Truly independent web browser

LibWeb: Renumber a list when a removed element holds its items

Aliaksandr Kalenik7fa2e67a3db6
diff --git a/Libraries/LibWeb/DOM/Node.cpp b/Libraries/LibWeb/DOM/Node.cpp
index 1e2132c083e..dbf2d447778 100644
--- a/Libraries/LibWeb/DOM/Node.cpp
+++ b/Libraries/LibWeb/DOM/Node.cpp
@@ -1500,7 +1500,21 @@ bool Node::schedule_list_item_renumber_for_removal()
element->schedule_list_item_renumber_for_list_owner();
return true;
}
- return false;
+ // An element in a list that holds list items renumbers the list as removing each of them would.
+ bool is_in_list = false;
+ for (auto ancestor = parent_element(); ancestor && !is_in_list; ancestor = ancestor->parent_element())
+ is_in_list = ancestor->is_html_ol_ul_menu_element();
+ if (!is_in_list)
+ return false;
+ bool holds_list_item = false;
+ element->for_each_in_subtree_of_type<Element>([&](Element const& descendant) {
+ auto descendant_style = descendant.computed_style();
+ holds_list_item = descendant.is_html_li_element() || (descendant_style && descendant_style->display().is_list_item());
+ return holds_list_item ? TraversalDecision::Break : TraversalDecision::Continue;
+ });
+ if (holds_list_item)
+ element->schedule_list_item_renumber_for_list_owner();
+ return holds_list_item;
}
void Node::report_removal_to_style_engine(Node& parent)
diff --git a/Tests/LibWeb/Ref/input/ol-render-node-remove-child-group-without-whitespace.html b/Tests/LibWeb/Ref/input/ol-render-node-remove-child-group-without-whitespace.html
new file mode 100644
index 00000000000..58a5c48176b
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/ol-render-node-remove-child-group-without-whitespace.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<head>
+ <link rel="match" href="../expected/ol-render-node-remove-ref.html" />
+</head>
+<html class="reftest-wait">
+<body>
+<!-- No white space between the elements, so the group is a block-level sibling of the items. -->
+<ol id="ol1"><li>One</li><div id="div1"><li>x</li><li>y</li><li>z</li></div><li>Two</li></ol><ol reversed id="ol2"><li>Two</li><div id="div2"><li>z</li><li>y</li><li>x</li></div><li>One</li></ol>
+<script>
+ // Two nested requestAnimationFrame() calls to force code execution _after_ initial paint
+ requestAnimationFrame(() => {
+ requestAnimationFrame(() => {
+ const ol1 = document.getElementById("ol1");
+ const div1 = document.getElementById("div1");
+ ol1.removeChild(div1);
+
+ const ol2 = document.getElementById("ol2");
+ const div2 = document.getElementById("div2");
+ ol2.removeChild(div2);
+
+ document.documentElement.classList.remove("reftest-wait");
+ });
+ });
+</script>
+</body>
+</html>