diff options
author | FranklinDM <mrmineshafter17@gmail.com> | 2023-01-03 20:52:31 +0800 |
---|---|---|
committer | FranklinDM <mrmineshafter17@gmail.com> | 2023-02-20 23:35:47 +0800 |
commit | 024b7500d1aa18b4b9170297ac8b8015b772010b (patch) | |
tree | 3a449df80f916f1377e53be23c0a557dfd067065 /layout/style/nsCSSRuleProcessor.cpp | |
parent | 9b1b294e294374cc6ccde925ca040e019c2daf39 (diff) | |
download | uxp-024b7500d1aa18b4b9170297ac8b8015b772010b.tar.gz |
Issue #2078 - Part 1: Update CSS rule processor to handle :is() and :where() CSS pseudo-classes
This modifies selector list parsing to accommodate being "forgiving". Aliases for the :is selector's former names were also included. Note that the older and prefixed variant `-moz-any` remains unforgiving.
Diffstat (limited to 'layout/style/nsCSSRuleProcessor.cpp')
-rw-r--r-- | layout/style/nsCSSRuleProcessor.cpp | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/layout/style/nsCSSRuleProcessor.cpp b/layout/style/nsCSSRuleProcessor.cpp index f49b9d3258..15838f411e 100644 --- a/layout/style/nsCSSRuleProcessor.cpp +++ b/layout/style/nsCSSRuleProcessor.cpp @@ -1622,7 +1622,8 @@ StateSelectorMatches(Element* aElement, static bool AnySelectorInArgListMatches(Element* aElement, nsPseudoClassList* aList, NodeMatchContext& aNodeMatchContext, - TreeMatchContext& aTreeMatchContext); + TreeMatchContext& aTreeMatchContext, + bool aIsForgiving = false); static bool StateSelectorMatches(Element* aElement, @@ -1886,7 +1887,21 @@ static bool SelectorMatches(Element* aElement, } break; + case CSSPseudoClassType::is: + case CSSPseudoClassType::matches: case CSSPseudoClassType::any: + case CSSPseudoClassType::where: + { + if (!AnySelectorInArgListMatches(aElement, pseudoClass, + aNodeMatchContext, + aTreeMatchContext, + true)) { + return false; + } + } + break; + + case CSSPseudoClassType::mozAny: { if (!AnySelectorInArgListMatches(aElement, pseudoClass, aNodeMatchContext, @@ -2355,11 +2370,17 @@ static bool SelectorMatches(Element* aElement, static bool AnySelectorInArgListMatches(Element* aElement, nsPseudoClassList* aList, NodeMatchContext& aNodeMatchContext, - TreeMatchContext& aTreeMatchContext) + TreeMatchContext& aTreeMatchContext, + bool aIsForgiving) { nsCSSSelectorList *l; for (l = aList->u.mSelectors; l; l = l->mNext) { nsCSSSelector *s = l->mSelectors; + if (s == nullptr) { + MOZ_ASSERT(aIsForgiving, + "unexpected empty selector in unforgiving selector list"); + return false; + } MOZ_ASSERT(!s->mNext && !s->IsPseudoElement(), "parser failed"); if (SelectorMatches( @@ -3494,12 +3515,10 @@ AddSelector(RuleCascadeData* aCascade, } } - // Recur through any :-moz-any or :host-context selectors + // Recur through any pseudo-class that has a selector list argument. for (nsPseudoClassList* pseudoClass = negation->mPseudoClassList; pseudoClass; pseudoClass = pseudoClass->mNext) { - if (pseudoClass->mType == CSSPseudoClassType::any || - pseudoClass->mType == CSSPseudoClassType::host || - pseudoClass->mType == CSSPseudoClassType::hostContext) { + if (nsCSSPseudoClasses::HasSelectorListArg(pseudoClass->mType)) { for (nsCSSSelectorList *l = pseudoClass->u.mSelectors; l; l = l->mNext) { nsCSSSelector *s = l->mSelectors; if (!AddSelector(aCascade, aSelectorInTopLevel, s, |