Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
1 /* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
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/. */
6 /* CSS Custom Property assignments for a Declaration at a given priority */
8 #ifndef mozilla_CSSVariableDeclarations_h
9 #define mozilla_CSSVariableDeclarations_h
11 #include "nsDataHashtable.h"
13 namespace mozilla {
14 class CSSVariableResolver;
15 }
16 class nsRuleData;
18 namespace mozilla {
20 class CSSVariableDeclarations
21 {
22 public:
23 CSSVariableDeclarations();
24 CSSVariableDeclarations(const CSSVariableDeclarations& aOther);
25 #ifdef DEBUG
26 ~CSSVariableDeclarations();
27 #endif
28 CSSVariableDeclarations& operator=(const CSSVariableDeclarations& aOther);
30 /**
31 * Returns whether this set of variable declarations includes a variable
32 * with a given name.
33 *
34 * @param aName The variable name (not including any "--" prefix that would
35 * be part of the custom property name).
36 */
37 bool Has(const nsAString& aName) const;
39 /**
40 * Represents the type of a variable value.
41 */
42 enum Type {
43 eTokenStream, // a stream of CSS tokens (the usual type for variables)
44 eInitial, // 'initial'
45 eInherit, // 'inherit'
46 eUnset // 'unset'
47 };
49 /**
50 * Gets the value of a variable in this set of variable declarations.
51 *
52 * @param aName The variable name (not including any "--" prefix that would
53 * be part of the custom property name).
54 * @param aType Out parameter into which the type of the variable value will
55 * be stored.
56 * @param aValue Out parameter into which the value of the variable will
57 * be stored. If the variable is 'initial', 'inherit' or 'unset', this will
58 * be the empty string.
59 * @return Whether a variable with the given name was found. When false
60 * is returned, aType and aValue will not be modified.
61 */
62 bool Get(const nsAString& aName, Type& aType, nsString& aValue) const;
64 /**
65 * Adds or modifies an existing entry in this set of variable declarations
66 * to have the value 'initial'.
67 *
68 * @param aName The variable name (not including any "--" prefix that would
69 * be part of the custom property name) whose value is to be set.
70 */
71 void PutInitial(const nsAString& aName);
73 /**
74 * Adds or modifies an existing entry in this set of variable declarations
75 * to have the value 'inherit'.
76 *
77 * @param aName The variable name (not including any "--" prefix that would
78 * be part of the custom property name) whose value is to be set.
79 */
80 void PutInherit(const nsAString& aName);
82 /**
83 * Adds or modifies an existing entry in this set of variable declarations
84 * to have the value 'unset'.
85 *
86 * @param aName The variable name (not including any "--" prefix that would
87 * be part of the custom property name) whose value is to be set.
88 */
89 void PutUnset(const nsAString& aName);
91 /**
92 * Adds or modifies an existing entry in this set of variable declarations
93 * to have a token stream value.
94 *
95 * @param aName The variable name (not including any "--" prefix that would
96 * be part of the custom property name) whose value is to be set.
97 * @param aTokenStream The CSS token stream.
98 */
99 void PutTokenStream(const nsAString& aName, const nsString& aTokenStream);
101 /**
102 * Removes an entry in this set of variable declarations.
103 *
104 * @param aName The variable name (not including any "--" prefix that would
105 * be part of the custom property name) whose entry is to be removed.
106 */
107 void Remove(const nsAString& aName);
109 /**
110 * Returns the number of entries in this set of variable declarations.
111 */
112 uint32_t Count() const { return mVariables.Count(); }
114 /**
115 * Copies each variable value from this object into aRuleData, unless that
116 * variable already exists on aRuleData.
117 */
118 void MapRuleInfoInto(nsRuleData* aRuleData);
120 /**
121 * Copies the variables from this object into aResolver, marking them as
122 * specified values.
123 */
124 void AddVariablesToResolver(CSSVariableResolver* aResolver) const;
126 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
128 private:
129 /**
130 * Adds all the variable declarations from aOther into this object.
131 */
132 void CopyVariablesFrom(const CSSVariableDeclarations& aOther);
133 static PLDHashOperator EnumerateVariableForCopy(const nsAString& aName,
134 nsString aValue,
135 void* aData);
136 static PLDHashOperator
137 EnumerateVariableForMapRuleInfoInto(const nsAString& aName,
138 nsString aValue,
139 void* aData);
140 static PLDHashOperator
141 EnumerateVariableForAddVariablesToResolver(const nsAString& aName,
142 nsString aValue,
143 void* aData);
145 nsDataHashtable<nsStringHashKey, nsString> mVariables;
146 };
148 } // namespace mozilla
150 #endif