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"
|
|
|
|
#include "nsCOMPtr.h"
|
2012-07-27 07:03:27 -07:00
|
|
|
#include "nsError.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "prtypes.h"
|
|
|
|
#include "nsContentUtils.h"
|
2012-07-20 09:42:08 -07:00
|
|
|
#include "nsDOMClassInfoID.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
nsDOMCSSValueList::nsDOMCSSValueList(bool aCommaDelimited, bool aReadonly)
|
2007-03-22 10:30:00 -07:00
|
|
|
: mCommaDelimited(aCommaDelimited), mReadonly(aReadonly)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDOMCSSValueList::~nsDOMCSSValueList()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsDOMCSSValueList)
|
|
|
|
NS_IMPL_RELEASE(nsDOMCSSValueList)
|
|
|
|
|
2010-01-12 05:08:43 -08:00
|
|
|
DOMCI_DATA(CSSValueList, nsDOMCSSValueList)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// QueryInterface implementation for nsDOMCSSValueList
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsDOMCSSValueList)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSValueList)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSValue)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2010-03-17 08:09:05 -07:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSValueList)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2011-03-04 09:28:57 -08:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsDOMCSSValueList::AppendCSSValue(nsIDOMCSSValue* aValue)
|
|
|
|
{
|
2011-03-04 09:28:57 -08:00
|
|
|
mCSSValues.AppendElement(aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// nsIDOMCSSValueList
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsDOMCSSValueList::GetLength(uint32_t* aLength)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-03-04 09:28:57 -08:00
|
|
|
*aLength = mCSSValues.Length();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsDOMCSSValueList::Item(uint32_t aIndex, nsIDOMCSSValue **aReturn)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aReturn);
|
|
|
|
|
2008-10-22 07:31:14 -07:00
|
|
|
NS_IF_ADDREF(*aReturn = GetItemAt(aIndex));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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(' '));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMCSSValue> cssValue;
|
|
|
|
nsAutoString tmpStr;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
2007-03-22 10:30:00 -07:00
|
|
|
cssValue = mCSSValues[i];
|
|
|
|
NS_ASSERTION(cssValue, "Eek! Someone filled the value list with null CSSValues!");
|
|
|
|
if (cssValue) {
|
|
|
|
cssValue->GetCssText(tmpStr);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|