michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* DOM object representing lists of values in DOM computed style */ michael@0: michael@0: #include "nsDOMCSSValueList.h" michael@0: #include "mozilla/dom/CSSValueListBinding.h" michael@0: #include "nsAutoPtr.h" michael@0: michael@0: using namespace mozilla; michael@0: michael@0: nsDOMCSSValueList::nsDOMCSSValueList(bool aCommaDelimited, bool aReadonly) michael@0: : CSSValue(), mCommaDelimited(aCommaDelimited), mReadonly(aReadonly) michael@0: { michael@0: SetIsDOMBinding(); michael@0: } michael@0: michael@0: nsDOMCSSValueList::~nsDOMCSSValueList() michael@0: { michael@0: } michael@0: michael@0: NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMCSSValueList) michael@0: NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMCSSValueList) michael@0: michael@0: // QueryInterface implementation for nsDOMCSSValueList michael@0: NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMCSSValueList) michael@0: NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY michael@0: NS_INTERFACE_MAP_ENTRY(nsIDOMCSSValue) michael@0: NS_INTERFACE_MAP_ENTRY(nsIDOMCSSValueList) michael@0: NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, CSSValue) michael@0: NS_INTERFACE_MAP_END michael@0: michael@0: NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(nsDOMCSSValueList, mCSSValues) michael@0: michael@0: JSObject* michael@0: nsDOMCSSValueList::WrapObject(JSContext *cx) michael@0: { michael@0: return dom::CSSValueListBinding::Wrap(cx, this); michael@0: } michael@0: michael@0: void michael@0: nsDOMCSSValueList::AppendCSSValue(CSSValue* aValue) michael@0: { michael@0: mCSSValues.AppendElement(aValue); michael@0: } michael@0: michael@0: // nsIDOMCSSValue michael@0: michael@0: NS_IMETHODIMP michael@0: nsDOMCSSValueList::GetCssText(nsAString& aCssText) michael@0: { michael@0: aCssText.Truncate(); michael@0: michael@0: uint32_t count = mCSSValues.Length(); michael@0: michael@0: nsAutoString separator; michael@0: if (mCommaDelimited) { michael@0: separator.AssignLiteral(", "); michael@0: } michael@0: else { michael@0: separator.Assign(char16_t(' ')); michael@0: } michael@0: michael@0: nsAutoString tmpStr; michael@0: for (uint32_t i = 0; i < count; ++i) { michael@0: CSSValue *cssValue = mCSSValues[i]; michael@0: NS_ASSERTION(cssValue, "Eek! Someone filled the value list with null CSSValues!"); michael@0: ErrorResult dummy; michael@0: if (cssValue) { michael@0: cssValue->GetCssText(tmpStr, dummy); michael@0: michael@0: if (tmpStr.IsEmpty()) { michael@0: michael@0: #ifdef DEBUG_caillon michael@0: NS_ERROR("Eek! An empty CSSValue! Bad!"); michael@0: #endif michael@0: michael@0: continue; michael@0: } michael@0: michael@0: // If this isn't the first item in the list, then michael@0: // it's ok to append a separator. michael@0: if (!aCssText.IsEmpty()) { michael@0: aCssText.Append(separator); michael@0: } michael@0: aCssText.Append(tmpStr); michael@0: } michael@0: } michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: void michael@0: nsDOMCSSValueList::GetCssText(nsString& aText, ErrorResult& aRv) michael@0: { michael@0: aRv = GetCssText(aText); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsDOMCSSValueList::SetCssText(const nsAString& aCssText) michael@0: { michael@0: if (mReadonly) { michael@0: return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; michael@0: } michael@0: michael@0: NS_NOTYETIMPLEMENTED("Can't SetCssText yet: please write me!"); michael@0: return NS_OK; michael@0: } michael@0: michael@0: void michael@0: nsDOMCSSValueList::SetCssText(const nsAString& aText, ErrorResult& aRv) michael@0: { michael@0: aRv = SetCssText(aText); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsDOMCSSValueList::GetCssValueType(uint16_t* aValueType) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(aValueType); michael@0: *aValueType = nsIDOMCSSValue::CSS_VALUE_LIST; michael@0: return NS_OK; michael@0: } michael@0: michael@0: uint16_t michael@0: nsDOMCSSValueList::CssValueType() const michael@0: { michael@0: return nsIDOMCSSValue::CSS_VALUE_LIST; michael@0: }