Bug 1269975 part 4 - Make nsCSSPseudoClasses::GetPseudoType() take CSSEnabledState rather than two bool params. r=heycam
authorXidorn Quan <quanxunzhen@gmail.com>
Tue, 10 May 2016 18:44:05 +1000
changeset 296748 e29698cb0cf5ab1c3e16eab9fc0099ab06cba7d5
parent 296747 d0769e80038115a28d497bcdc1166ae216f46747
child 296749 03a6279bb233dbf539d8ff4614f6309b90f3ca43
push id76467
push userxquan@mozilla.com
push dateTue, 10 May 2016 08:51:33 +0000
treeherdermozilla-inbound@7fa52daaae36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1269975
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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::eIgnoreEnabledState);
 
   // 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
@@ -105,50 +105,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,48 @@ 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);
+    MOZ_ASSERT(index < static_cast<size_t>(Type::Count));
+    if (sPseudoClassEnabled[index] ||
+        aEnabledState == EnabledState::eIgnoreEnabledState) {
+      return true;
+    }
+    auto flags = kPseudoClassFlags[index];
+    if (((aEnabledState & EnabledState::eInChrome) &&
+         (flags & CSS_PSEUDO_CLASS_ENABLED_IN_CHROME)) ||
+        ((aEnabledState & EnabledState::eInUASheets) &&
+         (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[size_t(Type::Count)];
   static bool sPseudoClassEnabled[size_t(Type::Count)];
 };
 
 #endif /* nsCSSPseudoClasses_h___ */