summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/DOM
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-11-05 17:06:19 +0100
committerAndreas Kling <kling@serenityos.org>2022-11-05 18:54:39 +0100
commit87b0ddb354191ff096b29c02de6b8814d418cb27 (patch)
tree5e1b9bb99abd92db469222ad7bbe0501274ee5c6 /Userland/Libraries/LibWeb/DOM
parent9c46fb7337be204e26ba9c1aeb8ac2aace8dff7a (diff)
downloadserenity-87b0ddb354191ff096b29c02de6b8814d418cb27.zip
LibWeb: Add DOM::Node::parent_or_shadow_host_element()
This will be used in style computation to inherit style across shadow tree boundaries.
Diffstat (limited to 'Userland/Libraries/LibWeb/DOM')
-rw-r--r--Userland/Libraries/LibWeb/DOM/Node.cpp13
-rw-r--r--Userland/Libraries/LibWeb/DOM/Node.h3
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.