1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 19:38:12 +00:00

LibWeb: Make the node mutation algorithms more spec compliant

The mutation algorithms now more closely follow the spec and
fixes some assertion failures in tests such as Acid3 and Dromaeo.

The main thing that is missing right now is passing exceptions to the
bindings layer. This is because of issue #6075. I spent a while trying
to work it out and got so frustrated I just left it as a FIXME. Besides
that, the algorithms bail at the appropriate points.

This also makes the adopting steps in the document more spec compliant
as it's needed by the insertion algorithm. While I was at it, I added
the adoptNode IDL binding.

This adds a bunch of ancestor/descendant checks to TreeNode as well.
I moved the "remove_all_children" function to Node as it needs to use
the full remove algorithm instead of simply removing it from
the child list.
This commit is contained in:
Luke 2021-04-06 19:34:49 +01:00 committed by Andreas Kling
parent 5b5d7857e3
commit 5beacf08a2
8 changed files with 305 additions and 55 deletions

View file

@ -62,14 +62,14 @@ void EditEventHandler::handle_delete(DOM::Range& range)
for (auto* parent = end->parent(); parent; parent = parent->parent())
queued_for_deletion.remove(parent);
for (auto* node : queued_for_deletion)
node->parent()->remove_child(*node);
node->remove();
// Join the parent nodes of start and end.
DOM::Node *insert_after = start, *remove_from = end, *parent_of_end = end->parent();
while (remove_from) {
auto* next_sibling = remove_from->next_sibling();
remove_from->parent()->remove_child(*remove_from);
remove_from->remove();
insert_after->parent()->insert_before(*remove_from, *insert_after);
insert_after = remove_from;
@ -77,7 +77,7 @@ void EditEventHandler::handle_delete(DOM::Range& range)
}
if (!parent_of_end->has_children()) {
if (parent_of_end->parent())
parent_of_end->parent()->remove_child(*parent_of_end);
parent_of_end->remove();
}
// Join the start and end nodes.
@ -86,7 +86,7 @@ void EditEventHandler::handle_delete(DOM::Range& range)
builder.append(end->data().substring_view(range.end_offset()));
start->set_data(builder.to_string());
start->parent()->remove_child(*end);
end->remove();
}
// FIXME: When nodes are removed from the DOM, the associated layout nodes become stale and still