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"
14 CSSVariableValues::CSSVariableValues()
16 MOZ_COUNT_CTOR(CSSVariableValues
);
19 CSSVariableValues::CSSVariableValues(const CSSVariableValues
& aOther
)
21 MOZ_COUNT_CTOR(CSSVariableValues
);
22 CopyVariablesFrom(aOther
);
26 CSSVariableValues::~CSSVariableValues()
28 MOZ_COUNT_DTOR(CSSVariableValues
);
33 CSSVariableValues::operator=(const CSSVariableValues
& aOther
)
35 if (this == &aOther
) {
41 CopyVariablesFrom(aOther
);
46 CSSVariableValues::operator==(const CSSVariableValues
& aOther
) const
48 if (mVariables
.Length() != aOther
.mVariables
.Length()) {
52 for (size_t thisIndex
= 0; thisIndex
< mVariables
.Length(); ++thisIndex
) {
54 if (!aOther
.mVariableIDs
.Get(mVariables
[thisIndex
].mVariableName
,
58 const nsString
& otherValue
= aOther
.mVariables
[otherIndex
].mValue
;
59 if (!mVariables
[thisIndex
].mValue
.Equals(otherValue
)) {
68 CSSVariableValues::Count() const
70 return mVariables
.Length();
74 CSSVariableValues::Get(const nsAString
& aName
, nsString
& aValue
) const
77 if (!mVariableIDs
.Get(aName
, &id
)) {
80 aValue
= mVariables
[id
].mValue
;
85 CSSVariableValues::Get(const nsAString
& aName
,
87 nsCSSTokenSerializationType
& aFirstToken
,
88 nsCSSTokenSerializationType
& aLastToken
) const
91 if (!mVariableIDs
.Get(aName
, &id
)) {
94 aValue
= mVariables
[id
].mValue
;
95 aFirstToken
= mVariables
[id
].mFirstToken
;
96 aLastToken
= mVariables
[id
].mLastToken
;
101 CSSVariableValues::GetVariableAt(size_t aIndex
, nsAString
& aName
) const
103 aName
= mVariables
[aIndex
].mVariableName
;
107 CSSVariableValues::Put(const nsAString
& aName
,
109 nsCSSTokenSerializationType aFirstToken
,
110 nsCSSTokenSerializationType aLastToken
)
113 if (mVariableIDs
.Get(aName
, &id
)) {
114 mVariables
[id
].mValue
= aValue
;
115 mVariables
[id
].mFirstToken
= aFirstToken
;
116 mVariables
[id
].mLastToken
= aLastToken
;
118 id
= mVariables
.Length();
119 mVariableIDs
.Put(aName
, id
);
120 mVariables
.AppendElement(Variable(aName
, aValue
, aFirstToken
, aLastToken
));
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
);
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
,
147 } // namespace mozilla