nsCSSPseudoClasses.h 3.2 KB

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