michael@0: /* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* computed CSS Variable values */ michael@0: michael@0: #ifndef mozilla_CSSVariableValues_h michael@0: #define mozilla_CSSVariableValues_h michael@0: michael@0: #include "nsCSSScanner.h" michael@0: #include "nsDataHashtable.h" michael@0: #include "nsTArray.h" michael@0: michael@0: namespace mozilla { michael@0: michael@0: class CSSVariableResolver; michael@0: michael@0: class CSSVariableValues michael@0: { michael@0: public: michael@0: CSSVariableValues(); michael@0: CSSVariableValues(const CSSVariableValues& aOther); michael@0: #ifdef DEBUG michael@0: ~CSSVariableValues(); michael@0: #endif michael@0: CSSVariableValues& operator=(const CSSVariableValues& aOther); michael@0: michael@0: bool operator==(const CSSVariableValues& aOther) const; michael@0: bool operator!=(const CSSVariableValues& aOther) const michael@0: { return !(*this == aOther); } michael@0: michael@0: /** michael@0: * Gets the value of a variable in this set of computed variables. michael@0: * michael@0: * @param aName The variable name (not including any "--" prefix that would michael@0: * be part of the custom property name). michael@0: * @param aValue Out parameter into which the value of the variable will michael@0: * be stored. michael@0: * @return Whether a variable with the given name was found. When false michael@0: * is returned, aValue will not be modified. michael@0: */ michael@0: bool Get(const nsAString& aName, nsString& aValue) const; michael@0: michael@0: /** michael@0: * Gets the value of a variable in this set of computed variables, along michael@0: * with information on the types of tokens that appear at the start and michael@0: * end of the token stream. michael@0: * michael@0: * @param aName The variable name (not including any "--" prefix that would michael@0: * be part of the custom property name). michael@0: * @param aValue Out parameter into which the value of the variable will michael@0: * be stored. michael@0: * @param aFirstToken The type of token at the start of the variable value. michael@0: * @param aLastToken The type of token at the en of the variable value. michael@0: * @return Whether a variable with the given name was found. When false michael@0: * is returned, aValue, aFirstToken and aLastToken will not be modified. michael@0: */ michael@0: bool Get(const nsAString& aName, michael@0: nsString& aValue, michael@0: nsCSSTokenSerializationType& aFirstToken, michael@0: nsCSSTokenSerializationType& aLastToken) const; michael@0: michael@0: /** michael@0: * Gets the name of the variable at the given index. michael@0: * michael@0: * Variables on this object are ordered, and that order is just determined michael@0: * based on the order that they are added to the object. A consistent michael@0: * ordering is required for CSSDeclaration objects in the DOM. michael@0: * CSSDeclarations expose property names as indexed properties, which need to michael@0: * be stable. michael@0: * michael@0: * @param aIndex The index of the variable to get. michael@0: * @param aName Out parameter into which the name of the variable will be michael@0: * stored. michael@0: */ michael@0: void GetVariableAt(size_t aIndex, nsAString& aName) const; michael@0: michael@0: /** michael@0: * Gets the number of variables stored on this object. michael@0: */ michael@0: size_t Count() const; michael@0: michael@0: /** michael@0: * Adds or modifies an existing entry in this set of variable values. michael@0: * michael@0: * @param aName The variable name (not including any "--" prefix that would michael@0: * be part of the custom property name) whose value is to be set. michael@0: * @param aValue The variable value. michael@0: * @param aFirstToken The type of token at the start of the variable value. michael@0: * @param aLastToken The type of token at the en of the variable value. michael@0: */ michael@0: void Put(const nsAString& aName, michael@0: nsString aValue, michael@0: nsCSSTokenSerializationType aFirstToken, michael@0: nsCSSTokenSerializationType aLastToken); michael@0: michael@0: /** michael@0: * Copies the variables from this object into aResolver, marking them as michael@0: * computed, inherited values. michael@0: */ michael@0: void AddVariablesToResolver(CSSVariableResolver* aResolver) const; michael@0: michael@0: private: michael@0: struct Variable michael@0: { michael@0: Variable() michael@0: : mFirstToken(eCSSTokenSerialization_Nothing) michael@0: , mLastToken(eCSSTokenSerialization_Nothing) michael@0: {} michael@0: michael@0: Variable(const nsAString& aVariableName, michael@0: nsString aValue, michael@0: nsCSSTokenSerializationType aFirstToken, michael@0: nsCSSTokenSerializationType aLastToken) michael@0: : mVariableName(aVariableName) michael@0: , mValue(aValue) michael@0: , mFirstToken(aFirstToken) michael@0: , mLastToken(aLastToken) michael@0: {} michael@0: michael@0: nsString mVariableName; michael@0: nsString mValue; michael@0: nsCSSTokenSerializationType mFirstToken; michael@0: nsCSSTokenSerializationType mLastToken; michael@0: }; michael@0: michael@0: /** michael@0: * Adds all the variables from aOther into this object. michael@0: */ michael@0: void CopyVariablesFrom(const CSSVariableValues& aOther); michael@0: michael@0: /** michael@0: * Map of variable names to IDs. Variable IDs are indexes into michael@0: * mVariables. michael@0: */ michael@0: nsDataHashtable mVariableIDs; michael@0: michael@0: /** michael@0: * Array of variables, indexed by variable ID. michael@0: */ michael@0: nsTArray mVariables; michael@0: }; michael@0: michael@0: } // namespace mozilla michael@0: michael@0: #endif