Truly independent web browser
LibWeb: Skip shadow roots in Node::flat_tree_parent()
Jelle Raaijmakersa67338ccc2cf
diff --git a/Libraries/LibWeb/CSS/Invalidation/PseudoClassInvalidator.cpp b/Libraries/LibWeb/CSS/Invalidation/PseudoClassInvalidator.cppindex 0446a5c3734..3a813ce1628 100644--- a/Libraries/LibWeb/CSS/Invalidation/PseudoClassInvalidator.cpp+++ b/Libraries/LibWeb/CSS/Invalidation/PseudoClassInvalidator.cpp@@ -12,6 +12,7 @@#include <LibWeb/CSS/StyleEngineInput.h>#include <LibWeb/DOM/Document.h>#include <LibWeb/DOM/Element.h>+#include <LibWeb/DOM/ShadowRoot.h>namespace Web::CSS::Invalidation {@@ -109,6 +110,8 @@ static bool subtree_holds_propagating_state_source(DOM::Node const& subtree, CSSfor (auto const* node = &source; node; node = node->flat_tree_parent()) {if (node == &subtree)return true;+ if (is<DOM::ShadowRoot>(subtree) && node->parent() == &subtree)+ return true;}return false;}diff --git a/Libraries/LibWeb/DOM/Node.cpp b/Libraries/LibWeb/DOM/Node.cppindex 9d48f440440..08bb280a61e 100644--- a/Libraries/LibWeb/DOM/Node.cpp+++ b/Libraries/LibWeb/DOM/Node.cpp@@ -2878,14 +2878,26 @@ Element* Node::parent_or_shadow_host_element()return nullptr;}+// https://drafts.csswg.org/css-shadow-1/#flat-treeParentNode* Node::flat_tree_parent(){- // If we're assigned to a slot, that slot is our flat tree parent.+ // pending node is a slot+ // Find slottables for pending node, and append them to pending nodes, with pending node as their associated+ // parent.if (auto slot = assigned_slot_for_node(*this))return slot.ptr();- // Otherwise, this is the parent or shadow host.- return parent_or_shadow_host();+ // pending node is a shadow host+ // Append the child nodes of the shadow root of the shadow tree it hosts to pending nodes, with pending node as+ // their associated parent.+ auto* parent = parent_or_shadow_host();+ if (auto* shadow_root = as_if<ShadowRoot>(parent))+ return shadow_root->host();++ // Otherwise,+ // Append the child nodes of pending node’s light tree to pending nodes, with pending node as their associated+ // parent.+ return parent;}Element* Node::flat_tree_parent_element()diff --git a/Tests/LibWeb/Text/expected/UIEvents/click-common-ancestor.txt b/Tests/LibWeb/Text/expected/UIEvents/click-common-ancestor.txtindex dbd2643121f..4587b4897b0 100644--- a/Tests/LibWeb/Text/expected/UIEvents/click-common-ancestor.txt+++ b/Tests/LibWeb/Text/expected/UIEvents/click-common-ancestor.txt@@ -11,4 +11,5 @@ removed press target: no clickremoved during mouseup: no clickshrinking icon: click on buttonslotted to shadow sibling: click on shadow-parent+shadow root children: click on hostancestor activation: truediff --git a/Tests/LibWeb/Text/input/UIEvents/click-common-ancestor.html b/Tests/LibWeb/Text/input/UIEvents/click-common-ancestor.htmlindex de8b302fceb..79d57ad3fec 100644--- a/Tests/LibWeb/Text/input/UIEvents/click-common-ancestor.html+++ b/Tests/LibWeb/Text/input/UIEvents/click-common-ancestor.html@@ -55,6 +55,9 @@shadow.innerHTML = `<div id="shadow-parent" style="width:200px;height:100px"><slot></slot><div id="shadow-child" style="position:absolute;left:70px;top:0;width:40px;height:40px"></div></div>`;pressAndRelease("slotted to shadow sibling", [60, 60], [120, 60]);+ shadow.innerHTML = `<div id="shadow-first" style="position:absolute;left:10px;top:10px;width:40px;height:40px"></div>+ <div id="shadow-second" style="position:absolute;left:70px;top:10px;width:40px;height:40px"></div>`;+ pressAndRelease("shadow root children", [60, 60], [120, 60]);fixture.innerHTML = `<label id="label" for="checkbox" style="display:block;width:200px;height:100px"><span id="label-first" style="position:absolute;left:0;top:0;width:40px;height:40px"></span>