LibWeb/DOM: Implement "is closed-shadow-hidden" algorithm

This commit is contained in:
Sam Atkins 2025-06-16 16:48:15 +01:00
parent 1435480d76
commit 3fbd3146a1
Notes: github-actions[bot] 2025-06-17 11:40:03 +00:00
2 changed files with 25 additions and 0 deletions

View file

@ -588,6 +588,29 @@ Node& Node::shadow_including_root()
return node_root; return node_root;
} }
// https://dom.spec.whatwg.org/#concept-closed-shadow-hidden
bool Node::is_closed_shadow_hidden_from(Node const& b) const
{
// A node A is closed-shadow-hidden from a node B if all of the following conditions are true:
auto const& a_root = root();
// - As root is a shadow root.
if (!a_root.is_shadow_root())
return false;
// - As root is not a shadow-including inclusive ancestor of B.
if (a_root.is_shadow_including_inclusive_ancestor_of(b))
return false;
// - As root is a shadow root whose mode is "closed" or As roots host is closed-shadow-hidden from B.
if (a_root.is_shadow_root() && static_cast<ShadowRoot const&>(a_root).mode() == Bindings::ShadowRootMode::Closed)
return true;
if (a_root.is_document_fragment() && static_cast<DocumentFragment const&>(a_root).host()->is_closed_shadow_hidden_from(b))
return true;
return false;
}
// https://dom.spec.whatwg.org/#connected // https://dom.spec.whatwg.org/#connected
bool Node::is_connected() const bool Node::is_connected() const
{ {

View file

@ -294,6 +294,8 @@ public:
return const_cast<Node*>(this)->shadow_including_root(); return const_cast<Node*>(this)->shadow_including_root();
} }
bool is_closed_shadow_hidden_from(Node const&) const;
bool is_connected() const; bool is_connected() const;
[[nodiscard]] bool is_browsing_context_connected() const; [[nodiscard]] bool is_browsing_context_connected() const;