LibWeb: Move non-DOM-related methods from DOM::Node to TreeNode

Motivated by wanting to do `is_before()` on a Layout::Node, and thought
I might as well move as many as possible while I was at it.
This commit is contained in:
Sam Atkins 2025-06-07 13:01:04 +01:00 committed by Andreas Kling
commit ea33bdc975
Notes: github-actions[bot] 2025-06-07 14:51:50 +00:00
3 changed files with 154 additions and 156 deletions

View file

@ -575,17 +575,6 @@ String Node::child_text_content() const
return MUST(builder.to_string());
}
// https://dom.spec.whatwg.org/#concept-tree-root
Node& Node::root()
{
// The root of an object is itself, if its parent is null, or else it is the root of its parent.
// The root of a tree is any object participating in that tree whose parent is null.
Node* root = this;
while (root->parent())
root = root->parent();
return *root;
}
// https://dom.spec.whatwg.org/#concept-shadow-including-root
Node& Node::shadow_including_root()
{
@ -1977,13 +1966,6 @@ bool Node::is_scripting_disabled() const
return !is_scripting_enabled();
}
// https://dom.spec.whatwg.org/#dom-node-contains
bool Node::contains(GC::Ptr<Node> other) const
{
// The contains(other) method steps are to return true if other is an inclusive descendant of this; otherwise false (including when other is null).
return other && other->is_inclusive_descendant_of(*this);
}
// https://dom.spec.whatwg.org/#concept-shadow-including-descendant
bool Node::is_shadow_including_descendant_of(Node const& other) const
{
@ -2588,28 +2570,6 @@ void Node::remove_child_impl(GC::Ref<Node> node)
TreeNode::remove_child(node);
}
bool Node::is_descendant_of(Node const& other) const
{
return other.is_ancestor_of(*this);
}
bool Node::is_inclusive_descendant_of(Node const& other) const
{
return other.is_inclusive_ancestor_of(*this);
}
// https://dom.spec.whatwg.org/#concept-tree-following
bool Node::is_following(Node 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;
}
void Node::build_accessibility_tree(AccessibilityTreeNode& parent)
{
if (is_uninteresting_whitespace_node())