diff options
Diffstat (limited to 'Userland/Libraries/LibWeb/DOM')
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Node.cpp | 13 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Node.h | 3 |
2 files changed, 16 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp index 57a756a109..d249c0b140 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.cpp +++ b/Userland/Libraries/LibWeb/DOM/Node.cpp @@ -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) { diff --git a/Userland/Libraries/LibWeb/DOM/Node.h b/Userland/Libraries/LibWeb/DOM/Node.h index 7e0dd8ec0b..a0dd4bda03 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.h +++ b/Userland/Libraries/LibWeb/DOM/Node.h @@ -45,6 +45,9 @@ public: ParentNode* parent_or_shadow_host(); ParentNode const* parent_or_shadow_host() const { return const_cast<Node*>(this)->parent_or_shadow_host(); } + Element* parent_or_shadow_host_element(); + Element const* parent_or_shadow_host_element() const { return const_cast<Node*>(this)->parent_or_shadow_host_element(); } + virtual ~Node(); // FIXME: Move cleanup to the regular destructor. |