Merge mozilla-central and tracemonkey. (a=blockers)
[mozilla-central.git] / layout / style / nsDOMCSSValueList.cpp
blob2cc2961352acc87cc2d9af9619ba9a69b95fe03e
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
14 * The Original Code is mozilla.org code.
16 * The Initial Developer of the Original Code is
17 * Netscape Communications Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 2002
19 * the Initial Developer. All Rights Reserved.
21 * Contributor(s):
22 * Christopher A. Aillon <christopher@aillon.com> (original author)
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 /* DOM object representing lists of values in DOM computed style */
40 #include "nsDOMCSSValueList.h"
41 #include "nsCOMPtr.h"
42 #include "nsDOMError.h"
43 #include "prtypes.h"
44 #include "nsContentUtils.h"
46 nsDOMCSSValueList::nsDOMCSSValueList(PRBool aCommaDelimited, PRBool aReadonly)
47 : mCommaDelimited(aCommaDelimited), mReadonly(aReadonly)
51 nsDOMCSSValueList::~nsDOMCSSValueList()
55 NS_IMPL_ADDREF(nsDOMCSSValueList)
56 NS_IMPL_RELEASE(nsDOMCSSValueList)
58 DOMCI_DATA(CSSValueList, nsDOMCSSValueList)
60 // QueryInterface implementation for nsDOMCSSValueList
61 NS_INTERFACE_MAP_BEGIN(nsDOMCSSValueList)
62 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSValueList)
63 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSValue)
64 NS_INTERFACE_MAP_ENTRY(nsISupports)
65 NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSValueList)
66 NS_INTERFACE_MAP_END
68 PRBool
69 nsDOMCSSValueList::AppendCSSValue(nsIDOMCSSValue* aValue)
71 return mCSSValues.AppendObject(aValue);
74 // nsIDOMCSSValueList
76 NS_IMETHODIMP
77 nsDOMCSSValueList::GetLength(PRUint32* aLength)
79 *aLength = mCSSValues.Count();
81 return NS_OK;
84 NS_IMETHODIMP
85 nsDOMCSSValueList::Item(PRUint32 aIndex, nsIDOMCSSValue **aReturn)
87 NS_ENSURE_ARG_POINTER(aReturn);
89 NS_IF_ADDREF(*aReturn = GetItemAt(aIndex));
91 return NS_OK;
94 // nsIDOMCSSValue
96 NS_IMETHODIMP
97 nsDOMCSSValueList::GetCssText(nsAString& aCssText)
99 aCssText.Truncate();
101 PRUint32 count = mCSSValues.Count();
103 nsAutoString separator;
104 if (mCommaDelimited) {
105 separator.AssignLiteral(", ");
107 else {
108 separator.Assign(PRUnichar(' '));
111 nsCOMPtr<nsIDOMCSSValue> cssValue;
112 nsAutoString tmpStr;
113 for (PRUint32 i = 0; i < count; ++i) {
114 cssValue = mCSSValues[i];
115 NS_ASSERTION(cssValue, "Eek! Someone filled the value list with null CSSValues!");
116 if (cssValue) {
117 cssValue->GetCssText(tmpStr);
119 if (tmpStr.IsEmpty()) {
121 #ifdef DEBUG_caillon
122 NS_ERROR("Eek! An empty CSSValue! Bad!");
123 #endif
125 continue;
128 // If this isn't the first item in the list, then
129 // it's ok to append a separator.
130 if (!aCssText.IsEmpty()) {
131 aCssText.Append(separator);
133 aCssText.Append(tmpStr);
137 return NS_OK;
140 NS_IMETHODIMP
141 nsDOMCSSValueList::SetCssText(const nsAString& aCssText)
143 if (mReadonly) {
144 return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
147 NS_NOTYETIMPLEMENTED("Can't SetCssText yet: please write me!");
148 return NS_OK;
152 NS_IMETHODIMP
153 nsDOMCSSValueList::GetCssValueType(PRUint16* aValueType)
155 NS_ENSURE_ARG_POINTER(aValueType);
156 *aValueType = nsIDOMCSSValue::CSS_VALUE_LIST;
157 return NS_OK;