summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/DOM
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-02-10 18:22:20 +0100
committerAndreas Kling <kling@serenityos.org>2021-02-10 19:06:20 +0100
commit2eddd74e85d5dbe748507e9dd739c6259ea44964 (patch)
treeeff2f75c83cd5ade45a3e22e6eea7c0e66146e3b /Userland/Libraries/LibWeb/DOM
parentd597626ea1b61cfe7f99d19fb60b451b7d3863f5 (diff)
downloadserenity-2eddd74e85d5dbe748507e9dd739c6259ea44964.zip
LibWeb: Add DOM::Node::parent_or_shadow_host()
This is useful when you want to traverse across shadow boundaries.
Diffstat (limited to 'Userland/Libraries/LibWeb/DOM')
-rw-r--r--Userland/Libraries/LibWeb/DOM/Node.cpp7
-rw-r--r--Userland/Libraries/LibWeb/DOM/Node.h3
2 files changed, 10 insertions, 0 deletions
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<ShadowRoot>(*this))
+ return downcast<ShadowRoot>(*this).host();
+ return downcast<ParentNode>(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<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(); }