diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp index 5d0125d9e7..26204538bc 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.cpp +++ b/Userland/Libraries/LibWeb/DOM/Node.cpp @@ -259,4 +259,11 @@ void Node::inserted_into(Node&) set_needs_style_update(true); } +ParentNode* Node::parent_or_shadow_host() +{ + if (is(*this)) + return downcast(*this).host(); + return downcast(parent()); +} + } diff --git a/Userland/Libraries/LibWeb/DOM/Node.h b/Userland/Libraries/LibWeb/DOM/Node.h index a62c220fe1..4b1797e0ff 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.h +++ b/Userland/Libraries/LibWeb/DOM/Node.h @@ -57,6 +57,9 @@ public: using TreeNode::ref; using TreeNode::unref; + ParentNode* parent_or_shadow_host(); + const ParentNode* parent_or_shadow_host() const { return const_cast(this)->parent_or_shadow_host(); } + // ^EventTarget virtual void ref_event_target() final { ref(); } virtual void unref_event_target() final { unref(); }