mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:48:12 +00:00
LibHTML: Add typed child/sibling traversal helpers for LayoutNode
Also add some special variants for the table classes, to make it a bit more pleasant to write table code. :^)
This commit is contained in:
parent
6202a0ab32
commit
65ad6c35f0
6 changed files with 101 additions and 0 deletions
|
@ -85,6 +85,18 @@ public:
|
|||
bool children_are_inline() const { return m_children_are_inline; }
|
||||
void set_children_are_inline(bool value) { m_children_are_inline = value; }
|
||||
|
||||
template<typename U>
|
||||
const U* next_sibling_of_type() const;
|
||||
|
||||
template<typename U>
|
||||
U* next_sibling_of_type();
|
||||
|
||||
template<typename T>
|
||||
const T* first_child_of_type() const;
|
||||
|
||||
template<typename T>
|
||||
T* first_child_of_type();
|
||||
|
||||
protected:
|
||||
explicit LayoutNode(const Node*);
|
||||
|
||||
|
@ -196,3 +208,43 @@ inline T& to(LayoutNode& node)
|
|||
ASSERT(is<T>(node));
|
||||
return static_cast<T&>(node);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline const T* LayoutNode::next_sibling_of_type() const
|
||||
{
|
||||
for (auto* sibling = next_sibling(); sibling; sibling = sibling->next_sibling()) {
|
||||
if (is<T>(*sibling))
|
||||
return &to<T>(*sibling);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T* LayoutNode::next_sibling_of_type()
|
||||
{
|
||||
for (auto* sibling = next_sibling(); sibling; sibling = sibling->next_sibling()) {
|
||||
if (is<T>(*sibling))
|
||||
return &to<T>(*sibling);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline const T* LayoutNode::first_child_of_type() const
|
||||
{
|
||||
for (auto* child = first_child(); child; child = child->next_sibling()) {
|
||||
if (is<T>(*child))
|
||||
return &to<T>(*child);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T* LayoutNode::first_child_of_type()
|
||||
{
|
||||
for (auto* child = first_child(); child; child = child->next_sibling()) {
|
||||
if (is<T>(*child))
|
||||
return &to<T>(*child);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue