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 /* computed CSS Variable values */
8 #ifndef mozilla_CSSVariableValues_h
9 #define mozilla_CSSVariableValues_h
11 #include "nsCSSScanner.h"
12 #include "nsDataHashtable.h"
17 class CSSVariableResolver
;
19 class CSSVariableValues
23 CSSVariableValues(const CSSVariableValues
& aOther
);
27 CSSVariableValues
& operator=(const CSSVariableValues
& aOther
);
29 bool operator==(const CSSVariableValues
& aOther
) const;
30 bool operator!=(const CSSVariableValues
& aOther
) const
31 { return !(*this == aOther
); }
34 * Gets the value of a variable in this set of computed variables.
36 * @param aName The variable name (not including any "--" prefix that would
37 * be part of the custom property name).
38 * @param aValue Out parameter into which the value of the variable will
40 * @return Whether a variable with the given name was found. When false
41 * is returned, aValue will not be modified.
43 bool Get(const nsAString
& aName
, nsString
& aValue
) const;
46 * Gets the value of a variable in this set of computed variables, along
47 * with information on the types of tokens that appear at the start and
48 * end of the token stream.
50 * @param aName The variable name (not including any "--" prefix that would
51 * be part of the custom property name).
52 * @param aValue Out parameter into which the value of the variable will
54 * @param aFirstToken The type of token at the start of the variable value.
55 * @param aLastToken The type of token at the en of the variable value.
56 * @return Whether a variable with the given name was found. When false
57 * is returned, aValue, aFirstToken and aLastToken will not be modified.
59 bool Get(const nsAString
& aName
,
61 nsCSSTokenSerializationType
& aFirstToken
,
62 nsCSSTokenSerializationType
& aLastToken
) const;
65 * Gets the name of the variable at the given index.
67 * Variables on this object are ordered, and that order is just determined
68 * based on the order that they are added to the object. A consistent
69 * ordering is required for CSSDeclaration objects in the DOM.
70 * CSSDeclarations expose property names as indexed properties, which need to
73 * @param aIndex The index of the variable to get.
74 * @param aName Out parameter into which the name of the variable will be
77 void GetVariableAt(size_t aIndex
, nsAString
& aName
) const;
80 * Gets the number of variables stored on this object.
85 * Adds or modifies an existing entry in this set of variable values.
87 * @param aName The variable name (not including any "--" prefix that would
88 * be part of the custom property name) whose value is to be set.
89 * @param aValue The variable value.
90 * @param aFirstToken The type of token at the start of the variable value.
91 * @param aLastToken The type of token at the en of the variable value.
93 void Put(const nsAString
& aName
,
95 nsCSSTokenSerializationType aFirstToken
,
96 nsCSSTokenSerializationType aLastToken
);
99 * Copies the variables from this object into aResolver, marking them as
100 * computed, inherited values.
102 void AddVariablesToResolver(CSSVariableResolver
* aResolver
) const;
108 : mFirstToken(eCSSTokenSerialization_Nothing
)
109 , mLastToken(eCSSTokenSerialization_Nothing
)
112 Variable(const nsAString
& aVariableName
,
114 nsCSSTokenSerializationType aFirstToken
,
115 nsCSSTokenSerializationType aLastToken
)
116 : mVariableName(aVariableName
)
118 , mFirstToken(aFirstToken
)
119 , mLastToken(aLastToken
)
122 nsString mVariableName
;
124 nsCSSTokenSerializationType mFirstToken
;
125 nsCSSTokenSerializationType mLastToken
;
129 * Adds all the variables from aOther into this object.
131 void CopyVariablesFrom(const CSSVariableValues
& aOther
);
134 * Map of variable names to IDs. Variable IDs are indexes into
137 nsDataHashtable
<nsStringHashKey
, size_t> mVariableIDs
;
140 * Array of variables, indexed by variable ID.
142 nsTArray
<Variable
> mVariables
;
145 } // namespace mozilla