mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:18:11 +00:00
LibHTML: Add Node::first_ancestor_of_type<T>()
Here's another helper for finding the first ancestor of a Node of a specific type.
This commit is contained in:
parent
03725c6135
commit
a239ef34d5
2 changed files with 15 additions and 6 deletions
|
@ -50,6 +50,9 @@ public:
|
|||
template<typename T>
|
||||
const T* first_child_of_type() const;
|
||||
|
||||
template<typename T>
|
||||
const T* first_ancestor_of_type() const;
|
||||
|
||||
virtual void inserted_into(Node&) {}
|
||||
virtual void removed_from(Node&) {}
|
||||
|
||||
|
@ -130,3 +133,13 @@ inline const T* Node::first_child_of_type() const
|
|||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline const T* Node::first_ancestor_of_type() const
|
||||
{
|
||||
for (auto* ancestor = parent(); ancestor; ancestor = ancestor->parent()) {
|
||||
if (is<T>(*ancestor))
|
||||
return to<T>(ancestor);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue