Bug 1826564 [wpt PR 39394] - Update mypy, a=testonly
[gecko.git] / layout / style / nsDOMCSSValueList.cpp
blobe0fc50dfefbe7607f9109d81ca37ef448bc7e8d1
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 ErrorResult dummy;
47 if (cssValue) {
48 cssValue->GetCssText(tmpStr, dummy);
50 if (tmpStr.IsEmpty()) {
51 #ifdef DEBUG_caillon
52 NS_ERROR("Eek! An empty CSSValue! Bad!");
53 #endif
55 continue;
58 // If this isn't the first item in the list, then
59 // it's ok to append a separator.
60 if (!aCssText.IsEmpty()) {
61 aCssText.Append(separator);
63 aCssText.Append(tmpStr);
68 void nsDOMCSSValueList::GetCssText(nsString& aCssText, ErrorResult& aRv) {
69 GetCssText(aCssText);