mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 13:49:16 +00:00
LibWeb: Add Node::for_each(_inclusive)_ancestor()
Allows for easy iteration over the chain of ancestors for a node.
This commit is contained in:
parent
4323669939
commit
d08febcf67
Notes:
github-actions[bot]
2025-01-10 22:39:07 +00:00
Author: https://github.com/gmta
Commit: d08febcf67
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3216
3 changed files with 83 additions and 53 deletions
|
@ -589,6 +589,36 @@ public:
|
|||
return TraversalDecision::Continue;
|
||||
}
|
||||
|
||||
template<typename Callback>
|
||||
void for_each_ancestor(Callback callback) const
|
||||
{
|
||||
return const_cast<Node*>(this)->for_each_ancestor(move(callback));
|
||||
}
|
||||
|
||||
template<typename Callback>
|
||||
void for_each_ancestor(Callback callback)
|
||||
{
|
||||
for (auto* ancestor = parent(); ancestor; ancestor = ancestor->parent()) {
|
||||
if (callback(*ancestor) == IterationDecision::Break)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Callback>
|
||||
void for_each_inclusive_ancestor(Callback callback) const
|
||||
{
|
||||
return const_cast<Node*>(this)->for_each_inclusive_ancestor(move(callback));
|
||||
}
|
||||
|
||||
template<typename Callback>
|
||||
void for_each_inclusive_ancestor(Callback callback)
|
||||
{
|
||||
for (auto* ancestor = this; ancestor; ancestor = ancestor->parent()) {
|
||||
if (callback(*ancestor) == IterationDecision::Break)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Callback>
|
||||
void for_each_child(Callback callback) const
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue