mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:27:45 +00:00
LibHTML: Add LayoutNode::first_ancestor_of_type<T>()
This commit is contained in:
parent
65ad6c35f0
commit
2305dee455
1 changed files with 32 additions and 0 deletions
|
@ -67,6 +67,7 @@ public:
|
||||||
|
|
||||||
const StyleProperties& style() const;
|
const StyleProperties& style() const;
|
||||||
|
|
||||||
|
LayoutNodeWithStyle* parent();
|
||||||
const LayoutNodeWithStyle* parent() const;
|
const LayoutNodeWithStyle* parent() const;
|
||||||
|
|
||||||
void inserted_into(LayoutNode&) {}
|
void inserted_into(LayoutNode&) {}
|
||||||
|
@ -97,6 +98,12 @@ public:
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T* first_child_of_type();
|
T* first_child_of_type();
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
const T* first_ancestor_of_type() const;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
T* first_ancestor_of_type();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit LayoutNode(const Node*);
|
explicit LayoutNode(const Node*);
|
||||||
|
|
||||||
|
@ -157,6 +164,11 @@ inline const LayoutNodeWithStyle* LayoutNode::parent() const
|
||||||
return static_cast<const LayoutNodeWithStyle*>(TreeNode<LayoutNode>::parent());
|
return static_cast<const LayoutNodeWithStyle*>(TreeNode<LayoutNode>::parent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline LayoutNodeWithStyle* LayoutNode::parent()
|
||||||
|
{
|
||||||
|
return static_cast<LayoutNodeWithStyle*>(TreeNode<LayoutNode>::parent());
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline bool is(const LayoutNode&)
|
inline bool is(const LayoutNode&)
|
||||||
{
|
{
|
||||||
|
@ -248,3 +260,23 @@ inline T* LayoutNode::first_child_of_type()
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline const T* LayoutNode::first_ancestor_of_type() const
|
||||||
|
{
|
||||||
|
for (auto* ancestor = parent(); ancestor; ancestor = ancestor->parent()) {
|
||||||
|
if (is<T>(*ancestor))
|
||||||
|
return &to<T>(*ancestor);
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline T* LayoutNode::first_ancestor_of_type()
|
||||||
|
{
|
||||||
|
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