diff options
author | Matt A. Tobin <email@mattatobin.com> | 2021-12-05 10:00:55 -0500 |
---|---|---|
committer | Matt A. Tobin <email@mattatobin.com> | 2021-12-05 10:00:55 -0500 |
commit | 53b9bb91045f2a80775f2c046c36f96d52b92627 (patch) | |
tree | 74ad138110d8f98dbb046a18fce8e385373a4016 /layout | |
parent | 9f26564e2739ed871bb75c09d708b2bfb71e1a23 (diff) | |
download | aura-central-53b9bb91045f2a80775f2c046c36f96d52b92627.tar.gz |
Revert "Issue %3024 - Part 1: Import William Chen's patches w/o selector implementation, fixed up."
This reverts commit 3f62b90b9542756bc2c2f3392880a4708e17ce80.
Diffstat (limited to 'layout')
-rw-r--r-- | layout/style/StyleRule.cpp | 23 | ||||
-rw-r--r-- | layout/style/StyleRule.h | 7 | ||||
-rw-r--r-- | layout/style/nsCSSParser.cpp | 5 | ||||
-rw-r--r-- | layout/style/nsCSSRuleProcessor.cpp | 124 | ||||
-rw-r--r-- | layout/style/nsRuleProcessorData.h | 35 | ||||
-rw-r--r-- | layout/style/nsStyleSet.cpp | 3 |
6 files changed, 26 insertions, 171 deletions
diff --git a/layout/style/StyleRule.cpp b/layout/style/StyleRule.cpp index c8f1a0a91..6fad62f8b 100644 --- a/layout/style/StyleRule.cpp +++ b/layout/style/StyleRule.cpp @@ -148,8 +148,7 @@ nsPseudoClassList::nsPseudoClassList(CSSPseudoClassType aType, : mType(aType), mNext(nullptr) { - NS_ASSERTION(nsCSSPseudoClasses::HasSelectorListArg(aType) || - nsCSSPseudoClasses::HasOptionalSelectorListArg(aType), + NS_ASSERTION(nsCSSPseudoClasses::HasSelectorListArg(aType), "unexpected pseudo-class"); NS_ASSERTION(aSelectorList, "selector list expected"); MOZ_COUNT_CTOR(nsPseudoClassList); @@ -314,7 +313,6 @@ nsCSSSelector::nsCSSSelector(void) mPseudoClassList(nullptr), mAttrList(nullptr), mNegations(nullptr), - mExplicitUniversal(false), mNext(nullptr), mNameSpace(kNameSpaceID_Unknown), mOperator(0), @@ -384,17 +382,6 @@ void nsCSSSelector::Reset(void) mOperator = char16_t(0); } -bool nsCSSSelector::HasFeatureSelectors() -{ - return mExplicitUniversal || mLowercaseTag || mCasedTag || - mIDList || mClassList || mAttrList; -} - -void nsCSSSelector::SetHasExplicitUniversal() -{ - mExplicitUniversal = true; -} - void nsCSSSelector::SetNameSpace(int32_t aNameSpace) { mNameSpace = aNameSpace; @@ -755,9 +742,9 @@ nsCSSSelector::AppendToStringWithoutCombinatorsOrNegations // Universal selector: avoid writing the universal selector when we // can avoid it, especially since we're required to avoid it for the // inside of :not() - if (wroteNamespace || mExplicitUniversal || + if (wroteNamespace || (!mIDList && !mClassList && !mPseudoClassList && !mAttrList && - aIsNegated)) { + (aIsNegated || !mNegations))) { aString.Append(char16_t('*')); } } else { @@ -765,7 +752,9 @@ nsCSSSelector::AppendToStringWithoutCombinatorsOrNegations nsAutoString tag; (isPseudoElement ? mLowercaseTag : mCasedTag)->ToString(tag); if (isPseudoElement) { - if (mExplicitUniversal) { + if (!mNext) { + // Lone pseudo-element selector -- toss in a wildcard type selector + // XXXldb Why? aString.Append(char16_t('*')); } // While our atoms use one colon, most pseudo-elements require two diff --git a/layout/style/StyleRule.h b/layout/style/StyleRule.h index dbf4e0840..907e55448 100644 --- a/layout/style/StyleRule.h +++ b/layout/style/StyleRule.h @@ -151,8 +151,6 @@ public: nsCSSSelector* Clone() const { return Clone(true, true); } void Reset(void); - bool HasFeatureSelectors(); - void SetHasExplicitUniversal(); void SetNameSpace(int32_t aNameSpace); void SetTag(const nsString& aTag); void AddID(const nsString& aID); @@ -233,10 +231,9 @@ public: // the argument to functional pseudos nsAttrSelector* mAttrList; nsCSSSelector* mNegations; - bool mExplicitUniversal; // True if universal selector explicitly - nsCSSSelector* mNext; // appears in the selector + nsCSSSelector* mNext; int32_t mNameSpace; - char mOperator; + char16_t mOperator; private: // The underlying type of CSSPseudoElementType is uint8_t and // it packs well with mOperator. (char16_t + uint8_t is less than 32bits.) diff --git a/layout/style/nsCSSParser.cpp b/layout/style/nsCSSParser.cpp index 2e2700c38..3d5edbd0e 100644 --- a/layout/style/nsCSSParser.cpp +++ b/layout/style/nsCSSParser.cpp @@ -5639,7 +5639,6 @@ CSSParserImpl::ParseTypeOrUniversalSelector(int32_t& aDataMask, aSelector.SetTag(mToken.mIdent); } else if (mToken.IsSymbol('*')) { // universal selector - aSelector.SetHasExplicitUniversal(); aDataMask |= SEL_MASK_ELEM; // don't set tag } @@ -5651,7 +5650,6 @@ CSSParserImpl::ParseTypeOrUniversalSelector(int32_t& aDataMask, } else { // was universal element selector SetDefaultNamespaceOnSelector(aSelector); - aSelector.SetHasExplicitUniversal(); aDataMask |= SEL_MASK_ELEM; // don't set any tag in the selector } @@ -6091,8 +6089,7 @@ CSSParserImpl::ParsePseudoSelector(int32_t& aDataMask, CSSPseudoClassType::negation == pseudoClassType || nsCSSPseudoClasses::HasStringArg(pseudoClassType) || nsCSSPseudoClasses::HasNthPairArg(pseudoClassType) || - nsCSSPseudoClasses::HasSelectorListArg(pseudoClassType)) && - !nsCSSPseudoClasses::HasOptionalSelectorListArg(pseudoClassType)) { + nsCSSPseudoClasses::HasSelectorListArg(pseudoClassType))) { // There are no other function pseudos REPORT_UNEXPECTED_TOKEN(PEPseudoSelNonFunc); UngetToken(); diff --git a/layout/style/nsCSSRuleProcessor.cpp b/layout/style/nsCSSRuleProcessor.cpp index 04b4e3608..aed26a1c0 100644 --- a/layout/style/nsCSSRuleProcessor.cpp +++ b/layout/style/nsCSSRuleProcessor.cpp @@ -48,7 +48,6 @@ #include "nsCSSRules.h" #include "nsStyleSet.h" #include "mozilla/dom/Element.h" -#include "mozilla/dom/ShadowRoot.h" #include "nsNthIndexCache.h" #include "mozilla/ArrayUtils.h" #include "mozilla/EventStates.h" @@ -1322,17 +1321,9 @@ struct NodeMatchContext { // mForStyling is false, we have to assume we don't know.) const bool mIsRelevantLink; - // If the node should be considered featureless (as specified in - // selectors 4), then mIsFeature should be set to true to prevent - // matching unless the selector is a special pseudo class or pseudo - // element that matches featureless elements. - const bool mIsFeatureless; - - NodeMatchContext(EventStates aStateMask, bool aIsRelevantLink, - bool aIsFeatureless = false) + NodeMatchContext(EventStates aStateMask, bool aIsRelevantLink) : mStateMask(aStateMask) , mIsRelevantLink(aIsRelevantLink) - , mIsFeatureless(aIsFeatureless) { } }; @@ -1619,11 +1610,6 @@ StateSelectorMatches(Element* aElement, return true; } -static bool AnySelectorInArgListMatches(Element* aElement, - nsPseudoClassList* aList, - NodeMatchContext& aNodeMatchContext, - TreeMatchContext& aTreeMatchContext); - static bool StateSelectorMatches(Element* aElement, nsCSSSelector* aSelector, @@ -1645,17 +1631,6 @@ StateSelectorMatches(Element* aElement, return true; } -// Returns whether aSelector can match featureless elements. -static bool CanMatchFeaturelessElement(nsCSSSelector* aSelector) -{ - if (aSelector->HasFeatureSelectors()) { - return false; - } - - return false; -} - - // |aDependence| has two functions: // * when non-null, it indicates that we're processing a negation, // which is done only when SelectorMatches calls itself recursively @@ -1676,11 +1651,6 @@ static bool SelectorMatches(Element* aElement, "is false since we don't know how to set it correctly in " "Has(Attribute|State)DependentStyle"); - if (aNodeMatchContext.mIsFeatureless && - !CanMatchFeaturelessElement(aSelector)) { - return false; - } - // namespace/tag match // optimization : bail out early if we can if ((kNameSpaceID_Unknown != aSelector->mNameSpace && @@ -1879,9 +1849,18 @@ static bool SelectorMatches(Element* aElement, case CSSPseudoClassType::any: { - if (!AnySelectorInArgListMatches(aElement, pseudoClass, - aNodeMatchContext, - aTreeMatchContext)) { + nsCSSSelectorList *l; + for (l = pseudoClass->u.mSelectors; l; l = l->mNext) { + nsCSSSelector *s = l->mSelectors; + MOZ_ASSERT(!s->mNext && !s->IsPseudoElement(), + "parser failed"); + if (SelectorMatches( + aElement, s, aNodeMatchContext, aTreeMatchContext, + SelectorMatchesFlags::IS_PSEUDO_CLASS_ARGUMENT)) { + break; + } + } + if (!l) { return false; } } @@ -2263,26 +2242,6 @@ static bool SelectorMatches(Element* aElement, return result; } -static bool AnySelectorInArgListMatches(Element* aElement, - nsPseudoClassList* aList, - NodeMatchContext& aNodeMatchContext, - TreeMatchContext& aTreeMatchContext) -{ - nsCSSSelectorList *l; - for (l = aList->u.mSelectors; l; l = l->mNext) { - nsCSSSelector *s = l->mSelectors; - MOZ_ASSERT(!s->mNext && !s->IsPseudoElement(), - "parser failed"); - if (SelectorMatches( - aElement, s, aNodeMatchContext, aTreeMatchContext, - SelectorMatchesFlags::IS_PSEUDO_CLASS_ARGUMENT)) { - break; - } - } - - return !!l; -} - #undef STATE_CHECK #ifdef DEBUG @@ -2372,9 +2331,7 @@ SelectorMatchesTree(Element* aPrevElement, MOZ_ASSERT(!aSelector || !aSelector->IsPseudoElement()); nsCSSSelector* selector = aSelector; Element* prevElement = aPrevElement; - bool crossedShadowRootBoundary = false; while (selector) { // check compound selectors - bool contentIsFeatureless = false; NS_ASSERTION(!selector->mNext || selector->mNext->mOperator != char16_t(0), "compound selector without combinator"); @@ -2405,20 +2362,6 @@ SelectorMatchesTree(Element* aPrevElement, // to test against is the parent else { nsIContent *content = prevElement->GetParent(); - - // In the shadow tree, the shadow host behaves as if it - // is a featureless parent of top-level elements of the shadow - // tree. Only cross shadow root boundary when the selector is the - // left most selector because ancestors of the host are not in - // the selector match list. - ShadowRoot* shadowRoot = content ? - ShadowRoot::FromNode(content) : nullptr; - if (shadowRoot && !selector->mNext && !crossedShadowRootBoundary) { - content = shadowRoot->GetHost(); - crossedShadowRootBoundary = true; - contentIsFeatureless = true; - } - // GetParent could return a document fragment; we only want // element parents. if (content && content->IsElement()) { @@ -2470,8 +2413,7 @@ SelectorMatchesTree(Element* aPrevElement, } const bool isRelevantLink = (aFlags & eLookForRelevantLink) && nsCSSRuleProcessor::IsLink(element); - - NodeMatchContext nodeContext(EventStates(), isRelevantLink, contentIsFeatureless); + NodeMatchContext nodeContext(EventStates(), isRelevantLink); if (isRelevantLink) { // If we find an ancestor of the matched node that is a link // during the matching process, then it's the relevant link (see @@ -2541,20 +2483,6 @@ void ContentEnumFunc(const RuleValue& value, nsCSSSelector* aSelector, // We won't match; nothing else to do here return; } - // If mOnlyMatchHostPseudo is set, then we only want to match against - // selectors that contain a :host-context pseudo class. - if (data->mTreeMatchContext.mOnlyMatchHostPseudo) { - nsCSSSelector* selector = aSelector; - while (selector && selector->mNext != nullptr) { - selector = selector->mNext; - } - - bool seenHostPseudo = false; - - if (!seenHostPseudo) { - return; - } - } if (!data->mTreeMatchContext.SetStyleScopeForSelectorMatching(data->mElement, data->mScope)) { // The selector is for a rule in a scoped style sheet, and the subject @@ -2614,8 +2542,7 @@ nsCSSRuleProcessor::RulesMatching(ElementRuleProcessorData *aData) if (cascade) { NodeMatchContext nodeContext(EventStates(), - nsCSSRuleProcessor::IsLink(aData->mElement), - aData->mElementIsFeatureless); + nsCSSRuleProcessor::IsLink(aData->mElement)); cascade->mRuleHash.EnumerateAllRules(aData->mElement, aData, nodeContext); } } @@ -2897,24 +2824,6 @@ AttributeEnumFunc(nsCSSSelector* aSelector, nsRestyleHint possibleChange = RestyleHintForSelectorWithAttributeChange(aData->change, aSelector, aRightmostSelector); - // If mOnlyMatchHostPseudo is set, then we only want to match against - // selectors that contain a :host-context pseudo class. - if (data->mTreeMatchContext.mOnlyMatchHostPseudo) { - nsCSSSelector* selector = aSelector; - while (selector && selector->mNext != nullptr) { - selector = selector->mNext; - } - - bool seenHostPseudo = false; - break; - } - } - - if (!seenHostPseudo) { - return; - } - } - // If, ignoring eRestyle_SomeDescendants, enumData->change already includes // all the bits of possibleChange, don't bother calling SelectorMatches, since @@ -3386,7 +3295,7 @@ AddSelector(RuleCascadeData* aCascade, } } - // Recur through any :-moz-any or :host-context selectors + // Recur through any :-moz-any selectors for (nsPseudoClassList* pseudoClass = negation->mPseudoClassList; pseudoClass; pseudoClass = pseudoClass->mNext) { if (pseudoClass->mType == CSSPseudoClassType::any) { @@ -4034,7 +3943,6 @@ TreeMatchContext::InitAncestors(Element *aElement) for (uint32_t i = ancestors.Length(); i-- != 0; ) { mAncestorFilter.PushAncestor(ancestors[i]); PushStyleScope(ancestors[i]); - PushShadowHost(ancestors[i]); } } } diff --git a/layout/style/nsRuleProcessorData.h b/layout/style/nsRuleProcessorData.h index f6d977100..fbaa768cc 100644 --- a/layout/style/nsRuleProcessorData.h +++ b/layout/style/nsRuleProcessorData.h @@ -164,23 +164,6 @@ struct MOZ_STACK_CLASS TreeMatchContext { mStyleScopes.TruncateLength(mStyleScopes.Length() - 1); } } - - void PushShadowHost(mozilla::dom::Element* aElement) - { - NS_PRECONDITION(aElement, "aElement must not be null"); - if (aElement->GetShadowRoot()) { - mShadowHosts.AppendElement(aElement); - } - } - - void PopShadowHost(mozilla::dom::Element* aElement) - { - NS_PRECONDITION(aElement, "aElement must not be null"); - if (mShadowHosts.SafeLastElement(nullptr) == aElement) { - mShadowHosts.TruncateLength(mShadowHosts.Length() - 1); - } - } - bool PopStyleScopeForSelectorMatching(mozilla::dom::Element* aElement) { @@ -250,7 +233,6 @@ struct MOZ_STACK_CLASS TreeMatchContext { MOZ_GUARD_OBJECT_NOTIFIER_PARAM) : mPushedAncestor(false) , mPushedStyleScope(false) - , mPushedShadowHost(false) , mTreeMatchContext(aTreeMatchContext) , mElement(nullptr) { @@ -263,10 +245,8 @@ struct MOZ_STACK_CLASS TreeMatchContext { mElement = aElement; mPushedAncestor = true; mPushedStyleScope = true; - mPushedShadowHost = true; mTreeMatchContext.mAncestorFilter.PushAncestor(aElement); mTreeMatchContext.PushStyleScope(aElement); - mTreeMatchContext.PushShadowHost(aElement); } } @@ -298,15 +278,11 @@ struct MOZ_STACK_CLASS TreeMatchContext { if (mPushedStyleScope) { mTreeMatchContext.PopStyleScope(mElement); } - if (mPushedShadowHost) { - mTreeMatchContext.PopShadowHost(mElement); - } } private: bool mPushedAncestor; bool mPushedStyleScope; - bool mPushedShadowHost; TreeMatchContext& mTreeMatchContext; mozilla::dom::Element* mElement; MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER @@ -366,11 +342,6 @@ struct MOZ_STACK_CLASS TreeMatchContext { // The document we're working with. nsIDocument* const mDocument; - // Only selectors that contain :host or :host-context pseudo class - // should be matched against elements. All other selectors should not - // match. - bool mOnlyMatchHostPseudo; - // Root of scoped stylesheet (set and unset by the supplier of the // scoped stylesheet). nsIContent* mScopedRoot; @@ -412,9 +383,6 @@ struct MOZ_STACK_CLASS TreeMatchContext { // <style scoped> child). AutoTArray<mozilla::dom::Element*, 1> mStyleScopes; - // List of ancestor elements that are a shadow root host. - AutoTArray<mozilla::dom::Element*, 1> mShadowHosts; - // The current style scope element for selector matching. mozilla::dom::Element* mCurrentStyleScope; @@ -428,7 +396,6 @@ struct MOZ_STACK_CLASS TreeMatchContext { , mHaveSpecifiedScope(false) , mVisitedHandling(aVisitedHandling) , mDocument(aDocument) - , mOnlyMatchHostPseudo(false) , mScopedRoot(nullptr) , mIsHTMLDocument(aDocument->IsHTMLDocument()) , mCompatMode(aDocument->GetCompatibilityMode()) @@ -470,7 +437,6 @@ struct MOZ_STACK_CLASS ElementDependentRuleProcessorData : : RuleProcessorData(aPresContext, aRuleWalker) , mElement(aElement) , mTreeMatchContext(aTreeMatchContext) - , mElementIsFeatureless(false) { NS_ASSERTION(aElement, "null element leaked into SelectorMatches"); NS_ASSERTION(aElement->OwnerDoc(), "Document-less node here?"); @@ -480,7 +446,6 @@ struct MOZ_STACK_CLASS ElementDependentRuleProcessorData : mozilla::dom::Element* const mElement; // weak ref, must not be null TreeMatchContext& mTreeMatchContext; - bool mElementIsFeatureless; }; struct MOZ_STACK_CLASS ElementRuleProcessorData : diff --git a/layout/style/nsStyleSet.cpp b/layout/style/nsStyleSet.cpp index edf61d2f9..5890100eb 100644 --- a/layout/style/nsStyleSet.cpp +++ b/layout/style/nsStyleSet.cpp @@ -1311,9 +1311,8 @@ nsStyleSet::WalkRuleProcessors(nsIStyleRuleProcessor::EnumFunc aFunc, if (mBindingManager) { // We can supply additional document-level sheets that should be walked. if (aWalkAllXBLStylesheets) { - mBindingManager->WalkAllRules(aFunc, aData, false); + mBindingManager->WalkAllRules(aFunc, aData); } else { - mBindingManager->WalkAllShadowRootHostRules(aFunc, aData); mBindingManager->WalkRules(aFunc, aData, &cutOffInheritance); } } |