From b3a63e1d503f3b837d62abc990d290112aab69cf Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 19 Oct 2019 18:14:54 +0200 Subject: [PATCH] LibHTML: Add TreeNode::for_each_in_subtree(callback) This helper invokes a callback for the node and each of its descendants in pre-order. --- Libraries/LibHTML/TreeNode.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Libraries/LibHTML/TreeNode.h b/Libraries/LibHTML/TreeNode.h index 3adf8695f7..229b07c4e2 100644 --- a/Libraries/LibHTML/TreeNode.h +++ b/Libraries/LibHTML/TreeNode.h @@ -53,6 +53,15 @@ public: bool is_child_allowed(const T&) const { return true; } + template + void for_each_in_subtree(Callback callback) + { + callback(static_cast(*this)); + for (auto* child = first_child(); child; child = child->next_sibling()) { + child->for_each_in_subtree(callback); + } + } + protected: TreeNode() {}