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"
14 class CSSVariableResolver
;
20 class CSSVariableDeclarations
23 CSSVariableDeclarations();
24 CSSVariableDeclarations(const CSSVariableDeclarations
& aOther
);
26 ~CSSVariableDeclarations();
28 CSSVariableDeclarations
& operator=(const CSSVariableDeclarations
& aOther
);
31 * Returns whether this set of variable declarations includes a variable
34 * @param aName The variable name (not including any "--" prefix that would
35 * be part of the custom property name).
37 bool Has(const nsAString
& aName
) const;
40 * Represents the type of a variable value.
43 eTokenStream
, // a stream of CSS tokens (the usual type for variables)
44 eInitial
, // 'initial'
45 eInherit
, // 'inherit'
50 * Gets the value of a variable in this set of variable declarations.
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
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.
62 bool Get(const nsAString
& aName
, Type
& aType
, nsString
& aValue
) const;
65 * Adds or modifies an existing entry in this set of variable declarations
66 * to have the value 'initial'.
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.
71 void PutInitial(const nsAString
& aName
);
74 * Adds or modifies an existing entry in this set of variable declarations
75 * to have the value 'inherit'.
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.
80 void PutInherit(const nsAString
& aName
);
83 * Adds or modifies an existing entry in this set of variable declarations
84 * to have the value 'unset'.
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.
89 void PutUnset(const nsAString
& aName
);
92 * Adds or modifies an existing entry in this set of variable declarations
93 * to have a token stream value.
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.
99 void PutTokenStream(const nsAString
& aName
, const nsString
& aTokenStream
);
102 * Removes an entry in this set of variable declarations.
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.
107 void Remove(const nsAString
& aName
);
110 * Returns the number of entries in this set of variable declarations.
112 uint32_t Count() const { return mVariables
.Count(); }
115 * Copies each variable value from this object into aRuleData, unless that
116 * variable already exists on aRuleData.
118 void MapRuleInfoInto(nsRuleData
* aRuleData
);
121 * Copies the variables from this object into aResolver, marking them as
124 void AddVariablesToResolver(CSSVariableResolver
* aResolver
) const;
126 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf
) const;
130 * Adds all the variable declarations from aOther into this object.
132 void CopyVariablesFrom(const CSSVariableDeclarations
& aOther
);
133 static PLDHashOperator
EnumerateVariableForCopy(const nsAString
& aName
,
136 static PLDHashOperator
137 EnumerateVariableForMapRuleInfoInto(const nsAString
& aName
,
140 static PLDHashOperator
141 EnumerateVariableForAddVariablesToResolver(const nsAString
& aName
,
145 nsDataHashtable
<nsStringHashKey
, nsString
> mVariables
;
148 } // namespace mozilla