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/. */ 6 7 /* DOM object representing lists of values in DOM computed style */ 8 9 #include "nsDOMCSSValueList.h" 10 11 #include <utility> 12 13 #include "mozilla/ErrorResult.h" 14 #include "nsString.h" 15 16 using namespace mozilla; 17 using namespace mozilla::dom; 18 nsDOMCSSValueList(bool aCommaDelimited)19nsDOMCSSValueList::nsDOMCSSValueList(bool aCommaDelimited) 20 : CSSValue(), mCommaDelimited(aCommaDelimited) {} 21 22 nsDOMCSSValueList::~nsDOMCSSValueList() = default; 23 AppendCSSValue(already_AddRefed<CSSValue> aValue)24void nsDOMCSSValueList::AppendCSSValue(already_AddRefed<CSSValue> aValue) { 25 RefPtr<CSSValue> val = aValue; 26 mCSSValues.AppendElement(std::move(val)); 27 } 28 GetCssText(nsAString & aCssText)29void nsDOMCSSValueList::GetCssText(nsAString& aCssText) { 30 aCssText.Truncate(); 31 32 uint32_t count = mCSSValues.Length(); 33 34 nsAutoString separator; 35 if (mCommaDelimited) { 36 separator.AssignLiteral(", "); 37 } else { 38 separator.Assign(char16_t(' ')); 39 } 40 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); 49 50 if (tmpStr.IsEmpty()) { 51 #ifdef DEBUG_caillon 52 NS_ERROR("Eek! An empty CSSValue! Bad!"); 53 #endif 54 55 continue; 56 } 57 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); 62 } 63 aCssText.Append(tmpStr); 64 } 65 } 66 } 67 GetCssText(nsString & aCssText,ErrorResult & aRv)68void nsDOMCSSValueList::GetCssText(nsString& aCssText, ErrorResult& aRv) { 69 GetCssText(aCssText); 70 } 71