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

LibWeb: Add DOM::Node::parent_or_shadow_host()

This is useful when you want to traverse across shadow boundaries.
This commit is contained in:
Andreas Kling 2021-02-10 18:22:20 +01:00
parent d597626ea1
commit 2eddd74e85
2 changed files with 10 additions and 0 deletions

View file

@ -259,4 +259,11 @@ void Node::inserted_into(Node&)
set_needs_style_update(true);
}
ParentNode* Node::parent_or_shadow_host()
{
if (is<ShadowRoot>(*this))
return downcast<ShadowRoot>(*this).host();
return downcast<ParentNode>(parent());
}
}

View file

@ -57,6 +57,9 @@ public:
using TreeNode<Node>::ref;
using TreeNode<Node>::unref;
ParentNode* parent_or_shadow_host();
const ParentNode* parent_or_shadow_host() const { return const_cast<Node*>(this)->parent_or_shadow_host(); }
// ^EventTarget
virtual void ref_event_target() final { ref(); }
virtual void unref_event_target() final { unref(); }