Bumping manifests a=b2g-bump
[gecko.git] / layout / style / CSSVariableDeclarations.h
blob8e081ad70297c29cd2517bca9d9b8b6f4da5711e
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;
16 struct nsRuleData;
18 namespace mozilla {
20 class CSSVariableDeclarations
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.
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;
39 /**
40 * Represents the type of a variable value.
42 enum Type {
43 eTokenStream, // a stream of CSS tokens (the usual type for variables)
44 eInitial, // 'initial'
45 eInherit, // 'inherit'
46 eUnset // 'unset'
49 /**
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
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.
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'.
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);
73 /**
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);
82 /**
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);
91 /**
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
122 * specified values.
124 void AddVariablesToResolver(CSSVariableResolver* aResolver) const;
126 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
128 private:
130 * Adds all the variable declarations from aOther into this object.
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;
148 } // namespace mozilla
150 #endif