diff options
author | Andreas Kling <kling@serenityos.org> | 2021-01-07 16:35:23 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-01-07 17:33:29 +0100 |
commit | 75829c1b8146fc337dc8fa5fd9a66650f9167469 (patch) | |
tree | bfd9323e36f2d8d2c42587394ee93c779bee8549 /Libraries/LibWeb | |
parent | fe9de4b55c1ff3cffd24d81f3f94bd348ee8cd03 (diff) | |
download | serenity-75829c1b8146fc337dc8fa5fd9a66650f9167469.zip |
LibWeb: Move remove_all_children() from Node to TreeNode<T>
This is useful in all tree types.
Diffstat (limited to 'Libraries/LibWeb')
-rw-r--r-- | Libraries/LibWeb/DOM/Node.cpp | 7 | ||||
-rw-r--r-- | Libraries/LibWeb/DOM/Node.h | 1 | ||||
-rw-r--r-- | Libraries/LibWeb/TreeNode.h | 9 |
3 files changed, 9 insertions, 8 deletions
diff --git a/Libraries/LibWeb/DOM/Node.cpp b/Libraries/LibWeb/DOM/Node.cpp index 55e062f4bc..f5dcc872ce 100644 --- a/Libraries/LibWeb/DOM/Node.cpp +++ b/Libraries/LibWeb/DOM/Node.cpp @@ -199,13 +199,6 @@ RefPtr<Node> Node::insert_before(NonnullRefPtr<Node> node, RefPtr<Node> child, b return node; } -void Node::remove_all_children() -{ - while (RefPtr<Node> child = first_child()) { - remove_child(*child); - } -} - void Node::set_document(Badge<Document>, Document& document) { if (m_document == &document) diff --git a/Libraries/LibWeb/DOM/Node.h b/Libraries/LibWeb/DOM/Node.h index 8103bbbff6..624b41b951 100644 --- a/Libraries/LibWeb/DOM/Node.h +++ b/Libraries/LibWeb/DOM/Node.h @@ -82,7 +82,6 @@ public: RefPtr<Node> append_child(NonnullRefPtr<Node>, bool notify = true); RefPtr<Node> insert_before(NonnullRefPtr<Node> node, RefPtr<Node> child, bool notify = true); - void remove_all_children(); virtual RefPtr<Layout::Node> create_layout_node(); diff --git a/Libraries/LibWeb/TreeNode.h b/Libraries/LibWeb/TreeNode.h index f198e4e231..1673a52dc5 100644 --- a/Libraries/LibWeb/TreeNode.h +++ b/Libraries/LibWeb/TreeNode.h @@ -104,6 +104,8 @@ public: void insert_before(NonnullRefPtr<T> node, RefPtr<T> child, bool notify = true); NonnullRefPtr<T> remove_child(NonnullRefPtr<T> node); + void remove_all_children(); + bool is_child_allowed(const T&) const { return true; } T* next_in_pre_order() @@ -313,6 +315,13 @@ private: }; template<typename T> +inline void TreeNode<T>::remove_all_children() +{ + while (RefPtr<T> child = first_child()) + remove_child(child.release_nonnull()); +} + +template<typename T> inline NonnullRefPtr<T> TreeNode<T>::remove_child(NonnullRefPtr<T> node) { ASSERT(node->m_parent == this); |