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: /* CSS Custom Property assignments for a Declaration at a given priority */ michael@0: michael@0: #ifndef mozilla_CSSVariableDeclarations_h michael@0: #define mozilla_CSSVariableDeclarations_h michael@0: michael@0: #include "nsDataHashtable.h" michael@0: michael@0: namespace mozilla { michael@0: class CSSVariableResolver; michael@0: } michael@0: class nsRuleData; michael@0: michael@0: namespace mozilla { michael@0: michael@0: class CSSVariableDeclarations michael@0: { michael@0: public: michael@0: CSSVariableDeclarations(); michael@0: CSSVariableDeclarations(const CSSVariableDeclarations& aOther); michael@0: #ifdef DEBUG michael@0: ~CSSVariableDeclarations(); michael@0: #endif michael@0: CSSVariableDeclarations& operator=(const CSSVariableDeclarations& aOther); michael@0: michael@0: /** michael@0: * Returns whether this set of variable declarations includes a variable michael@0: * with a given name. 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: */ michael@0: bool Has(const nsAString& aName) const; michael@0: michael@0: /** michael@0: * Represents the type of a variable value. michael@0: */ michael@0: enum Type { michael@0: eTokenStream, // a stream of CSS tokens (the usual type for variables) michael@0: eInitial, // 'initial' michael@0: eInherit, // 'inherit' michael@0: eUnset // 'unset' michael@0: }; michael@0: michael@0: /** michael@0: * Gets the value of a variable in this set of variable declarations. 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 aType Out parameter into which the type of the variable value will michael@0: * be stored. michael@0: * @param aValue Out parameter into which the value of the variable will michael@0: * be stored. If the variable is 'initial', 'inherit' or 'unset', this will michael@0: * be the empty string. michael@0: * @return Whether a variable with the given name was found. When false michael@0: * is returned, aType and aValue will not be modified. michael@0: */ michael@0: bool Get(const nsAString& aName, Type& aType, nsString& aValue) const; michael@0: michael@0: /** michael@0: * Adds or modifies an existing entry in this set of variable declarations michael@0: * to have the value 'initial'. 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: */ michael@0: void PutInitial(const nsAString& aName); michael@0: michael@0: /** michael@0: * Adds or modifies an existing entry in this set of variable declarations michael@0: * to have the value 'inherit'. 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: */ michael@0: void PutInherit(const nsAString& aName); michael@0: michael@0: /** michael@0: * Adds or modifies an existing entry in this set of variable declarations michael@0: * to have the value 'unset'. 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: */ michael@0: void PutUnset(const nsAString& aName); michael@0: michael@0: /** michael@0: * Adds or modifies an existing entry in this set of variable declarations michael@0: * to have a token stream value. 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 aTokenStream The CSS token stream. michael@0: */ michael@0: void PutTokenStream(const nsAString& aName, const nsString& aTokenStream); michael@0: michael@0: /** michael@0: * Removes an entry in this set of variable declarations. 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 entry is to be removed. michael@0: */ michael@0: void Remove(const nsAString& aName); michael@0: michael@0: /** michael@0: * Returns the number of entries in this set of variable declarations. michael@0: */ michael@0: uint32_t Count() const { return mVariables.Count(); } michael@0: michael@0: /** michael@0: * Copies each variable value from this object into aRuleData, unless that michael@0: * variable already exists on aRuleData. michael@0: */ michael@0: void MapRuleInfoInto(nsRuleData* aRuleData); michael@0: michael@0: /** michael@0: * Copies the variables from this object into aResolver, marking them as michael@0: * specified values. michael@0: */ michael@0: void AddVariablesToResolver(CSSVariableResolver* aResolver) const; michael@0: michael@0: size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; michael@0: michael@0: private: michael@0: /** michael@0: * Adds all the variable declarations from aOther into this object. michael@0: */ michael@0: void CopyVariablesFrom(const CSSVariableDeclarations& aOther); michael@0: static PLDHashOperator EnumerateVariableForCopy(const nsAString& aName, michael@0: nsString aValue, michael@0: void* aData); michael@0: static PLDHashOperator michael@0: EnumerateVariableForMapRuleInfoInto(const nsAString& aName, michael@0: nsString aValue, michael@0: void* aData); michael@0: static PLDHashOperator michael@0: EnumerateVariableForAddVariablesToResolver(const nsAString& aName, michael@0: nsString aValue, michael@0: void* aData); michael@0: michael@0: nsDataHashtable mVariables; michael@0: }; michael@0: michael@0: } // namespace mozilla michael@0: michael@0: #endif