diff options
author | Andreas Kling <kling@serenityos.org> | 2021-02-10 18:22:20 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-02-10 19:06:20 +0100 |
commit | 2eddd74e85d5dbe748507e9dd739c6259ea44964 (patch) | |
tree | eff2f75c83cd5ade45a3e22e6eea7c0e66146e3b /Userland/Libraries/LibWeb/DOM | |
parent | d597626ea1b61cfe7f99d19fb60b451b7d3863f5 (diff) | |
download | serenity-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.cpp | 7 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Node.h | 3 |
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(); } |