From 9907e9112a687eb5541522d63f0c8e9cecc86293 Mon Sep 17 00:00:00 2001 From: "L. David Baron" Date: Thu, 23 Oct 2014 12:57:27 -0400 Subject: [PATCH] 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 | 21 +++++++++++++++++++++ layout/style/nsCSSPseudoClasses.h | 9 +++++++++ layout/style/nsCSSPseudoElements.cpp | 9 ++++----- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/layout/style/nsCSSPseudoClasses.cpp b/layout/style/nsCSSPseudoClasses.cpp index ce8c43827382..72321369c495 100644 --- a/layout/style/nsCSSPseudoClasses.cpp +++ b/layout/style/nsCSSPseudoClasses.cpp @@ -25,6 +25,7 @@ using namespace mozilla; #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_), @@ -32,6 +33,16 @@ static const nsStaticAtom CSSPseudoClasses_info[] = { #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, @@ -99,3 +110,13 @@ nsCSSPseudoClasses::IsUserActionPseudoClass(Type aType) aType == ePseudoClass_active || aType == ePseudoClass_focus; } + +/* static */ uint32_t +nsCSSPseudoClasses::FlagsForPseudoClass(const Type aType) +{ + size_t index = static_cast(aType); + NS_ASSERTION(index < ArrayLength(CSSPseudoClasses_flags), + "argument must be a pseudo-class"); + return CSSPseudoClasses_flags[index]; +} + diff --git a/layout/style/nsCSSPseudoClasses.h b/layout/style/nsCSSPseudoClasses.h index 3e7b12b5701d..6cd7cc037ef6 100644 --- a/layout/style/nsCSSPseudoClasses.h +++ b/layout/style/nsCSSPseudoClasses.h @@ -37,6 +37,15 @@ public: // 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___ */ diff --git a/layout/style/nsCSSPseudoElements.cpp b/layout/style/nsCSSPseudoElements.cpp index 42e3d463d49a..fd140f75cd29 100644 --- a/layout/style/nsCSSPseudoElements.cpp +++ b/layout/style/nsCSSPseudoElements.cpp @@ -25,6 +25,7 @@ using namespace mozilla; #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_), @@ -32,11 +33,9 @@ static const nsStaticAtom CSSPseudoElements_info[] = { #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_,