Back to index

lightning-sunbird  0.9+nobinonly
nsDOMCSSValueList.cpp
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is mozilla.org code.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 2002
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Christopher A. Aillon <christopher@aillon.com> (original author)
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "nsDOMCSSValueList.h"
00039 #include "nsCOMPtr.h"
00040 #include "nsDOMError.h"
00041 #include "prtypes.h"
00042 #include "nsContentUtils.h"
00043 
00044 nsDOMCSSValueList::nsDOMCSSValueList(PRBool aCommaDelimited, PRBool aReadonly)
00045   : mCommaDelimited(aCommaDelimited), mReadonly(aReadonly)
00046 {
00047 }
00048 
00049 nsDOMCSSValueList::~nsDOMCSSValueList()
00050 {
00051 }
00052 
00053 NS_IMPL_ADDREF(nsDOMCSSValueList)
00054 NS_IMPL_RELEASE(nsDOMCSSValueList)
00055 
00056 // QueryInterface implementation for nsDOMCSSValueList
00057 NS_INTERFACE_MAP_BEGIN(nsDOMCSSValueList)
00058   NS_INTERFACE_MAP_ENTRY(nsIDOMCSSValueList)
00059   NS_INTERFACE_MAP_ENTRY(nsIDOMCSSValue)
00060   NS_INTERFACE_MAP_ENTRY(nsISupports)
00061   NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(CSSValueList)
00062 NS_INTERFACE_MAP_END
00063 
00064 PRBool
00065 nsDOMCSSValueList::AppendCSSValue(nsIDOMCSSValue* aValue)
00066 {
00067   return mCSSValues.AppendObject(aValue);
00068 }
00069 
00070 // nsIDOMCSSValueList
00071 
00072 NS_IMETHODIMP
00073 nsDOMCSSValueList::GetLength(PRUint32* aLength)
00074 {
00075   *aLength = mCSSValues.Count();
00076 
00077   return NS_OK;
00078 }
00079 
00080 NS_IMETHODIMP
00081 nsDOMCSSValueList::Item(PRUint32 aIndex, nsIDOMCSSValue **aReturn)
00082 {
00083   NS_ENSURE_ARG_POINTER(aReturn);
00084 
00085   *aReturn = mCSSValues[aIndex];
00086   NS_IF_ADDREF(*aReturn);
00087 
00088   return NS_OK;
00089 }
00090 
00091 // nsIDOMCSSValue
00092 
00093 NS_IMETHODIMP
00094 nsDOMCSSValueList::GetCssText(nsAString& aCssText)
00095 {
00096   aCssText.Truncate();
00097 
00098   PRUint32 count = mCSSValues.Count();
00099 
00100   nsAutoString separator;
00101   if (mCommaDelimited) {
00102     separator.AssignLiteral(", ");
00103   }
00104   else {
00105     separator.Assign(PRUnichar(' '));
00106   }
00107 
00108   nsCOMPtr<nsIDOMCSSValue> cssValue;
00109   nsAutoString tmpStr;
00110   for (PRUint32 i = 0; i < count; ++i) {
00111     cssValue = mCSSValues[i];
00112     NS_ASSERTION(cssValue, "Eek!  Someone filled the value list with null CSSValues!");
00113     if (cssValue) {
00114       cssValue->GetCssText(tmpStr);
00115 
00116       if (tmpStr.IsEmpty()) {
00117 
00118 #ifdef DEBUG_caillon
00119         NS_ERROR("Eek!  An empty CSSValue!  Bad!");
00120 #endif
00121 
00122         continue;
00123       }
00124 
00125       // If this isn't the first item in the list, then
00126       // its ok to append a separator.
00127       if (!aCssText.IsEmpty()) {
00128         aCssText.Append(separator);
00129       }
00130       aCssText.Append(tmpStr);
00131     }
00132   }
00133 
00134   return NS_OK;
00135 }
00136 
00137 NS_IMETHODIMP
00138 nsDOMCSSValueList::SetCssText(const nsAString& aCssText)
00139 {
00140   if (mReadonly) {
00141     return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
00142   }
00143 
00144   NS_NOTYETIMPLEMENTED("Can't SetCssText yet: please write me!");
00145   return NS_OK;
00146 }
00147 
00148 
00149 NS_IMETHODIMP
00150 nsDOMCSSValueList::GetCssValueType(PRUint16* aValueType)
00151 {
00152   NS_ENSURE_ARG_POINTER(aValueType);
00153   *aValueType = nsIDOMCSSValue::CSS_VALUE_LIST;
00154   return NS_OK;
00155 }
00156