LibWeb: Add DOM::Node::parent_or_shadow_host_element()

This will be used in style computation to inherit style across shadow
tree boundaries.
This commit is contained in:
Andreas Kling 2022-11-05 17:06:19 +01:00
commit 87b0ddb354
Notes: sideshowbarker 2024-07-18 02:13:10 +09:00
2 changed files with 16 additions and 0 deletions

View file

@ -872,6 +872,19 @@ ParentNode* Node::parent_or_shadow_host()
return verify_cast<ParentNode>(parent());
}
Element* Node::parent_or_shadow_host_element()
{
if (is<ShadowRoot>(*this))
return static_cast<ShadowRoot&>(*this).host();
if (!parent())
return nullptr;
if (is<Element>(*parent()))
return static_cast<Element*>(parent());
if (is<ShadowRoot>(*parent()))
return static_cast<ShadowRoot&>(*parent()).host();
return nullptr;
}
JS::NonnullGCPtr<NodeList> Node::child_nodes()
{
if (!m_child_nodes) {