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:
parent
9a5e065229
commit
26493a3039
1 changed files with 24 additions and 0 deletions
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue