1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:17:44 +00:00

LibWeb: Add shadow including ancestor/descendant checks

This commit is contained in:
Luke Wilde 2021-09-02 02:17:13 +01:00 committed by Andreas Kling
parent dd5ceb74e9
commit bd55f0ad64
2 changed files with 38 additions and 0 deletions

View file

@ -655,4 +655,37 @@ bool Node::contains(RefPtr<Node> other) const
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
{
if (is_descendant_of(other))
return true;
if (!is<ShadowRoot>(root()))
return false;
auto shadow_root = verify_cast<ShadowRoot>(root());
// NOTE: While host is nullable because of inheriting from DocumentFragment, shadow roots always have a host.
return shadow_root->host()->is_shadow_including_inclusive_descendant_of(other);
}
// https://dom.spec.whatwg.org/#concept-shadow-including-inclusive-descendant
bool Node::is_shadow_including_inclusive_descendant_of(Node const& other) const
{
return &other == this || is_shadow_including_descendant_of(other);
}
// https://dom.spec.whatwg.org/#concept-shadow-including-ancestor
bool Node::is_shadow_including_ancestor_of(Node const& other) const
{
return other.is_shadow_including_descendant_of(*this);
}
// https://dom.spec.whatwg.org/#concept-shadow-including-inclusive-ancestor
bool Node::is_shadow_including_inclusive_ancestor_of(Node const& other) const
{
return other.is_shadow_including_inclusive_descendant_of(*this);
}
}

View file

@ -174,6 +174,11 @@ public:
// Used for dumping the DOM Tree
void serialize_tree_as_json(JsonObjectSerializer<StringBuilder>&) const;
bool is_shadow_including_descendant_of(Node const&) const;
bool is_shadow_including_inclusive_descendant_of(Node const&) const;
bool is_shadow_including_ancestor_of(Node const&) const;
bool is_shadow_including_inclusive_ancestor_of(Node const&) const;
protected:
Node(Document&, NodeType);