layout/style/CSSVariableResolver.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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 /* object that resolves CSS variables using specified and inherited variable
michael@0 7 * values
michael@0 8 */
michael@0 9
michael@0 10 #ifndef mozilla_CSSVariableResolver_h
michael@0 11 #define mozilla_CSSVariableResolver_h
michael@0 12
michael@0 13 #include "mozilla/DebugOnly.h"
michael@0 14 #include "nsCSSParser.h"
michael@0 15 #include "nsCSSScanner.h"
michael@0 16 #include "nsDataHashtable.h"
michael@0 17 #include "nsTArray.h"
michael@0 18
michael@0 19 namespace mozilla {
michael@0 20
michael@0 21 class CSSVariableDeclarations;
michael@0 22 class CSSVariableValues;
michael@0 23 class EnumerateVariableReferencesData;
michael@0 24
michael@0 25 class CSSVariableResolver
michael@0 26 {
michael@0 27 friend class CSSVariableDeclarations;
michael@0 28 friend class CSSVariableValues;
michael@0 29 friend class EnumerateVariableReferencesData;
michael@0 30 public:
michael@0 31 /**
michael@0 32 * Creates a new CSSVariableResolver that will output a set of resolved,
michael@0 33 * computed variables into aOutput.
michael@0 34 */
michael@0 35 CSSVariableResolver(CSSVariableValues* aOutput)
michael@0 36 : mOutput(aOutput)
michael@0 37 , mResolved(false)
michael@0 38 {
michael@0 39 MOZ_ASSERT(aOutput);
michael@0 40 }
michael@0 41
michael@0 42 /**
michael@0 43 * Resolves the set of inherited variables from aInherited and the
michael@0 44 * set of specified variables from aSpecified. The resoled variables
michael@0 45 * are written in to mOutput.
michael@0 46 */
michael@0 47 void Resolve(const CSSVariableValues* aInherited,
michael@0 48 const CSSVariableDeclarations* aSpecified);
michael@0 49
michael@0 50 private:
michael@0 51 struct Variable
michael@0 52 {
michael@0 53 Variable(const nsAString& aVariableName,
michael@0 54 nsString aValue,
michael@0 55 nsCSSTokenSerializationType aFirstToken,
michael@0 56 nsCSSTokenSerializationType aLastToken,
michael@0 57 bool aWasInherited)
michael@0 58 : mVariableName(aVariableName)
michael@0 59 , mValue(aValue)
michael@0 60 , mFirstToken(aFirstToken)
michael@0 61 , mLastToken(aLastToken)
michael@0 62 , mWasInherited(aWasInherited)
michael@0 63 , mResolved(false)
michael@0 64 , mReferencesNonExistentVariable(false)
michael@0 65 , mInStack(false)
michael@0 66 , mIndex(0)
michael@0 67 , mLowLink(0) { }
michael@0 68
michael@0 69 nsString mVariableName;
michael@0 70 nsString mValue;
michael@0 71 nsCSSTokenSerializationType mFirstToken;
michael@0 72 nsCSSTokenSerializationType mLastToken;
michael@0 73
michael@0 74 // Whether this variable came from the set of inherited variables.
michael@0 75 bool mWasInherited;
michael@0 76
michael@0 77 // Whether this variable has been resolved yet.
michael@0 78 bool mResolved;
michael@0 79
michael@0 80 // Whether this variables includes any references to non-existent variables.
michael@0 81 bool mReferencesNonExistentVariable;
michael@0 82
michael@0 83 // Bookkeeping for the cycle remover algorithm.
michael@0 84 bool mInStack;
michael@0 85 size_t mIndex;
michael@0 86 size_t mLowLink;
michael@0 87 };
michael@0 88
michael@0 89 /**
michael@0 90 * Adds or modifies an existing entry in the set of variables to be resolved.
michael@0 91 * This is intended to be called by the AddVariablesToResolver functions on
michael@0 92 * the CSSVariableDeclarations and CSSVariableValues objects passed in to
michael@0 93 * Resolve.
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 aValue The variable value.
michael@0 98 * @param aFirstToken The type of token at the start of the variable value.
michael@0 99 * @param aLastToken The type of token at the en of the variable value.
michael@0 100 * @param aWasInherited Whether this variable came from the set of inherited
michael@0 101 * variables.
michael@0 102 */
michael@0 103 void Put(const nsAString& aVariableName,
michael@0 104 nsString aValue,
michael@0 105 nsCSSTokenSerializationType aFirstToken,
michael@0 106 nsCSSTokenSerializationType aLastToken,
michael@0 107 bool aWasInherited);
michael@0 108
michael@0 109 // Helper functions for Resolve.
michael@0 110 void RemoveCycles(size_t aID);
michael@0 111 void ResolveVariable(size_t aID);
michael@0 112
michael@0 113 // A mapping of variable names to an ID that indexes into mVariables
michael@0 114 // and mReferences.
michael@0 115 nsDataHashtable<nsStringHashKey, size_t> mVariableIDs;
michael@0 116
michael@0 117 // The set of variables.
michael@0 118 nsTArray<Variable> mVariables;
michael@0 119
michael@0 120 // The list of variables that each variable references.
michael@0 121 nsTArray<nsTArray<size_t> > mReferences;
michael@0 122
michael@0 123 // The next index to assign to a variable found during the cycle removing
michael@0 124 // algorithm's traversal of the variable reference graph.
michael@0 125 size_t mNextIndex;
michael@0 126
michael@0 127 // Stack of variable IDs that we push to as we traverse the variable reference
michael@0 128 // graph while looking for cycles. Variable::mInStack reflects whether a
michael@0 129 // given variable has its ID in mStack.
michael@0 130 nsTArray<size_t> mStack;
michael@0 131
michael@0 132 // CSS parser to use for parsing property values with variable references.
michael@0 133 nsCSSParser mParser;
michael@0 134
michael@0 135 // The object to output the resolved variables into.
michael@0 136 CSSVariableValues* mOutput;
michael@0 137
michael@0 138 // Whether Resolve has been called.
michael@0 139 DebugOnly<bool> mResolved;
michael@0 140 };
michael@0 141
michael@0 142 }
michael@0 143
michael@0 144 #endif

mercurial