1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 13:57:35 +00:00

LibWeb: Implement "NodeIterator pre-removing steps"

These steps run when a node is about to be removed from its parent,
and adjust the position of any live NodeIterators so that they don't
point at a now-removed node.

Note that while this commit implements what's in the DOM specification,
the specification doesn't fully match what other browsers do.

Spec bug: https://github.com/whatwg/dom/issues/907
This commit is contained in:
Andreas Kling 2022-03-09 16:38:44 +01:00
parent acbdb95b0a
commit 9c6999ecf2
5 changed files with 91 additions and 2 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -327,6 +327,16 @@ public:
NonnullRefPtr<NodeIterator> create_node_iterator(Node& root, unsigned what_to_show, RefPtr<NodeFilter>);
NonnullRefPtr<TreeWalker> create_tree_walker(Node& root, unsigned what_to_show, RefPtr<NodeFilter>);
void register_node_iterator(Badge<NodeIterator>, NodeIterator&);
void unregister_node_iterator(Badge<NodeIterator>, NodeIterator&);
template<typename Callback>
void for_each_node_iterator(Callback callback)
{
for (auto* node_iterator : m_node_iterators)
callback(*node_iterator);
}
private:
explicit Document(const AK::URL&);
@ -430,5 +440,8 @@ private:
Vector<WeakPtr<CSS::MediaQueryList>> m_media_query_lists;
bool m_needs_layout { false };
HashTable<NodeIterator*> m_node_iterators;
};
}