mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:17:35 +00:00
LibWeb: Make Range.setStart and Range.setEnd spec compliant
These functions are way more involved than simply setting their respective boundary points :^)
This commit is contained in:
parent
af3c866898
commit
46ce50f74e
6 changed files with 185 additions and 11 deletions
|
@ -80,6 +80,16 @@ public:
|
|||
return const_cast<TreeNode*>(this)->child_at_index(index);
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#concept-tree-index
|
||||
size_t index() const
|
||||
{
|
||||
// The index of an object is its number of preceding siblings, or 0 if it has none.
|
||||
size_t index = 0;
|
||||
for (auto* node = previous_sibling(); node; node = node->previous_sibling())
|
||||
++index;
|
||||
return index;
|
||||
}
|
||||
|
||||
Optional<size_t> index_of_child(const T& search_child)
|
||||
{
|
||||
VERIFY(search_child.parent() == this);
|
||||
|
@ -118,6 +128,8 @@ public:
|
|||
bool is_descendant_of(const TreeNode&) const;
|
||||
bool is_inclusive_descendant_of(const TreeNode&) const;
|
||||
|
||||
bool is_following(TreeNode const&) const;
|
||||
|
||||
void append_child(NonnullRefPtr<T> node);
|
||||
void prepend_child(NonnullRefPtr<T> node);
|
||||
void insert_before(NonnullRefPtr<T> node, RefPtr<T> child);
|
||||
|
@ -571,4 +583,17 @@ inline bool TreeNode<T>::is_inclusive_descendant_of(const TreeNode<T>& other) co
|
|||
return other.is_inclusive_ancestor_of(*this);
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#concept-tree-following
|
||||
template<typename T>
|
||||
inline bool TreeNode<T>::is_following(TreeNode<T> const& other) const
|
||||
{
|
||||
// An object A is following an object B if A and B are in the same tree and A comes after B in tree order.
|
||||
for (auto* node = previous_in_pre_order(); node; node = node->previous_in_pre_order()) {
|
||||
if (node == &other)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue