summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/DOM
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-03-21 20:26:35 +0100
committerAndreas Kling <kling@serenityos.org>2022-03-21 20:26:35 +0100
commit3b6323340aa3c955f0e39e6a97b52fa79755bace (patch)
tree93b6c946c5b52af7cb95431b47f3d3a5420ac160 /Userland/Libraries/LibWeb/DOM
parent1254758b00b046cac8e50128cc897dc4ddec1332 (diff)
downloadserenity-3b6323340aa3c955f0e39e6a97b52fa79755bace.zip
LibWeb: Update live ranges on Node insertion and removal
Taking care of some old FIXMEs :^)
Diffstat (limited to 'Userland/Libraries/LibWeb/DOM')
-rw-r--r--Userland/Libraries/LibWeb/DOM/Node.cpp44
1 files changed, 37 insertions, 7 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp
index 71220abf93..dd56577a43 100644
--- a/Userland/Libraries/LibWeb/DOM/Node.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Node.cpp
@@ -313,9 +313,19 @@ void Node::insert_before(NonnullRefPtr<Node> node, RefPtr<Node> child, bool supp
// FIXME: Queue a tree mutation record for node with « », nodes, null, and null.
}
+ // 5. If child is non-null, then:
if (child) {
- // FIXME: For each live range whose start node is parent and start offset is greater than child’s index, increase its start offset by count.
- // FIXME: For each live range whose end node is parent and end offset is greater than child’s index, increase its end offset by count.
+ // 1. For each live range whose start node is parent and start offset is greater than child’s index, increase its start offset by count.
+ for (auto& range : Range::live_ranges()) {
+ if (range->start_container() == this && range->start_offset() > child->index())
+ range->set_start(*range->start_container(), range->start_offset() + count);
+ }
+
+ // 2. For each live range whose end node is parent and end offset is greater than child’s index, increase its end offset by count.
+ for (auto& range : Range::live_ranges()) {
+ if (range->start_container() == this && range->end_offset() > child->index())
+ range->set_end(*range->end_container(), range->end_offset() + count);
+ }
}
// FIXME: Let previousSibling be child’s previous sibling or parent’s last child if child is null. (Currently unused so not included)
@@ -399,12 +409,32 @@ void Node::remove(bool suppress_observers)
auto* parent = TreeNode<Node>::parent();
VERIFY(parent);
- // FIXME: Let index be node’s index. (Currently unused so not included)
+ // 3. Let index be node’s index.
+ auto index = this->index();
+
+ // 4. For each live range whose start node is an inclusive descendant of node, set its start to (parent, index).
+ for (auto& range : Range::live_ranges()) {
+ if (range->start_container()->is_inclusive_descendant_of(*this))
+ range->set_start(*parent, index);
+ }
+
+ // 5. For each live range whose end node is an inclusive descendant of node, set its end to (parent, index).
+ for (auto& range : Range::live_ranges()) {
+ if (range->end_container()->is_inclusive_descendant_of(*this))
+ range->set_end(*parent, index);
+ }
- // FIXME: For each live range whose start node is an inclusive descendant of node, set its start to (parent, index).
- // FIXME: For each live range whose end node is an inclusive descendant of node, set its end to (parent, index).
- // FIXME: For each live range whose start node is parent and start offset is greater than index, decrease its start offset by 1.
- // FIXME: For each live range whose end node is parent and end offset is greater than index, decrease its end offset by 1.
+ // 6. For each live range whose start node is parent and start offset is greater than index, decrease its start offset by 1.
+ for (auto& range : Range::live_ranges()) {
+ if (range->start_container() == this && range->start_offset() > index)
+ range->set_start(*range->start_container(), range->start_offset() - 1);
+ }
+
+ // 7. For each live range whose end node is parent and end offset is greater than index, decrease its end offset by 1.
+ for (auto& range : Range::live_ranges()) {
+ if (range->end_container() == this && range->end_offset() > index)
+ range->set_end(*range->end_container(), range->end_offset() - 1);
+ }
// For each NodeIterator object iterator whose root’s node document is node’s node document, run the NodeIterator pre-removing steps given node and iterator.
document().for_each_node_iterator([&](NodeIterator& node_iterator) {