Line data Source code
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/. */
5 :
6 : /* computed CSS Variable values */
7 :
8 : #ifndef mozilla_CSSVariableValues_h
9 : #define mozilla_CSSVariableValues_h
10 :
11 : #include "nsCSSScanner.h"
12 : #include "nsDataHashtable.h"
13 : #include "nsTArray.h"
14 :
15 : namespace mozilla {
16 :
17 : class CSSVariableResolver;
18 :
19 : class CSSVariableValues
20 : {
21 : public:
22 : CSSVariableValues();
23 : CSSVariableValues(const CSSVariableValues& aOther);
24 : #ifdef DEBUG
25 : ~CSSVariableValues();
26 : #endif
27 : CSSVariableValues& operator=(const CSSVariableValues& aOther);
28 :
29 : bool operator==(const CSSVariableValues& aOther) const;
30 : bool operator!=(const CSSVariableValues& aOther) const
31 : { return !(*this == aOther); }
32 :
33 : /**
34 : * Gets the value of a variable in this set of computed variables.
35 : *
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
39 : * be stored.
40 : * @return Whether a variable with the given name was found. When false
41 : * is returned, aValue will not be modified.
42 : */
43 : bool Get(const nsAString& aName, nsString& aValue) const;
44 :
45 : /**
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.
49 : *
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
53 : * be stored.
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.
58 : */
59 : bool Get(const nsAString& aName,
60 : nsString& aValue,
61 : nsCSSTokenSerializationType& aFirstToken,
62 : nsCSSTokenSerializationType& aLastToken) const;
63 :
64 : /**
65 : * Gets the name of the variable at the given index.
66 : *
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
71 : * be stable.
72 : *
73 : * @param aIndex The index of the variable to get.
74 : * @param aName Out parameter into which the name of the variable will be
75 : * stored.
76 : */
77 : void GetVariableAt(size_t aIndex, nsAString& aName) const;
78 :
79 : /**
80 : * Gets the number of variables stored on this object.
81 : */
82 : size_t Count() const;
83 :
84 : /**
85 : * Adds or modifies an existing entry in this set of variable values.
86 : *
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.
92 : */
93 : void Put(const nsAString& aName,
94 : nsString aValue,
95 : nsCSSTokenSerializationType aFirstToken,
96 : nsCSSTokenSerializationType aLastToken);
97 :
98 : /**
99 : * Copies the variables from this object into aResolver, marking them as
100 : * computed, inherited values.
101 : */
102 : void AddVariablesToResolver(CSSVariableResolver* aResolver) const;
103 :
104 : private:
105 1340 : struct Variable
106 : {
107 : Variable()
108 : : mFirstToken(eCSSTokenSerialization_Nothing)
109 : , mLastToken(eCSSTokenSerialization_Nothing)
110 : {}
111 :
112 487 : Variable(const nsAString& aVariableName,
113 : nsString aValue,
114 : nsCSSTokenSerializationType aFirstToken,
115 : nsCSSTokenSerializationType aLastToken)
116 487 : : mVariableName(aVariableName)
117 : , mValue(aValue)
118 : , mFirstToken(aFirstToken)
119 487 : , mLastToken(aLastToken)
120 487 : {}
121 :
122 : nsString mVariableName;
123 : nsString mValue;
124 : nsCSSTokenSerializationType mFirstToken;
125 : nsCSSTokenSerializationType mLastToken;
126 : };
127 :
128 : /**
129 : * Adds all the variables from aOther into this object.
130 : */
131 : void CopyVariablesFrom(const CSSVariableValues& aOther);
132 :
133 : /**
134 : * Map of variable names to IDs. Variable IDs are indexes into
135 : * mVariables.
136 : */
137 : nsDataHashtable<nsStringHashKey, size_t> mVariableIDs;
138 :
139 : /**
140 : * Array of variables, indexed by variable ID.
141 : */
142 : nsTArray<Variable> mVariables;
143 : };
144 :
145 : } // namespace mozilla
146 :
147 : #endif
|