LibWeb: Add non-inclusive variants of subtree traversal

This commit is contained in:
Luke 2021-04-06 18:49:02 +01:00 committed by Andreas Kling
parent ca71ac484b
commit e56c56128b
Notes: sideshowbarker 2024-07-18 20:42:53 +09:00

View file

@ -191,6 +191,46 @@ public:
return IterationDecision::Continue;
}
template<typename Callback>
IterationDecision for_each_in_subtree(Callback callback) const
{
for (auto* child = first_child(); child; child = child->next_sibling()) {
if (child->for_each_in_inclusive_subtree(callback) == IterationDecision::Break)
return IterationDecision::Break;
}
return IterationDecision::Continue;
}
template<typename Callback>
IterationDecision for_each_in_subtree(Callback callback)
{
for (auto* child = first_child(); child; child = child->next_sibling()) {
if (child->for_each_in_inclusive_subtree(callback) == IterationDecision::Break)
return IterationDecision::Break;
}
return IterationDecision::Continue;
}
template<typename U, typename Callback>
IterationDecision for_each_in_subtree_of_type(Callback callback)
{
for (auto* child = first_child(); child; child = child->next_sibling()) {
if (child->template for_each_in_inclusive_subtree_of_type<U>(callback) == IterationDecision::Break)
return IterationDecision::Break;
}
return IterationDecision::Continue;
}
template<typename U, typename Callback>
IterationDecision for_each_in_subtree_of_type(Callback callback) const
{
for (auto* child = first_child(); child; child = child->next_sibling()) {
if (child->template for_each_in_inclusive_subtree_of_type<U>(callback) == IterationDecision::Break)
return IterationDecision::Break;
}
return IterationDecision::Continue;
}
template<typename Callback>
void for_each_child(Callback callback) const
{