1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/style/CSSVariableValues.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,147 @@ 1.4 +/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* computed CSS Variable values */ 1.10 + 1.11 +#ifndef mozilla_CSSVariableValues_h 1.12 +#define mozilla_CSSVariableValues_h 1.13 + 1.14 +#include "nsCSSScanner.h" 1.15 +#include "nsDataHashtable.h" 1.16 +#include "nsTArray.h" 1.17 + 1.18 +namespace mozilla { 1.19 + 1.20 +class CSSVariableResolver; 1.21 + 1.22 +class CSSVariableValues 1.23 +{ 1.24 +public: 1.25 + CSSVariableValues(); 1.26 + CSSVariableValues(const CSSVariableValues& aOther); 1.27 +#ifdef DEBUG 1.28 + ~CSSVariableValues(); 1.29 +#endif 1.30 + CSSVariableValues& operator=(const CSSVariableValues& aOther); 1.31 + 1.32 + bool operator==(const CSSVariableValues& aOther) const; 1.33 + bool operator!=(const CSSVariableValues& aOther) const 1.34 + { return !(*this == aOther); } 1.35 + 1.36 + /** 1.37 + * Gets the value of a variable in this set of computed variables. 1.38 + * 1.39 + * @param aName The variable name (not including any "--" prefix that would 1.40 + * be part of the custom property name). 1.41 + * @param aValue Out parameter into which the value of the variable will 1.42 + * be stored. 1.43 + * @return Whether a variable with the given name was found. When false 1.44 + * is returned, aValue will not be modified. 1.45 + */ 1.46 + bool Get(const nsAString& aName, nsString& aValue) const; 1.47 + 1.48 + /** 1.49 + * Gets the value of a variable in this set of computed variables, along 1.50 + * with information on the types of tokens that appear at the start and 1.51 + * end of the token stream. 1.52 + * 1.53 + * @param aName The variable name (not including any "--" prefix that would 1.54 + * be part of the custom property name). 1.55 + * @param aValue Out parameter into which the value of the variable will 1.56 + * be stored. 1.57 + * @param aFirstToken The type of token at the start of the variable value. 1.58 + * @param aLastToken The type of token at the en of the variable value. 1.59 + * @return Whether a variable with the given name was found. When false 1.60 + * is returned, aValue, aFirstToken and aLastToken will not be modified. 1.61 + */ 1.62 + bool Get(const nsAString& aName, 1.63 + nsString& aValue, 1.64 + nsCSSTokenSerializationType& aFirstToken, 1.65 + nsCSSTokenSerializationType& aLastToken) const; 1.66 + 1.67 + /** 1.68 + * Gets the name of the variable at the given index. 1.69 + * 1.70 + * Variables on this object are ordered, and that order is just determined 1.71 + * based on the order that they are added to the object. A consistent 1.72 + * ordering is required for CSSDeclaration objects in the DOM. 1.73 + * CSSDeclarations expose property names as indexed properties, which need to 1.74 + * be stable. 1.75 + * 1.76 + * @param aIndex The index of the variable to get. 1.77 + * @param aName Out parameter into which the name of the variable will be 1.78 + * stored. 1.79 + */ 1.80 + void GetVariableAt(size_t aIndex, nsAString& aName) const; 1.81 + 1.82 + /** 1.83 + * Gets the number of variables stored on this object. 1.84 + */ 1.85 + size_t Count() const; 1.86 + 1.87 + /** 1.88 + * Adds or modifies an existing entry in this set of variable values. 1.89 + * 1.90 + * @param aName The variable name (not including any "--" prefix that would 1.91 + * be part of the custom property name) whose value is to be set. 1.92 + * @param aValue The variable value. 1.93 + * @param aFirstToken The type of token at the start of the variable value. 1.94 + * @param aLastToken The type of token at the en of the variable value. 1.95 + */ 1.96 + void Put(const nsAString& aName, 1.97 + nsString aValue, 1.98 + nsCSSTokenSerializationType aFirstToken, 1.99 + nsCSSTokenSerializationType aLastToken); 1.100 + 1.101 + /** 1.102 + * Copies the variables from this object into aResolver, marking them as 1.103 + * computed, inherited values. 1.104 + */ 1.105 + void AddVariablesToResolver(CSSVariableResolver* aResolver) const; 1.106 + 1.107 +private: 1.108 + struct Variable 1.109 + { 1.110 + Variable() 1.111 + : mFirstToken(eCSSTokenSerialization_Nothing) 1.112 + , mLastToken(eCSSTokenSerialization_Nothing) 1.113 + {} 1.114 + 1.115 + Variable(const nsAString& aVariableName, 1.116 + nsString aValue, 1.117 + nsCSSTokenSerializationType aFirstToken, 1.118 + nsCSSTokenSerializationType aLastToken) 1.119 + : mVariableName(aVariableName) 1.120 + , mValue(aValue) 1.121 + , mFirstToken(aFirstToken) 1.122 + , mLastToken(aLastToken) 1.123 + {} 1.124 + 1.125 + nsString mVariableName; 1.126 + nsString mValue; 1.127 + nsCSSTokenSerializationType mFirstToken; 1.128 + nsCSSTokenSerializationType mLastToken; 1.129 + }; 1.130 + 1.131 + /** 1.132 + * Adds all the variables from aOther into this object. 1.133 + */ 1.134 + void CopyVariablesFrom(const CSSVariableValues& aOther); 1.135 + 1.136 + /** 1.137 + * Map of variable names to IDs. Variable IDs are indexes into 1.138 + * mVariables. 1.139 + */ 1.140 + nsDataHashtable<nsStringHashKey, size_t> mVariableIDs; 1.141 + 1.142 + /** 1.143 + * Array of variables, indexed by variable ID. 1.144 + */ 1.145 + nsTArray<Variable> mVariables; 1.146 +}; 1.147 + 1.148 +} // namespace mozilla 1.149 + 1.150 +#endif