1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 /* atom list for CSS pseudo-classes */ 7 8 #ifndef nsCSSPseudoClasses_h___ 9 #define nsCSSPseudoClasses_h___ 10 11 #include "nsStringFwd.h" 12 13 // The following two flags along with the pref defines where this pseudo 14 // class can be used: 15 // * If none of the two flags is presented, the pref completely controls 16 // the availability of this pseudo class. And in that case, if it has 17 // no pref, this property is usable everywhere. 18 // * If any of the flags is set, this pseudo class is always enabled in 19 // the specific contexts regardless of the value of the pref. If there 20 // is no pref for this pseudo class at all in this case, it is an 21 // internal-only pseudo class, which cannot be used anywhere else. 22 #define CSS_PSEUDO_CLASS_ENABLED_MASK (3<<0) 23 #define CSS_PSEUDO_CLASS_ENABLED_IN_UA_SHEETS (1<<0) 24 #define CSS_PSEUDO_CLASS_ENABLED_IN_CHROME (1<<1) 25 #define CSS_PSEUDO_CLASS_ENABLED_IN_UA_SHEETS_AND_CHROME \ 26 (CSS_PSEUDO_CLASS_ENABLED_IN_UA_SHEETS | CSS_PSEUDO_CLASS_ENABLED_IN_CHROME) 27 28 class nsIAtom; 29 30 namespace mozilla { 31 32 // The total count of CSSPseudoClassType is less than 256, 33 // so use uint8_t as its underlying type. 34 typedef uint8_t CSSPseudoClassTypeBase; 35 enum class CSSPseudoClassType : CSSPseudoClassTypeBase 36 { 37 #define CSS_PSEUDO_CLASS(_name, _value, _flags, _pref) \ 38 _name, 39 #include "nsCSSPseudoClassList.h" 40 #undef CSS_PSEUDO_CLASS 41 Count, 42 NotPseudo, // This value MUST be second last! SelectorMatches depends on it. 43 MAX 44 }; 45 46 } // namespace mozilla 47 48 class nsCSSPseudoClasses 49 { 50 typedef mozilla::CSSPseudoClassType Type; 51 typedef mozilla::CSSEnabledState EnabledState; 52 53 public: 54 static void AddRefAtoms(); 55 56 static Type GetPseudoType(nsIAtom* aAtom, EnabledState aEnabledState); 57 static bool HasStringArg(Type aType); 58 static bool HasNthPairArg(Type aType); HasSelectorListArg(Type aType)59 static bool HasSelectorListArg(Type aType) { 60 return aType == Type::any; 61 } 62 static bool IsUserActionPseudoClass(Type aType); 63 64 // Should only be used on types other than Count and NotPseudoClass 65 static void PseudoTypeToString(Type aType, nsAString& aString); 66 IsEnabled(Type aType,EnabledState aEnabledState)67 static bool IsEnabled(Type aType, EnabledState aEnabledState) 68 { 69 auto index = static_cast<size_t>(aType); 70 MOZ_ASSERT(index < static_cast<size_t>(Type::Count)); 71 if (sPseudoClassEnabled[index] || 72 aEnabledState == EnabledState::eIgnoreEnabledState) { 73 return true; 74 } 75 auto flags = kPseudoClassFlags[index]; 76 if (((aEnabledState & EnabledState::eInChrome) && 77 (flags & CSS_PSEUDO_CLASS_ENABLED_IN_CHROME)) || 78 ((aEnabledState & EnabledState::eInUASheets) && 79 (flags & CSS_PSEUDO_CLASS_ENABLED_IN_UA_SHEETS))) { 80 return true; 81 } 82 return false; 83 } 84 85 private: 86 static const uint32_t kPseudoClassFlags[size_t(Type::Count)]; 87 static bool sPseudoClassEnabled[size_t(Type::Count)]; 88 }; 89 90 #endif /* nsCSSPseudoClasses_h___ */ 91