diff --git a/Libraries/LibHTML/TreeNode.h b/Libraries/LibHTML/TreeNode.h
index 8461fd3160..ae84db165b 100644
--- a/Libraries/LibHTML/TreeNode.h
+++ b/Libraries/LibHTML/TreeNode.h
@@ -49,6 +49,7 @@ public:
void prepend_child(NonnullRefPtr node, bool call_inserted_into = true);
void append_child(NonnullRefPtr node, bool call_inserted_into = true);
+ NonnullRefPtr remove_child(NonnullRefPtr node, bool call_removed_from = true);
void donate_all_children_to(T& node);
bool is_child_allowed(const T&) const { return true; }
@@ -109,6 +110,29 @@ private:
T* m_previous_sibling { nullptr };
};
+template
+inline NonnullRefPtr TreeNode::remove_child(NonnullRefPtr node, bool call_removed_from)
+{
+ ASSERT(node->m_parent == this);
+
+ if (m_first_child == node)
+ m_first_child = node->m_next_sibling;
+
+ if (m_last_child == node)
+ m_last_child = node->m_previous_sibling;
+
+ node->m_next_sibling = nullptr;
+ node->m_previous_sibling = nullptr;
+ node->m_parent = nullptr;
+
+ if (call_removed_from)
+ node->removed_from(static_cast(*this));
+
+ node->deref();
+
+ return node;
+}
+
template
inline void TreeNode::append_child(NonnullRefPtr node, bool call_inserted_into)
{