Bug 1082899 patch 2 - Add flags storage and accessors for nsCSSPseudoClasses. r=birtles
authorL. David Baron <dbaron@dbaron.org>
Thu, 23 Oct 2014 12:57:27 -0400
changeset 211910 c66f58d9a4013772821357e91ebe1ccefb68a06a
parent 211909 25a3e04caeed666d801a519c75962d0c8740409d
child 211911 6925c2f5d70156de2e7ed5b47c64b05a4590bdb2
push id50852
push userdbaron@mozilla.com
push dateThu, 23 Oct 2014 16:58:05 +0000
treeherdermozilla-inbound@1ac58452ef7d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbirtles
bugs1082899
milestone36.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 1082899 patch 2 - Add flags storage and accessors for nsCSSPseudoClasses. r=birtles The code for this is basically copied from nsCSSPseudoElements.
layout/style/nsCSSPseudoClasses.cpp
layout/style/nsCSSPseudoClasses.h
layout/style/nsCSSPseudoElements.cpp
--- a/layout/style/nsCSSPseudoClasses.cpp
+++ b/layout/style/nsCSSPseudoClasses.cpp
@@ -20,23 +20,34 @@ using namespace mozilla;
 #include "nsCSSPseudoClassList.h"
 #undef CSS_PSEUDO_CLASS
 
 #define CSS_PSEUDO_CLASS(name_, value_, flags_, pref_) \
   NS_STATIC_ATOM_BUFFER(name_##_pseudo_class_buffer, value_)
 #include "nsCSSPseudoClassList.h"
 #undef CSS_PSEUDO_CLASS
 
+// Array of nsStaticAtom for each of the pseudo-classes.
 static const nsStaticAtom CSSPseudoClasses_info[] = {
 #define CSS_PSEUDO_CLASS(name_, value_, flags_, pref_) \
   NS_STATIC_ATOM(name_##_pseudo_class_buffer, &sPseudoClass_##name_),
 #include "nsCSSPseudoClassList.h"
 #undef CSS_PSEUDO_CLASS
 };
 
+// Flags data for each of the pseudo-classes, which must be separate
+// from the previous array since there's no place for it in
+// nsStaticAtom.
+static const uint32_t CSSPseudoClasses_flags[] = {
+#define CSS_PSEUDO_CLASS(name_, value_, flags_, pref_) \
+  flags_,
+#include "nsCSSPseudoClassList.h"
+#undef CSS_PSEUDO_CLASS
+};
+
 static bool sPseudoClassEnabled[] = {
 #define CSS_PSEUDO_CLASS(name_, value_, flags_, pref_) \
   true,
 #include "nsCSSPseudoClassList.h"
 #undef CSS_PSEUDO_CLASS
 };  
 
 void nsCSSPseudoClasses::AddRefAtoms()
@@ -94,8 +105,18 @@ nsCSSPseudoClasses::GetPseudoType(nsIAto
 /* static */ bool
 nsCSSPseudoClasses::IsUserActionPseudoClass(Type aType)
 {
   // See http://dev.w3.org/csswg/selectors4/#useraction-pseudos
   return aType == ePseudoClass_hover ||
          aType == ePseudoClass_active ||
          aType == ePseudoClass_focus;
 }
+
+/* static */ uint32_t
+nsCSSPseudoClasses::FlagsForPseudoClass(const Type aType)
+{
+  size_t index = static_cast<size_t>(aType);
+  NS_ASSERTION(index < ArrayLength(CSSPseudoClasses_flags),
+               "argument must be a pseudo-class");
+  return CSSPseudoClasses_flags[index];
+}
+
--- a/layout/style/nsCSSPseudoClasses.h
+++ b/layout/style/nsCSSPseudoClasses.h
@@ -32,11 +32,20 @@ public:
   static bool HasNthPairArg(Type aType);
   static bool HasSelectorListArg(Type aType) {
     return aType == ePseudoClass_any;
   }
   static bool IsUserActionPseudoClass(Type aType);
 
   // Should only be used on types other than Count and NotPseudoClass
   static void PseudoTypeToString(Type aType, nsAString& aString);
+
+private:
+  static uint32_t FlagsForPseudoClass(const Type aType);
+
+  // Does the given pseudo-class have all of the flags given?
+  static bool PseudoClassHasFlags(const Type aType, uint32_t aFlags)
+  {
+    return (FlagsForPseudoClass(aType) & aFlags) == aFlags;
+  }
 };
 
 #endif /* nsCSSPseudoClasses_h___ */
--- a/layout/style/nsCSSPseudoElements.cpp
+++ b/layout/style/nsCSSPseudoElements.cpp
@@ -20,28 +20,27 @@ using namespace mozilla;
 #include "nsCSSPseudoElementList.h"
 #undef CSS_PSEUDO_ELEMENT
 
 #define CSS_PSEUDO_ELEMENT(name_, value_, flags_) \
   NS_STATIC_ATOM_BUFFER(name_##_pseudo_element_buffer, value_)
 #include "nsCSSPseudoElementList.h"
 #undef CSS_PSEUDO_ELEMENT
 
+// Array of nsStaticAtom for each of the pseudo-elements.
 static const nsStaticAtom CSSPseudoElements_info[] = {
 #define CSS_PSEUDO_ELEMENT(name_, value_, flags_) \
   NS_STATIC_ATOM(name_##_pseudo_element_buffer, (nsIAtom**)&nsCSSPseudoElements::name_),
 #include "nsCSSPseudoElementList.h"
 #undef CSS_PSEUDO_ELEMENT
 };
 
-// Separate from the array above so that we can have an array of
-// nsStaticAtom (to pass to NS_RegisterStaticAtoms and
-// nsAtomListUtils::IsMember), but with corresponding indices (so the
-// i-th element of this array is the flags for the i-th pseudo-element
-// in the previous array).
+// 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 CSSPseudoElements_flags[] = {
 #define CSS_PSEUDO_ELEMENT(name_, value_, flags_) \
   flags_,
 #include "nsCSSPseudoElementList.h"
 #undef CSS_PSEUDO_ELEMENT
 };
 
 void nsCSSPseudoElements::AddRefAtoms()