2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* DOM object representing lists of values in DOM computed style */
|
|
|
|
|
|
|
|
#include "nsDOMCSSValueList.h"
|
2012-10-01 09:49:41 -07:00
|
|
|
#include "mozilla/dom/CSSValueListBinding.h"
|
2013-03-17 00:55:08 -07:00
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsContentUtils.h"
|
2012-10-01 09:49:41 -07:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
nsDOMCSSValueList::nsDOMCSSValueList(bool aCommaDelimited, bool aReadonly)
|
2012-10-01 09:49:41 -07:00
|
|
|
: CSSValue(), mCommaDelimited(aCommaDelimited), mReadonly(aReadonly)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-10-01 09:49:41 -07:00
|
|
|
SetIsDOMBinding();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsDOMCSSValueList::~nsDOMCSSValueList()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-10-01 09:49:41 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMCSSValueList)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMCSSValueList)
|
2010-01-12 05:08:43 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// QueryInterface implementation for nsDOMCSSValueList
|
2012-10-01 09:49:41 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMCSSValueList)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSValue)
|
2013-01-14 09:29:27 -08:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSValueList)
|
2012-10-01 09:49:41 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, CSSValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2012-10-01 09:49:41 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(nsDOMCSSValueList, mCSSValues)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-10-01 09:49:41 -07:00
|
|
|
JSObject*
|
2013-04-25 09:29:54 -07:00
|
|
|
nsDOMCSSValueList::WrapObject(JSContext *cx, JS::Handle<JSObject*> scope)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-03-11 16:03:47 -07:00
|
|
|
return dom::CSSValueListBinding::Wrap(cx, scope, this);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-10-01 09:49:41 -07:00
|
|
|
void
|
|
|
|
nsDOMCSSValueList::AppendCSSValue(CSSValue* aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-10-01 09:49:41 -07:00
|
|
|
mCSSValues.AppendElement(aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// nsIDOMCSSValue
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMCSSValueList::GetCssText(nsAString& aCssText)
|
|
|
|
{
|
|
|
|
aCssText.Truncate();
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t count = mCSSValues.Length();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsAutoString separator;
|
|
|
|
if (mCommaDelimited) {
|
|
|
|
separator.AssignLiteral(", ");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
separator.Assign(PRUnichar(' '));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString tmpStr;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
2012-10-01 09:49:41 -07:00
|
|
|
CSSValue *cssValue = mCSSValues[i];
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(cssValue, "Eek! Someone filled the value list with null CSSValues!");
|
2012-10-01 09:49:41 -07:00
|
|
|
ErrorResult dummy;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (cssValue) {
|
2012-10-01 09:49:41 -07:00
|
|
|
cssValue->GetCssText(tmpStr, dummy);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (tmpStr.IsEmpty()) {
|
|
|
|
|
|
|
|
#ifdef DEBUG_caillon
|
|
|
|
NS_ERROR("Eek! An empty CSSValue! Bad!");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If this isn't the first item in the list, then
|
|
|
|
// it's ok to append a separator.
|
|
|
|
if (!aCssText.IsEmpty()) {
|
|
|
|
aCssText.Append(separator);
|
|
|
|
}
|
|
|
|
aCssText.Append(tmpStr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-01 09:49:41 -07:00
|
|
|
void
|
|
|
|
nsDOMCSSValueList::GetCssText(nsString& aText, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
aRv = GetCssText(aText);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMCSSValueList::SetCssText(const nsAString& aCssText)
|
|
|
|
{
|
|
|
|
if (mReadonly) {
|
|
|
|
return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_NOTYETIMPLEMENTED("Can't SetCssText yet: please write me!");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-01 09:49:41 -07:00
|
|
|
void
|
|
|
|
nsDOMCSSValueList::SetCssText(const nsAString& aText, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
aRv = SetCssText(aText);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsDOMCSSValueList::GetCssValueType(uint16_t* aValueType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aValueType);
|
|
|
|
*aValueType = nsIDOMCSSValue::CSS_VALUE_LIST;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-01 09:49:41 -07:00
|
|
|
uint16_t
|
|
|
|
nsDOMCSSValueList::CssValueType() const
|
|
|
|
{
|
|
|
|
return nsIDOMCSSValue::CSS_VALUE_LIST;
|
|
|
|
}
|