Bumping manifests a=b2g-bump
[gecko.git] / layout / style / CSSVariableValues.cpp
blobe6f1faf2617c44e0117a9a86769c15acbd051595
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 /* computed CSS Variable values */
8 #include "CSSVariableValues.h"
10 #include "CSSVariableResolver.h"
12 namespace mozilla {
14 CSSVariableValues::CSSVariableValues()
16 MOZ_COUNT_CTOR(CSSVariableValues);
19 CSSVariableValues::CSSVariableValues(const CSSVariableValues& aOther)
21 MOZ_COUNT_CTOR(CSSVariableValues);
22 CopyVariablesFrom(aOther);
25 #ifdef DEBUG
26 CSSVariableValues::~CSSVariableValues()
28 MOZ_COUNT_DTOR(CSSVariableValues);
30 #endif
32 CSSVariableValues&
33 CSSVariableValues::operator=(const CSSVariableValues& aOther)
35 if (this == &aOther) {
36 return *this;
39 mVariableIDs.Clear();
40 mVariables.Clear();
41 CopyVariablesFrom(aOther);
42 return *this;
45 bool
46 CSSVariableValues::operator==(const CSSVariableValues& aOther) const
48 if (mVariables.Length() != aOther.mVariables.Length()) {
49 return false;
52 for (size_t thisIndex = 0; thisIndex < mVariables.Length(); ++thisIndex) {
53 size_t otherIndex;
54 if (!aOther.mVariableIDs.Get(mVariables[thisIndex].mVariableName,
55 &otherIndex)) {
56 return false;
58 const nsString& otherValue = aOther.mVariables[otherIndex].mValue;
59 if (!mVariables[thisIndex].mValue.Equals(otherValue)) {
60 return false;
64 return true;
67 size_t
68 CSSVariableValues::Count() const
70 return mVariables.Length();
73 bool
74 CSSVariableValues::Get(const nsAString& aName, nsString& aValue) const
76 size_t id;
77 if (!mVariableIDs.Get(aName, &id)) {
78 return false;
80 aValue = mVariables[id].mValue;
81 return true;
84 bool
85 CSSVariableValues::Get(const nsAString& aName,
86 nsString& aValue,
87 nsCSSTokenSerializationType& aFirstToken,
88 nsCSSTokenSerializationType& aLastToken) const
90 size_t id;
91 if (!mVariableIDs.Get(aName, &id)) {
92 return false;
94 aValue = mVariables[id].mValue;
95 aFirstToken = mVariables[id].mFirstToken;
96 aLastToken = mVariables[id].mLastToken;
97 return true;
100 void
101 CSSVariableValues::GetVariableAt(size_t aIndex, nsAString& aName) const
103 aName = mVariables[aIndex].mVariableName;
106 void
107 CSSVariableValues::Put(const nsAString& aName,
108 nsString aValue,
109 nsCSSTokenSerializationType aFirstToken,
110 nsCSSTokenSerializationType aLastToken)
112 size_t id;
113 if (mVariableIDs.Get(aName, &id)) {
114 mVariables[id].mValue = aValue;
115 mVariables[id].mFirstToken = aFirstToken;
116 mVariables[id].mLastToken = aLastToken;
117 } else {
118 id = mVariables.Length();
119 mVariableIDs.Put(aName, id);
120 mVariables.AppendElement(Variable(aName, aValue, aFirstToken, aLastToken));
124 void
125 CSSVariableValues::CopyVariablesFrom(const CSSVariableValues& aOther)
127 for (size_t i = 0, n = aOther.mVariables.Length(); i < n; i++) {
128 Put(aOther.mVariables[i].mVariableName,
129 aOther.mVariables[i].mValue,
130 aOther.mVariables[i].mFirstToken,
131 aOther.mVariables[i].mLastToken);
135 void
136 CSSVariableValues::AddVariablesToResolver(CSSVariableResolver* aResolver) const
138 for (size_t i = 0, n = mVariables.Length(); i < n; i++) {
139 aResolver->Put(mVariables[i].mVariableName,
140 mVariables[i].mValue,
141 mVariables[i].mFirstToken,
142 mVariables[i].mLastToken,
143 true);
147 } // namespace mozilla