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