Bug 1839315: part 4) Link from `SheetLoadData::mWasAlternate` to spec. r=emilio DONTBUILD
[gecko.git] / layout / style / nsDOMCSSValueList.cpp
blob6cee83e509028b290e23cbfe50e7afec4cb7a7c9
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /* DOM object representing lists of values in DOM computed style */
9 #include "nsDOMCSSValueList.h"
11 #include <utility>
13 #include "mozilla/ErrorResult.h"
14 #include "nsString.h"
16 using namespace mozilla;
17 using namespace mozilla::dom;
19 nsDOMCSSValueList::nsDOMCSSValueList(bool aCommaDelimited)
20 : CSSValue(), mCommaDelimited(aCommaDelimited) {}
22 nsDOMCSSValueList::~nsDOMCSSValueList() = default;
24 void nsDOMCSSValueList::AppendCSSValue(already_AddRefed<CSSValue> aValue) {
25 RefPtr<CSSValue> val = aValue;
26 mCSSValues.AppendElement(std::move(val));
29 void nsDOMCSSValueList::GetCssText(nsAString& aCssText) {
30 aCssText.Truncate();
32 uint32_t count = mCSSValues.Length();
34 nsAutoString separator;
35 if (mCommaDelimited) {
36 separator.AssignLiteral(", ");
37 } else {
38 separator.Assign(char16_t(' '));
41 nsAutoString tmpStr;
42 for (uint32_t i = 0; i < count; ++i) {
43 CSSValue* cssValue = mCSSValues[i];
44 NS_ASSERTION(cssValue,
45 "Eek! Someone filled the value list with null CSSValues!");
46 if (cssValue) {
47 cssValue->GetCssText(tmpStr);
48 if (tmpStr.IsEmpty()) {
49 #ifdef DEBUG_caillon
50 NS_ERROR("Eek! An empty CSSValue! Bad!");
51 #endif
52 continue;
54 // If this isn't the first item in the list, then
55 // it's ok to append a separator.
56 if (!aCssText.IsEmpty()) {
57 aCssText.Append(separator);
59 aCssText.Append(tmpStr);