CSSVariableDeclarations.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. /* CSS Custom Property assignments for a Declaration at a given priority */
  5. #ifndef mozilla_CSSVariableDeclarations_h
  6. #define mozilla_CSSVariableDeclarations_h
  7. #include "nsDataHashtable.h"
  8. namespace mozilla {
  9. class CSSVariableResolver;
  10. } // namespace mozilla
  11. struct nsRuleData;
  12. namespace mozilla {
  13. class CSSVariableDeclarations
  14. {
  15. public:
  16. CSSVariableDeclarations();
  17. CSSVariableDeclarations(const CSSVariableDeclarations& aOther);
  18. #ifdef DEBUG
  19. ~CSSVariableDeclarations();
  20. #endif
  21. CSSVariableDeclarations& operator=(const CSSVariableDeclarations& aOther);
  22. /**
  23. * Returns whether this set of variable declarations includes a variable
  24. * with a given name.
  25. *
  26. * @param aName The variable name (not including any "--" prefix that would
  27. * be part of the custom property name).
  28. */
  29. bool Has(const nsAString& aName) const;
  30. /**
  31. * Represents the type of a variable value.
  32. */
  33. enum Type {
  34. eTokenStream, // a stream of CSS tokens (the usual type for variables)
  35. eInitial, // 'initial'
  36. eInherit, // 'inherit'
  37. eUnset // 'unset'
  38. };
  39. /**
  40. * Gets the value of a variable in this set of variable declarations.
  41. *
  42. * @param aName The variable name (not including any "--" prefix that would
  43. * be part of the custom property name).
  44. * @param aType Out parameter into which the type of the variable value will
  45. * be stored.
  46. * @param aValue Out parameter into which the value of the variable will
  47. * be stored. If the variable is 'initial', 'inherit' or 'unset', this will
  48. * be the empty string.
  49. * @return Whether a variable with the given name was found. When false
  50. * is returned, aType and aValue will not be modified.
  51. */
  52. bool Get(const nsAString& aName, Type& aType, nsString& aValue) const;
  53. /**
  54. * Adds or modifies an existing entry in this set of variable declarations
  55. * to have the value 'initial'.
  56. *
  57. * @param aName The variable name (not including any "--" prefix that would
  58. * be part of the custom property name) whose value is to be set.
  59. */
  60. void PutInitial(const nsAString& aName);
  61. /**
  62. * Adds or modifies an existing entry in this set of variable declarations
  63. * to have the value 'inherit'.
  64. *
  65. * @param aName The variable name (not including any "--" prefix that would
  66. * be part of the custom property name) whose value is to be set.
  67. */
  68. void PutInherit(const nsAString& aName);
  69. /**
  70. * Adds or modifies an existing entry in this set of variable declarations
  71. * to have the value 'unset'.
  72. *
  73. * @param aName The variable name (not including any "--" prefix that would
  74. * be part of the custom property name) whose value is to be set.
  75. */
  76. void PutUnset(const nsAString& aName);
  77. /**
  78. * Adds or modifies an existing entry in this set of variable declarations
  79. * to have a token stream value.
  80. *
  81. * @param aName The variable name (not including any "--" prefix that would
  82. * be part of the custom property name) whose value is to be set.
  83. * @param aTokenStream The CSS token stream.
  84. */
  85. void PutTokenStream(const nsAString& aName, const nsString& aTokenStream);
  86. /**
  87. * Removes an entry in this set of variable declarations.
  88. *
  89. * @param aName The variable name (not including any "--" prefix that would
  90. * be part of the custom property name) whose entry is to be removed.
  91. */
  92. void Remove(const nsAString& aName);
  93. /**
  94. * Returns the number of entries in this set of variable declarations.
  95. */
  96. uint32_t Count() const { return mVariables.Count(); }
  97. /**
  98. * Copies each variable value from this object into aRuleData, unless that
  99. * variable already exists on aRuleData.
  100. */
  101. void MapRuleInfoInto(nsRuleData* aRuleData);
  102. /**
  103. * Copies the variables from this object into aResolver, marking them as
  104. * specified values.
  105. */
  106. void AddVariablesToResolver(CSSVariableResolver* aResolver) const;
  107. size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
  108. private:
  109. /**
  110. * Adds all the variable declarations from aOther into this object.
  111. */
  112. void CopyVariablesFrom(const CSSVariableDeclarations& aOther);
  113. nsDataHashtable<nsStringHashKey, nsString> mVariables;
  114. };
  115. } // namespace mozilla
  116. #endif