LibHTML: Add TreeNode<T>::for_each_in_subtree(callback)

This helper invokes a callback for the node and each of its descendants
in pre-order.
This commit is contained in:
Andreas Kling 2019-10-19 18:14:54 +02:00
parent 8acc61f19a
commit b3a63e1d50
Notes: sideshowbarker 2024-07-19 11:38:21 +09:00

View file

@ -53,6 +53,15 @@ public:
bool is_child_allowed(const T&) const { return true; }
template<typename Callback>
void for_each_in_subtree(Callback callback)
{
callback(static_cast<T&>(*this));
for (auto* child = first_child(); child; child = child->next_sibling()) {
child->for_each_in_subtree(callback);
}
}
protected:
TreeNode() {}