diff --git a/layout/inspector/inDOMUtils.cpp b/layout/inspector/inDOMUtils.cpp index 03ca9c400327..ed4da113cf73 100644 --- a/layout/inspector/inDOMUtils.cpp +++ b/layout/inspector/inDOMUtils.cpp @@ -459,8 +459,8 @@ inDOMUtils::SelectorMatchesElement(nsIDOMElement* aElement, // We need to make sure that the requested pseudo element type // matches the selector pseudo element type before proceeding. nsCOMPtr pseudoElt = NS_Atomize(aPseudo); - if (sel->mSelectors->PseudoType() != nsCSSPseudoElements:: - GetPseudoType(pseudoElt, CSSEnabledState::eIgnoreEnabledState)) { + if (sel->mSelectors->PseudoType() != + nsCSSPseudoElements::GetPseudoType(pseudoElt)) { *aMatches = false; return NS_OK; } @@ -1233,7 +1233,7 @@ inDOMUtils::GetCSSPseudoElementNames(uint32_t* aLength, char16_t*** aNames) static_cast(CSSPseudoElementType::Count); for (CSSPseudoElementTypeBase i = 0; i < pseudoCount; ++i) { CSSPseudoElementType type = static_cast(i); - if (nsCSSPseudoElements::IsEnabled(type, CSSEnabledState::eForAllContent)) { + if (!nsCSSPseudoElements::PseudoElementIsUASheetOnly(type)) { nsIAtom* atom = nsCSSPseudoElements::GetPseudoAtom(type); array.AppendElement(atom); } diff --git a/layout/style/nsCSSParser.cpp b/layout/style/nsCSSParser.cpp index 1ec301595c1e..f4f6e4f2ab50 100644 --- a/layout/style/nsCSSParser.cpp +++ b/layout/style/nsCSSParser.cpp @@ -5916,12 +5916,20 @@ CSSParserImpl::ParsePseudoSelector(int32_t& aDataMask, bool isTreePseudo = false; CSSEnabledState enabledState = EnabledState(); CSSPseudoElementType pseudoElementType = - nsCSSPseudoElements::GetPseudoType(pseudo, enabledState); + nsCSSPseudoElements::GetPseudoType(pseudo); CSSPseudoClassType pseudoClassType = nsCSSPseudoClasses::GetPseudoType(pseudo, enabledState); bool pseudoClassIsUserAction = nsCSSPseudoClasses::IsUserActionPseudoClass(pseudoClassType); + if (pseudoElementType < CSSPseudoElementType::Count && !AgentRulesEnabled() && + nsCSSPseudoElements::PseudoElementIsUASheetOnly(pseudoElementType)) { + // This pseudo-element is not exposed to content. + REPORT_UNEXPECTED_TOKEN(PEPseudoSelUnknown); + UngetToken(); + return eSelectorParsingStatus_Error; + } + if (nsCSSAnonBoxes::IsNonElement(pseudo)) { // Non-element anonymous boxes should not match any rule. REPORT_UNEXPECTED_TOKEN(PEPseudoSelUnknown); diff --git a/layout/style/nsCSSPseudoElements.cpp b/layout/style/nsCSSPseudoElements.cpp index 237b6310c838..3323c5412ce7 100644 --- a/layout/style/nsCSSPseudoElements.cpp +++ b/layout/style/nsCSSPseudoElements.cpp @@ -36,8 +36,7 @@ static const nsStaticAtom CSSPseudoElements_info[] = { // Flags data for each of the pseudo-elements, which must be separate // from the previous array since there's no place for it in // nsStaticAtom. -/* static */ const uint32_t -nsCSSPseudoElements::kPseudoElementFlags[Type::Count] = { +static const uint32_t CSSPseudoElements_flags[] = { #define CSS_PSEUDO_ELEMENT(name_, value_, flags_) \ flags_, #include "nsCSSPseudoElementList.h" @@ -68,22 +67,20 @@ nsCSSPseudoElements::IsCSS2PseudoElement(nsIAtom *aAtom) aAtom == nsCSSPseudoElements::firstLetter || aAtom == nsCSSPseudoElements::firstLine; NS_ASSERTION(nsCSSAnonBoxes::IsAnonBox(aAtom) || - result == PseudoElementHasFlags( - GetPseudoType(aAtom, EnabledState::eIgnoreEnabledState), - CSS_PSEUDO_ELEMENT_IS_CSS2), + result == PseudoElementHasFlags(GetPseudoType(aAtom), + CSS_PSEUDO_ELEMENT_IS_CSS2), "result doesn't match flags"); return result; } /* static */ CSSPseudoElementType -nsCSSPseudoElements::GetPseudoType(nsIAtom *aAtom, EnabledState aEnabledState) +nsCSSPseudoElements::GetPseudoType(nsIAtom *aAtom) { for (CSSPseudoElementTypeBase i = 0; i < ArrayLength(CSSPseudoElements_info); ++i) { if (*CSSPseudoElements_info[i].mAtom == aAtom) { - auto type = static_cast(i); - return IsEnabled(type, aEnabledState) ? type : Type::NotPseudo; + return static_cast(i); } } @@ -108,6 +105,15 @@ nsCSSPseudoElements::GetPseudoAtom(Type aType) static_cast(aType)].mAtom; } +/* static */ uint32_t +nsCSSPseudoElements::FlagsForPseudoElement(const Type aType) +{ + CSSPseudoElementTypeBase index = static_cast(aType); + NS_ASSERTION(index < ArrayLength(CSSPseudoElements_flags), + "argument must be a pseudo-element"); + return CSSPseudoElements_flags[index]; +} + /* static */ bool nsCSSPseudoElements::PseudoElementSupportsUserActionState(const Type aType) { diff --git a/layout/style/nsCSSPseudoElements.h b/layout/style/nsCSSPseudoElements.h index 157b206747cd..a3f7c16aa766 100644 --- a/layout/style/nsCSSPseudoElements.h +++ b/layout/style/nsCSSPseudoElements.h @@ -9,7 +9,6 @@ #define nsCSSPseudoElements_h___ #include "nsIAtom.h" -#include "mozilla/CSSEnabledState.h" // Is this pseudo-element a CSS2 pseudo-element that can be specified // with the single colon syntax (in addition to the double-colon syntax, @@ -66,7 +65,6 @@ class nsICSSPseudoElement : public nsIAtom {}; class nsCSSPseudoElements { typedef mozilla::CSSPseudoElementType Type; - typedef mozilla::CSSEnabledState EnabledState; public: static void AddRefAtoms(); @@ -80,7 +78,7 @@ public: #include "nsCSSPseudoElementList.h" #undef CSS_PSEUDO_ELEMENT - static Type GetPseudoType(nsIAtom* aAtom, EnabledState aEnabledState); + static Type GetPseudoType(nsIAtom* aAtom); // Get the atom for a given Type. aType must be < CSSPseudoElementType::Count static nsIAtom* GetPseudoAtom(Type aType); @@ -97,21 +95,19 @@ public: static bool PseudoElementSupportsUserActionState(const Type aType); - static bool IsEnabled(Type aType, EnabledState aEnabledState) - { - return !PseudoElementHasFlags(aType, CSS_PSEUDO_ELEMENT_UA_SHEET_ONLY) || - (aEnabledState & EnabledState::eInUASheets); + static bool PseudoElementIsUASheetOnly(const Type aType) { + MOZ_ASSERT(aType < Type::Count); + return PseudoElementHasFlags(aType, CSS_PSEUDO_ELEMENT_UA_SHEET_ONLY); } private: + static uint32_t FlagsForPseudoElement(const Type aType); + // Does the given pseudo-element have all of the flags given? static bool PseudoElementHasFlags(const Type aType, uint32_t aFlags) { - MOZ_ASSERT(aType < Type::Count); - return (kPseudoElementFlags[size_t(aType)] & aFlags) == aFlags; + return (FlagsForPseudoElement(aType) & aFlags) == aFlags; } - - static const uint32_t kPseudoElementFlags[Type::Count]; }; #endif /* nsCSSPseudoElements_h___ */ diff --git a/layout/style/nsComputedDOMStyle.cpp b/layout/style/nsComputedDOMStyle.cpp index beb641ddd5db..fab63d4c4a9f 100644 --- a/layout/style/nsComputedDOMStyle.cpp +++ b/layout/style/nsComputedDOMStyle.cpp @@ -488,8 +488,7 @@ nsComputedDOMStyle::GetStyleContextForElementNoFlush(Element* aElement, RefPtr sc; if (aPseudo) { - CSSPseudoElementType type = nsCSSPseudoElements:: - GetPseudoType(aPseudo, CSSEnabledState::eIgnoreEnabledState); + CSSPseudoElementType type = nsCSSPseudoElements::GetPseudoType(aPseudo); if (type >= CSSPseudoElementType::Count) { return nullptr; } diff --git a/layout/style/nsStyleSet.cpp b/layout/style/nsStyleSet.cpp index 0352f2d217af..8cf6b21e2c59 100644 --- a/layout/style/nsStyleSet.cpp +++ b/layout/style/nsStyleSet.cpp @@ -865,9 +865,8 @@ nsStyleSet::GetContext(nsStyleContext* aParentContext, aPseudoType == CSSPseudoElementType::NotPseudo) || (aPseudoTag && - nsCSSPseudoElements::GetPseudoType( - aPseudoTag, CSSEnabledState::eIgnoreEnabledState) == - aPseudoType), + nsCSSPseudoElements::GetPseudoType(aPseudoTag) == + aPseudoType), "Pseudo mismatch"); if (aVisitedRuleNode == aRuleNode) {