From 8d2533ad70566ff4fd69d4d446b5e28e28f7bb2f Mon Sep 17 00:00:00 2001 From: FranklinDM Date: Sat, 18 Mar 2023 23:08:00 +0800 Subject: [PATCH] Issue #1592 - Part 5: Use flattened element tree when looking for a parent while matching ::slotted() --- layout/style/nsCSSRuleProcessor.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/layout/style/nsCSSRuleProcessor.cpp b/layout/style/nsCSSRuleProcessor.cpp index 63c228fda2..5f1eae5481 100644 --- a/layout/style/nsCSSRuleProcessor.cpp +++ b/layout/style/nsCSSRuleProcessor.cpp @@ -2566,6 +2566,11 @@ SelectorMatchesTree(Element* aPrevElement, // The relevant link must be an ancestor of the node being matched. aFlags = SelectorMatchesTreeFlags(aFlags & ~eLookForRelevantLink); nsIContent* parent = prevElement->GetParent(); + // Operate on the flattened element tree when matching the + // ::slotted() pseudo-element. + if (aTreeMatchContext.mRestrictToSlottedPseudo) { + parent = prevElement->GetFlattenedTreeParent(); + } if (parent) { if (aTreeMatchContext.mForStyling) parent->SetFlags(NODE_HAS_SLOW_SELECTOR_LATER_SIBLINGS); @@ -2576,7 +2581,12 @@ SelectorMatchesTree(Element* aPrevElement, // for descendant combinators and child combinators, the element // to test against is the parent else { - nsIContent *content = prevElement->GetParent(); + nsIContent* content = prevElement->GetParent(); + // Operate on the flattened element tree when matching the + // ::slotted() pseudo-element. + if (aTreeMatchContext.mRestrictToSlottedPseudo) { + content = prevElement->GetFlattenedTreeParent(); + } // In the shadow tree, the shadow host behaves as if it // is a featureless parent of top-level elements of the shadow @@ -2584,11 +2594,12 @@ SelectorMatchesTree(Element* aPrevElement, // left most selector because ancestors of the host are not in // the selector match list. ShadowRoot* shadowRoot = content ? - ShadowRoot::FromNode(content) : nullptr; + ShadowRoot::FromNode(content) : + nullptr; if (shadowRoot && !selector->mNext && !crossedShadowRootBoundary) { - content = shadowRoot->GetHost(); - crossedShadowRootBoundary = true; - contentIsFeatureless = true; + content = shadowRoot->GetHost(); + crossedShadowRootBoundary = true; + contentIsFeatureless = true; } // GetParent could return a document fragment; we only want