mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:27:35 +00:00
LibWeb: Move tree iteration helpers from Node/LayoutNode to TreeNode
Since these are generally useful in our trees, let's just keep them in TreeNode instead of duplicating the helpers in subclasses.
This commit is contained in:
parent
62ea2c5437
commit
eaf7e68408
3 changed files with 92 additions and 164 deletions
|
@ -106,12 +106,6 @@ public:
|
|||
Element* parent_element();
|
||||
const Element* parent_element() const;
|
||||
|
||||
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&) { }
|
||||
virtual void children_changed() { }
|
||||
|
@ -144,24 +138,4 @@ protected:
|
|||
bool m_needs_style_update { true };
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
inline const T* Node::first_child_of_type() const
|
||||
{
|
||||
for (auto* child = first_child(); child; child = child->next_sibling()) {
|
||||
if (is<T>(*child))
|
||||
return downcast<T>(child);
|
||||
}
|
||||
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 downcast<T>(ancestor);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue