Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / layout / style / nsDOMCSSValueList.cpp
blob24982fc6584af195a5205419e10f4353570fe40f
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 // QueryInterface implementation for nsDOMCSSValueList
59 NS_INTERFACE_MAP_BEGIN(nsDOMCSSValueList)
60 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSValueList)
61 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSValue)
62 NS_INTERFACE_MAP_ENTRY(nsISupports)
63 NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(CSSValueList)
64 NS_INTERFACE_MAP_END
66 PRBool
67 nsDOMCSSValueList::AppendCSSValue(nsIDOMCSSValue* aValue)
69 return mCSSValues.AppendObject(aValue);
72 // nsIDOMCSSValueList
74 NS_IMETHODIMP
75 nsDOMCSSValueList::GetLength(PRUint32* aLength)
77 *aLength = mCSSValues.Count();
79 return NS_OK;
82 NS_IMETHODIMP
83 nsDOMCSSValueList::Item(PRUint32 aIndex, nsIDOMCSSValue **aReturn)
85 NS_ENSURE_ARG_POINTER(aReturn);
87 NS_IF_ADDREF(*aReturn = GetItemAt(aIndex));
89 return NS_OK;
92 // nsIDOMCSSValue
94 NS_IMETHODIMP
95 nsDOMCSSValueList::GetCssText(nsAString& aCssText)
97 aCssText.Truncate();
99 PRUint32 count = mCSSValues.Count();
101 nsAutoString separator;
102 if (mCommaDelimited) {
103 separator.AssignLiteral(", ");
105 else {
106 separator.Assign(PRUnichar(' '));
109 nsCOMPtr<nsIDOMCSSValue> cssValue;
110 nsAutoString tmpStr;
111 for (PRUint32 i = 0; i < count; ++i) {
112 cssValue = mCSSValues[i];
113 NS_ASSERTION(cssValue, "Eek! Someone filled the value list with null CSSValues!");
114 if (cssValue) {
115 cssValue->GetCssText(tmpStr);
117 if (tmpStr.IsEmpty()) {
119 #ifdef DEBUG_caillon
120 NS_ERROR("Eek! An empty CSSValue! Bad!");
121 #endif
123 continue;
126 // If this isn't the first item in the list, then
127 // it's ok to append a separator.
128 if (!aCssText.IsEmpty()) {
129 aCssText.Append(separator);
131 aCssText.Append(tmpStr);
135 return NS_OK;
138 NS_IMETHODIMP
139 nsDOMCSSValueList::SetCssText(const nsAString& aCssText)
141 if (mReadonly) {
142 return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
145 NS_NOTYETIMPLEMENTED("Can't SetCssText yet: please write me!");
146 return NS_OK;
150 NS_IMETHODIMP
151 nsDOMCSSValueList::GetCssValueType(PRUint16* aValueType)
153 NS_ENSURE_ARG_POINTER(aValueType);
154 *aValueType = nsIDOMCSSValue::CSS_VALUE_LIST;
155 return NS_OK;