1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 /* DOM object representing lists of values in DOM computed style */
7 #include "nsDOMCSSValueList.h"
8 #include "mozilla/dom/CSSValueListBinding.h"
11 using namespace mozilla
;
13 nsDOMCSSValueList::nsDOMCSSValueList(bool aCommaDelimited
, bool aReadonly
)
14 : CSSValue(), mCommaDelimited(aCommaDelimited
), mReadonly(aReadonly
)
19 nsDOMCSSValueList::~nsDOMCSSValueList()
23 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMCSSValueList
)
24 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMCSSValueList
)
26 // QueryInterface implementation for nsDOMCSSValueList
27 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMCSSValueList
)
28 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
29 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSValue
)
30 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSValueList
)
31 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports
, CSSValue
)
34 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(nsDOMCSSValueList
, mCSSValues
)
37 nsDOMCSSValueList::WrapObject(JSContext
*cx
)
39 return dom::CSSValueListBinding::Wrap(cx
, this);
43 nsDOMCSSValueList::AppendCSSValue(CSSValue
* aValue
)
45 mCSSValues
.AppendElement(aValue
);
51 nsDOMCSSValueList::GetCssText(nsAString
& aCssText
)
55 uint32_t count
= mCSSValues
.Length();
57 nsAutoString separator
;
58 if (mCommaDelimited
) {
59 separator
.AssignLiteral(", ");
62 separator
.Assign(char16_t(' '));
66 for (uint32_t i
= 0; i
< count
; ++i
) {
67 CSSValue
*cssValue
= mCSSValues
[i
];
68 NS_ASSERTION(cssValue
, "Eek! Someone filled the value list with null CSSValues!");
71 cssValue
->GetCssText(tmpStr
, dummy
);
73 if (tmpStr
.IsEmpty()) {
76 NS_ERROR("Eek! An empty CSSValue! Bad!");
82 // If this isn't the first item in the list, then
83 // it's ok to append a separator.
84 if (!aCssText
.IsEmpty()) {
85 aCssText
.Append(separator
);
87 aCssText
.Append(tmpStr
);
95 nsDOMCSSValueList::GetCssText(nsString
& aText
, ErrorResult
& aRv
)
97 aRv
= GetCssText(aText
);
101 nsDOMCSSValueList::SetCssText(const nsAString
& aCssText
)
104 return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR
;
107 NS_NOTYETIMPLEMENTED("Can't SetCssText yet: please write me!");
112 nsDOMCSSValueList::SetCssText(const nsAString
& aText
, ErrorResult
& aRv
)
114 aRv
= SetCssText(aText
);
118 nsDOMCSSValueList::GetCssValueType(uint16_t* aValueType
)
120 NS_ENSURE_ARG_POINTER(aValueType
);
121 *aValueType
= nsIDOMCSSValue::CSS_VALUE_LIST
;
126 nsDOMCSSValueList::CssValueType() const
128 return nsIDOMCSSValue::CSS_VALUE_LIST
;