Bug 1269975 part 4 - Make nsCSSPseudoClasses::GetPseudoType() take CSSEnabledState rather than two bool params. r?heycam draft
authorXidorn Quan <quanxunzhen@gmail.com>
Thu, 05 May 2016 11:38:01 +1000
changeset 363589 8a9ccffbd214c6d83ac671953489953884db3057
parent 363588 a02bc6616946eaee1615d24aa195429287ebbbef
child 363593 e07fd5270041e16b3e7dc4e327b05cf46c6a2fec
push id17251
push userxquan@mozilla.com
push dateThu, 05 May 2016 03:35:39 +0000
reviewersheycam
bugs1269975
milestone49.0a1
Bug 1269975 part 4 - Make nsCSSPseudoClasses::GetPseudoType() take CSSEnabledState rather than two bool params. r?heycam MozReview-Commit-ID: Xh50g9hsH9
layout/inspector/inDOMUtils.cpp
layout/style/nsCSSParser.cpp
layout/style/nsCSSPseudoClasses.cpp
layout/style/nsCSSPseudoClasses.h
--- a/layout/inspector/inDOMUtils.cpp
+++ b/layout/inspector/inDOMUtils.cpp
@@ -1206,17 +1206,18 @@ GetStatesForPseudoClass(const nsAString&
     EventStates(),
     EventStates()
   };
   static_assert(MOZ_ARRAY_LENGTH(sPseudoClassStates) ==
                 static_cast<size_t>(CSSPseudoClassType::MAX),
                 "Length of PseudoClassStates array is incorrect");
 
   nsCOMPtr<nsIAtom> atom = NS_Atomize(aStatePseudo);
-  CSSPseudoClassType type = nsCSSPseudoClasses::GetPseudoType(atom, true, true);
+  CSSPseudoClassType type =
+    nsCSSPseudoClasses::GetPseudoType(atom, CSSEnabledState::eIgnore);
 
   // Ignore :moz-any-link so we don't give the element simultaneous
   // visited and unvisited style state
   if (type == CSSPseudoClassType::mozAnyLink) {
     return EventStates();
   }
   // Our array above is long enough that indexing into it with
   // NotPseudo is ok.
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -5909,21 +5909,21 @@ CSSParserImpl::ParsePseudoSelector(int32
   nsAutoString buffer;
   buffer.Append(char16_t(':'));
   buffer.Append(mToken.mIdent);
   nsContentUtils::ASCIIToLower(buffer);
   nsCOMPtr<nsIAtom> pseudo = NS_Atomize(buffer);
 
   // stash away some info about this pseudo so we only have to get it once.
   bool isTreePseudo = false;
+  CSSEnabledState enabledState = EnabledState();
   CSSPseudoElementType pseudoElementType =
     nsCSSPseudoElements::GetPseudoType(pseudo);
   CSSPseudoClassType pseudoClassType =
-    nsCSSPseudoClasses::GetPseudoType(pseudo, AgentRulesEnabled(),
-                                      ChromeRulesEnabled());
+    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();
--- a/layout/style/nsCSSPseudoClasses.cpp
+++ b/layout/style/nsCSSPseudoClasses.cpp
@@ -104,50 +104,27 @@ void
 nsCSSPseudoClasses::PseudoTypeToString(Type aType, nsAString& aString)
 {
   MOZ_ASSERT(aType < Type::Count, "Unexpected type");
   auto idx = static_cast<CSSPseudoClassTypeBase>(aType);
   (*CSSPseudoClasses_info[idx].mAtom)->ToString(aString);
 }
 
 /* static */ CSSPseudoClassType
-nsCSSPseudoClasses::GetPseudoType(nsIAtom* aAtom,
-                                  bool aAgentEnabled, bool aChromeEnabled)
+nsCSSPseudoClasses::GetPseudoType(nsIAtom* aAtom, EnabledState aEnabledState)
 {
   for (uint32_t i = 0; i < ArrayLength(CSSPseudoClasses_info); ++i) {
     if (*CSSPseudoClasses_info[i].mAtom == aAtom) {
       Type type = Type(i);
-      if (sPseudoClassEnabled[i]) {
-        return type;
-      } else {
-        auto flags = FlagsForPseudoClass(type);
-        if ((aChromeEnabled &&
-             (flags & CSS_PSEUDO_CLASS_ENABLED_IN_CHROME)) ||
-            (aAgentEnabled &&
-             (flags & CSS_PSEUDO_CLASS_ENABLED_IN_UA_SHEETS))) {
-          return type;
-        }
-      }
-      return Type::NotPseudo;
+      return IsEnabled(type, aEnabledState) ? type : Type::NotPseudo;
     }
   }
-
   return Type::NotPseudo;
 }
 
 /* static */ bool
 nsCSSPseudoClasses::IsUserActionPseudoClass(Type aType)
 {
   // See http://dev.w3.org/csswg/selectors4/#useraction-pseudos
   return aType == Type::hover ||
          aType == Type::active ||
          aType == Type::focus;
 }
-
-/* static */ uint32_t
-nsCSSPseudoClasses::FlagsForPseudoClass(const Type aType)
-{
-  size_t index = static_cast<size_t>(aType);
-  MOZ_ASSERT(index < ArrayLength(kPseudoClassFlags),
-             "argument must be a pseudo-class");
-  return kPseudoClassFlags[index];
-}
-
--- a/layout/style/nsCSSPseudoClasses.h
+++ b/layout/style/nsCSSPseudoClasses.h
@@ -43,32 +43,47 @@ enum class CSSPseudoClassType : CSSPseud
   MAX
 };
 
 } // namespace mozilla
 
 class nsCSSPseudoClasses
 {
   typedef mozilla::CSSPseudoClassType Type;
+  typedef mozilla::CSSEnabledState EnabledState;
 
 public:
   static void AddRefAtoms();
 
-  static Type GetPseudoType(nsIAtom* aAtom,
-                            bool aAgentEnabled, bool aChromeEnabled);
+  static Type GetPseudoType(nsIAtom* aAtom, EnabledState aEnabledState);
   static bool HasStringArg(Type aType);
   static bool HasNthPairArg(Type aType);
   static bool HasSelectorListArg(Type aType) {
     return aType == Type::any;
   }
   static bool IsUserActionPseudoClass(Type aType);
 
   // Should only be used on types other than Count and NotPseudoClass
   static void PseudoTypeToString(Type aType, nsAString& aString);
 
+  static bool IsEnabled(Type aType, EnabledState aEnabledState)
+  {
+    auto index = static_cast<size_t>(aType);
+    if (sPseudoClassEnabled[index] ||
+        aEnabledState == EnabledState::eIgnore) {
+      return true;
+    }
+    auto flags = kPseudoClassFlags[index];
+    if (((aEnabledState & EnabledState::eChrome) &&
+         (flags & CSS_PSEUDO_CLASS_ENABLED_IN_CHROME)) ||
+        ((aEnabledState & EnabledState::eUASheets) &&
+         (flags & CSS_PSEUDO_CLASS_ENABLED_IN_UA_SHEETS))) {
+      return true;
+    }
+    return false;
+  }
+
 private:
-  static uint32_t FlagsForPseudoClass(const Type aType);
-
   static const uint32_t kPseudoClassFlags[Type::Count];
   static bool sPseudoClassEnabled[Type::Count];
 };
 
 #endif /* nsCSSPseudoClasses_h___ */