1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 05:47:34 +00:00

LibWeb: Add Node.insertBefore(Node node, Node? child)

This commit is contained in:
Andreas Kling 2020-06-21 16:45:21 +02:00
parent 82a75bcf5f
commit 213e2793bd
4 changed files with 43 additions and 0 deletions

View file

@ -110,6 +110,7 @@ public:
void prepend_child(NonnullRefPtr<T> node);
void append_child(NonnullRefPtr<T> node, bool notify = true);
void insert_before(NonnullRefPtr<T> node, RefPtr<T> child, bool notify = true);
NonnullRefPtr<T> remove_child(NonnullRefPtr<T> node);
void donate_all_children_to(T& node);
@ -252,6 +253,33 @@ inline void TreeNode<T>::append_child(NonnullRefPtr<T> node, bool notify)
static_cast<T*>(this)->children_changed();
}
template<typename T>
inline void TreeNode<T>::insert_before(NonnullRefPtr<T> node, RefPtr<T> child, bool notify)
{
if (!child)
return append_child(move(node), notify);
ASSERT(!node->m_parent);
ASSERT(child->parent() == this);
if (!static_cast<T*>(this)->is_child_allowed(*node))
return;
node->m_previous_sibling = child->m_previous_sibling;
node->m_next_sibling = child;
if (m_first_child == child)
m_first_child = node;
node->m_parent = static_cast<T*>(this);
if (notify)
node->inserted_into(static_cast<T&>(*this));
(void)node.leak_ref();
if (notify)
static_cast<T*>(this)->children_changed();
}
template<typename T>
inline void TreeNode<T>::prepend_child(NonnullRefPtr<T> node)
{