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