From 5c002ce200a63f4e3b69f7fb6f0dabe966358617 Mon Sep 17 00:00:00 2001 From: Jeremy Andrews Date: Thu, 4 Nov 2021 04:07:12 -0500 Subject: [PATCH] Issue #1593 - Part 2: Account for Shadow DOM v1 and iterator in nsBindingManager. --- dom/xbl/nsBindingManager.cpp | 55 ++++++------------------------------ 1 file changed, 9 insertions(+), 46 deletions(-) diff --git a/dom/xbl/nsBindingManager.cpp b/dom/xbl/nsBindingManager.cpp index 189616e09f..6fb29ca871 100644 --- a/dom/xbl/nsBindingManager.cpp +++ b/dom/xbl/nsBindingManager.cpp @@ -669,25 +669,13 @@ nsBindingManager::WalkRules(nsIStyleRuleProcessor::EnumFunc aFunc, aData->mElementIsFeatureless = true; ShadowRoot* currentShadow = aData->mElement->GetShadowRoot(); - // XXX: Obviously not the right approach for Shadow DOM v1. - // Per spec, rules from younger shadow DOM win over rules from older shadow - // DOM. Iterate to the oldest shadow root on the host then walk back to the - // youngest when walking rules. - while (currentShadow) { - ShadowRoot* olderShadow = currentShadow->GetOlderShadowRoot(); - if (!olderShadow) { - break; - } - currentShadow = olderShadow; - } - while (currentShadow) { + if (currentShadow) { nsXBLBinding* associatedBinding = currentShadow->GetAssociatedBinding(); if (associatedBinding) { aData->mTreeMatchContext.mScopedRoot = aData->mElement; associatedBinding->WalkRules(aFunc, aData); } - currentShadow = currentShadow->GetYoungerShadowRoot(); } aData->mElementIsFeatureless = false; @@ -733,24 +721,10 @@ nsBindingManager::WalkRules(nsIStyleRuleProcessor::EnumFunc aFunc, typedef nsTHashtable > RuleProcessorSet; -// XXX: Figure out what the anonymous namespace is for. Is this even appropriate now that we're using iterators instead of enumerators? - -namespace { - -struct RuleProcessorsData { - RuleProcessorSet* mSet; - bool mOnlyWalkShadowHosts; -}; - -} // anonymous namespace - - static RuleProcessorSet* -GetContentSetRuleProcessors(nsTHashtable>* aContentSet) +GetContentSetRuleProcessors(nsTHashtable>* aContentSet, bool aOnlyWalkShadowRootRules) { - RuleProcessorsData* data = nullptr; - RuleProcessorSet* set = data->mSet; - + RuleProcessorSet* set = nullptr; for (auto iter = aContentSet->Iter(); !iter.Done(); iter.Next()) { nsIContent* boundContent = iter.Get()->GetKey(); @@ -758,7 +732,7 @@ GetContentSetRuleProcessors(nsTHashtable>* aContentS // If we are only walking rules for shadow root hosts, skip other types // of bound content. ShadowRoot *shadowRoot = boundContent->GetShadowRoot(); - if (data->mOnlyWalkShadowHosts && !shadowRoot) { + if (aOnlyWalkShadowRootRules && !shadowRoot) { return set; } @@ -767,7 +741,7 @@ GetContentSetRuleProcessors(nsTHashtable>* aContentS // inheritance chain. Additionally, a bound content may host multiple // shadow roots, each with its own rule processor. nsXBLBinding *binding = boundContent->GetXBLBinding(); - while (binding) { + if (binding) { nsIStyleRuleProcessor* ruleProc = binding->PrototypeBinding()->GetRuleProcessor(); if (ruleProc) { @@ -778,24 +752,15 @@ GetContentSetRuleProcessors(nsTHashtable>* aContentS } binding = binding->GetBaseBinding(); - // XXX: Obviously not the right approach for Shadow DOM v1. - // If there isn't a base binding, start walking the binding of the - // next older shadow root hosted by the bound content (if any). - if (!binding && shadowRoot) { - shadowRoot = shadowRoot->GetOlderShadowRoot(); - if (shadowRoot) { - binding = shadowRoot->GetAssociatedBinding(); + if (shadowRoot) { + binding = shadowRoot->GetAssociatedBinding(); } } } - } return set; } -// XXX: I think since this calls GetContentSetRuleProcessors directly now, no changes should be needed here? The original enumerator patch used the RuleProcessorsData function from the anonymous namespace here. - - void nsBindingManager::WalkAllRules(nsIStyleRuleProcessor::EnumFunc aFunc, ElementDependentRuleProcessorData* aData, @@ -806,7 +771,7 @@ nsBindingManager::WalkAllRules(nsIStyleRuleProcessor::EnumFunc aFunc, } nsAutoPtr set; - set = GetContentSetRuleProcessors(mBoundContentSet); + set = GetContentSetRuleProcessors(mBoundContentSet, aOnlyWalkShadowRootRules); if (!set) { return; } @@ -828,8 +793,6 @@ nsBindingManager::WalkAllShadowRootHostRules(nsIStyleRuleProcessor::EnumFunc aFu aData->mTreeMatchContext.mOnlyMatchHostPseudo = false; } -//XXX: I think since this calls GetContentSetRuleProcessors directly now, no changes should be needed here? The original enumerator patch used the RuleProcessorsData function from the anonymous namespace here. - nsresult nsBindingManager::MediumFeaturesChanged(nsPresContext* aPresContext, bool* aRulesChanged) @@ -840,7 +803,7 @@ nsBindingManager::MediumFeaturesChanged(nsPresContext* aPresContext, } nsAutoPtr set; - set = GetContentSetRuleProcessors(mBoundContentSet); + set = GetContentSetRuleProcessors(mBoundContentSet, false); if (!set) { return NS_OK; }