Bug 1269975 part 4 - Make nsCSSPseudoClasses::GetPseudoType() take CSSEnabledState rather than two bool params. r=heycam
☠☠ backed out by 9235ed9eac26 ☠ ☠
authorXidorn Quan <quanxunzhen@gmail.com>
Tue, 10 May 2016 13:36:25 +1000
changeset 296725 a55ecedea260452b5c099c668531e1d61a762fba
parent 296724 5321545b938ccdb01d30a1448cb12d73f940e8f3
child 296726 6f7ecae8e6637fb8208c28f522d5dd43f342cb9d
push id76456
push userxquan@mozilla.com
push dateTue, 10 May 2016 03:37:58 +0000
treeherdermozilla-inbound@4e949692600a [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[Type::Count];
   static bool sPseudoClassEnabled[Type::Count];
 };
 
 #endif /* nsCSSPseudoClasses_h___ */