2012-05-21 15:12:37 +04: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/. */
|
2002-07-08 11:11:59 +04:00
|
|
|
|
2006-03-25 08:47:31 +03:00
|
|
|
/* DOM object representing lists of values in DOM computed style */
|
|
|
|
|
2002-07-08 11:11:59 +04:00
|
|
|
#include "nsDOMCSSValueList.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2012-10-01 20:49:41 +04:00
|
|
|
#include "mozilla/dom/CSSValueListBinding.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2002-07-08 11:11:59 +04:00
|
|
|
#include "nsContentUtils.h"
|
2012-10-01 20:49:41 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2002-07-08 11:11:59 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
nsDOMCSSValueList::nsDOMCSSValueList(bool aCommaDelimited, bool aReadonly)
|
2012-10-01 20:49:41 +04:00
|
|
|
: CSSValue(), mCommaDelimited(aCommaDelimited), mReadonly(aReadonly)
|
2002-07-08 11:11:59 +04:00
|
|
|
{
|
2012-10-01 20:49:41 +04:00
|
|
|
SetIsDOMBinding();
|
2002-07-08 11:11:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsDOMCSSValueList::~nsDOMCSSValueList()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-10-01 20:49:41 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMCSSValueList)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMCSSValueList)
|
2010-01-12 16:08:43 +03:00
|
|
|
|
2002-07-08 11:11:59 +04:00
|
|
|
// QueryInterface implementation for nsDOMCSSValueList
|
2012-10-01 20:49:41 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMCSSValueList)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2002-07-08 11:11:59 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSValue)
|
2013-01-14 21:29:27 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSValueList)
|
2012-10-01 20:49:41 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, CSSValue)
|
2002-07-08 11:11:59 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2012-10-01 20:49:41 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(nsDOMCSSValueList, mCSSValues)
|
2002-07-08 11:11:59 +04:00
|
|
|
|
2012-10-01 20:49:41 +04:00
|
|
|
JSObject*
|
|
|
|
nsDOMCSSValueList::WrapObject(JSContext *cx, JSObject *scope, bool *tried)
|
2002-07-08 11:11:59 +04:00
|
|
|
{
|
2012-10-01 20:49:41 +04:00
|
|
|
return dom::CSSValueListBinding::Wrap(cx, scope, this, tried);
|
2002-07-08 11:11:59 +04:00
|
|
|
}
|
|
|
|
|
2012-10-01 20:49:41 +04:00
|
|
|
void
|
|
|
|
nsDOMCSSValueList::AppendCSSValue(CSSValue* aValue)
|
2002-07-08 11:11:59 +04:00
|
|
|
{
|
2012-10-01 20:49:41 +04:00
|
|
|
mCSSValues.AppendElement(aValue);
|
2002-07-08 11:11:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// nsIDOMCSSValue
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMCSSValueList::GetCssText(nsAString& aCssText)
|
|
|
|
{
|
|
|
|
aCssText.Truncate();
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t count = mCSSValues.Length();
|
2002-07-08 11:11:59 +04:00
|
|
|
|
|
|
|
nsAutoString separator;
|
|
|
|
if (mCommaDelimited) {
|
2004-06-17 04:13:25 +04:00
|
|
|
separator.AssignLiteral(", ");
|
2002-07-08 11:11:59 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
separator.Assign(PRUnichar(' '));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString tmpStr;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
2012-10-01 20:49:41 +04:00
|
|
|
CSSValue *cssValue = mCSSValues[i];
|
2002-07-08 11:11:59 +04:00
|
|
|
NS_ASSERTION(cssValue, "Eek! Someone filled the value list with null CSSValues!");
|
2012-10-01 20:49:41 +04:00
|
|
|
ErrorResult dummy;
|
2002-07-08 11:11:59 +04:00
|
|
|
if (cssValue) {
|
2012-10-01 20:49:41 +04:00
|
|
|
cssValue->GetCssText(tmpStr, dummy);
|
2002-07-08 11:11:59 +04: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
|
2005-11-21 01:05:24 +03:00
|
|
|
// it's ok to append a separator.
|
2002-07-08 11:11:59 +04:00
|
|
|
if (!aCssText.IsEmpty()) {
|
|
|
|
aCssText.Append(separator);
|
|
|
|
}
|
|
|
|
aCssText.Append(tmpStr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-01 20:49:41 +04:00
|
|
|
void
|
|
|
|
nsDOMCSSValueList::GetCssText(nsString& aText, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
aRv = GetCssText(aText);
|
|
|
|
}
|
|
|
|
|
2002-07-08 11:11:59 +04: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 20:49:41 +04:00
|
|
|
void
|
|
|
|
nsDOMCSSValueList::SetCssText(const nsAString& aText, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
aRv = SetCssText(aText);
|
|
|
|
}
|
2002-07-08 11:11:59 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsDOMCSSValueList::GetCssValueType(uint16_t* aValueType)
|
2002-07-08 11:11:59 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aValueType);
|
|
|
|
*aValueType = nsIDOMCSSValue::CSS_VALUE_LIST;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-01 20:49:41 +04:00
|
|
|
uint16_t
|
|
|
|
nsDOMCSSValueList::CssValueType() const
|
|
|
|
{
|
|
|
|
return nsIDOMCSSValue::CSS_VALUE_LIST;
|
|
|
|
}
|