mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:07:35 +00:00
LibWeb: Add preceding and following Node cases in tree constraints
This also does some east-const changes in TreeNode.
This commit is contained in:
parent
24ed8511dd
commit
1a28fc3cb5
2 changed files with 47 additions and 8 deletions
|
@ -137,12 +137,29 @@ public:
|
|||
return node;
|
||||
}
|
||||
|
||||
const T* next_in_pre_order() const
|
||||
T const* next_in_pre_order() const
|
||||
{
|
||||
return const_cast<TreeNode*>(this)->next_in_pre_order();
|
||||
}
|
||||
|
||||
bool is_before(const T& other) const
|
||||
T* previous_in_pre_order()
|
||||
{
|
||||
if (auto* node = previous_sibling()) {
|
||||
while (node->last_child())
|
||||
node = node->last_child();
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
return parent();
|
||||
}
|
||||
|
||||
T const* previous_in_pre_order() const
|
||||
{
|
||||
return const_cast<TreeNode*>(this)->previous_in_pre_order();
|
||||
}
|
||||
|
||||
bool is_before(T const& other) const
|
||||
{
|
||||
if (this == &other)
|
||||
return false;
|
||||
|
@ -153,6 +170,28 @@ public:
|
|||
return false;
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#concept-tree-preceding (Object A is 'typename U' and Object B is 'this')
|
||||
template<typename U>
|
||||
bool has_preceding_node_of_type_in_tree_order() const
|
||||
{
|
||||
for (auto* node = previous_in_pre_order(); node; node = node->previous_in_pre_order()) {
|
||||
if (is<U>(node))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#concept-tree-following (Object A is 'typename U' and Object B is 'this')
|
||||
template<typename U>
|
||||
bool has_following_node_of_type_in_tree_order() const
|
||||
{
|
||||
for (auto* node = next_in_pre_order(); node; node = node->next_in_pre_order()) {
|
||||
if (is<U>(node))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename Callback>
|
||||
IterationDecision for_each_in_inclusive_subtree(Callback callback) const
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue