Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
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 | /* computed CSS Variable values */ |
michael@0 | 7 | |
michael@0 | 8 | #include "CSSVariableValues.h" |
michael@0 | 9 | |
michael@0 | 10 | #include "CSSVariableResolver.h" |
michael@0 | 11 | |
michael@0 | 12 | namespace mozilla { |
michael@0 | 13 | |
michael@0 | 14 | CSSVariableValues::CSSVariableValues() |
michael@0 | 15 | { |
michael@0 | 16 | MOZ_COUNT_CTOR(CSSVariableValues); |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | CSSVariableValues::CSSVariableValues(const CSSVariableValues& aOther) |
michael@0 | 20 | { |
michael@0 | 21 | MOZ_COUNT_CTOR(CSSVariableValues); |
michael@0 | 22 | CopyVariablesFrom(aOther); |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | #ifdef DEBUG |
michael@0 | 26 | CSSVariableValues::~CSSVariableValues() |
michael@0 | 27 | { |
michael@0 | 28 | MOZ_COUNT_DTOR(CSSVariableValues); |
michael@0 | 29 | } |
michael@0 | 30 | #endif |
michael@0 | 31 | |
michael@0 | 32 | CSSVariableValues& |
michael@0 | 33 | CSSVariableValues::operator=(const CSSVariableValues& aOther) |
michael@0 | 34 | { |
michael@0 | 35 | if (this == &aOther) { |
michael@0 | 36 | return *this; |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | mVariableIDs.Clear(); |
michael@0 | 40 | mVariables.Clear(); |
michael@0 | 41 | CopyVariablesFrom(aOther); |
michael@0 | 42 | return *this; |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | bool |
michael@0 | 46 | CSSVariableValues::operator==(const CSSVariableValues& aOther) const |
michael@0 | 47 | { |
michael@0 | 48 | if (mVariables.Length() != aOther.mVariables.Length()) { |
michael@0 | 49 | return false; |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | for (size_t thisIndex = 0; thisIndex < mVariables.Length(); ++thisIndex) { |
michael@0 | 53 | size_t otherIndex; |
michael@0 | 54 | if (!aOther.mVariableIDs.Get(mVariables[thisIndex].mVariableName, |
michael@0 | 55 | &otherIndex)) { |
michael@0 | 56 | return false; |
michael@0 | 57 | } |
michael@0 | 58 | const nsString& otherValue = aOther.mVariables[otherIndex].mValue; |
michael@0 | 59 | if (!mVariables[thisIndex].mValue.Equals(otherValue)) { |
michael@0 | 60 | return false; |
michael@0 | 61 | } |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | return true; |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | size_t |
michael@0 | 68 | CSSVariableValues::Count() const |
michael@0 | 69 | { |
michael@0 | 70 | return mVariables.Length(); |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | bool |
michael@0 | 74 | CSSVariableValues::Get(const nsAString& aName, nsString& aValue) const |
michael@0 | 75 | { |
michael@0 | 76 | size_t id; |
michael@0 | 77 | if (!mVariableIDs.Get(aName, &id)) { |
michael@0 | 78 | return false; |
michael@0 | 79 | } |
michael@0 | 80 | aValue = mVariables[id].mValue; |
michael@0 | 81 | return true; |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | bool |
michael@0 | 85 | CSSVariableValues::Get(const nsAString& aName, |
michael@0 | 86 | nsString& aValue, |
michael@0 | 87 | nsCSSTokenSerializationType& aFirstToken, |
michael@0 | 88 | nsCSSTokenSerializationType& aLastToken) const |
michael@0 | 89 | { |
michael@0 | 90 | size_t id; |
michael@0 | 91 | if (!mVariableIDs.Get(aName, &id)) { |
michael@0 | 92 | return false; |
michael@0 | 93 | } |
michael@0 | 94 | aValue = mVariables[id].mValue; |
michael@0 | 95 | aFirstToken = mVariables[id].mFirstToken; |
michael@0 | 96 | aLastToken = mVariables[id].mLastToken; |
michael@0 | 97 | return true; |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | void |
michael@0 | 101 | CSSVariableValues::GetVariableAt(size_t aIndex, nsAString& aName) const |
michael@0 | 102 | { |
michael@0 | 103 | aName = mVariables[aIndex].mVariableName; |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | void |
michael@0 | 107 | CSSVariableValues::Put(const nsAString& aName, |
michael@0 | 108 | nsString aValue, |
michael@0 | 109 | nsCSSTokenSerializationType aFirstToken, |
michael@0 | 110 | nsCSSTokenSerializationType aLastToken) |
michael@0 | 111 | { |
michael@0 | 112 | size_t id; |
michael@0 | 113 | if (mVariableIDs.Get(aName, &id)) { |
michael@0 | 114 | mVariables[id].mValue = aValue; |
michael@0 | 115 | mVariables[id].mFirstToken = aFirstToken; |
michael@0 | 116 | mVariables[id].mLastToken = aLastToken; |
michael@0 | 117 | } else { |
michael@0 | 118 | id = mVariables.Length(); |
michael@0 | 119 | mVariableIDs.Put(aName, id); |
michael@0 | 120 | mVariables.AppendElement(Variable(aName, aValue, aFirstToken, aLastToken)); |
michael@0 | 121 | } |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | void |
michael@0 | 125 | CSSVariableValues::CopyVariablesFrom(const CSSVariableValues& aOther) |
michael@0 | 126 | { |
michael@0 | 127 | for (size_t i = 0, n = aOther.mVariables.Length(); i < n; i++) { |
michael@0 | 128 | Put(aOther.mVariables[i].mVariableName, |
michael@0 | 129 | aOther.mVariables[i].mValue, |
michael@0 | 130 | aOther.mVariables[i].mFirstToken, |
michael@0 | 131 | aOther.mVariables[i].mLastToken); |
michael@0 | 132 | } |
michael@0 | 133 | } |
michael@0 | 134 | |
michael@0 | 135 | void |
michael@0 | 136 | CSSVariableValues::AddVariablesToResolver(CSSVariableResolver* aResolver) const |
michael@0 | 137 | { |
michael@0 | 138 | for (size_t i = 0, n = mVariables.Length(); i < n; i++) { |
michael@0 | 139 | aResolver->Put(mVariables[i].mVariableName, |
michael@0 | 140 | mVariables[i].mValue, |
michael@0 | 141 | mVariables[i].mFirstToken, |
michael@0 | 142 | mVariables[i].mLastToken, |
michael@0 | 143 | true); |
michael@0 | 144 | } |
michael@0 | 145 | } |
michael@0 | 146 | |
michael@0 | 147 | } // namespace mozilla |