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

LibHTML: Add TreeNode::remove_child()

This removes a child from the tree and returns it to the caller.
It optionally (but by default) calls removed_from(parent) on the child.
This commit is contained in:
Andreas Kling 2019-11-06 20:25:40 +01:00
parent 9a5e065229
commit 26493a3039

View file

@ -49,6 +49,7 @@ public:
void prepend_child(NonnullRefPtr<T> node, bool call_inserted_into = true);
void append_child(NonnullRefPtr<T> node, bool call_inserted_into = true);
NonnullRefPtr<T> remove_child(NonnullRefPtr<T> 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<typename T>
inline NonnullRefPtr<T> TreeNode<T>::remove_child(NonnullRefPtr<T> 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<T&>(*this));
node->deref();
return node;
}
template<typename T>
inline void TreeNode<T>::append_child(NonnullRefPtr<T> node, bool call_inserted_into)
{