Back to index

lightning-sunbird  0.9+nobinonly
nsSVGAnimatedNumberList.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Mozilla SVG project.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Scooter Morris.
00019  * Portions created by the Initial Developer are Copyright (C) 2004
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Scooter Morris <scootermorris@comcast.net> (original author)
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include "nsSVGAnimatedNumberList.h"
00040 #include "nsSVGNumberList.h"
00041 #include "nsSVGValue.h"
00042 #include "nsWeakReference.h"
00043 #include "nsContentUtils.h"
00044 
00046 // nsSVGAnimatedNumberList
00047 
00048 class nsSVGAnimatedNumberList : public nsIDOMSVGAnimatedNumberList,
00049                                 public nsSVGValue,
00050                                 public nsISVGValueObserver,
00051                                 public nsSupportsWeakReference
00052 {  
00053 protected:
00054   friend nsresult
00055   NS_NewSVGAnimatedNumberList(nsIDOMSVGAnimatedNumberList** result,
00056                               nsIDOMSVGNumberList* aBaseVal);
00057 
00058   nsSVGAnimatedNumberList();
00059   ~nsSVGAnimatedNumberList();
00060   nsresult Init(nsIDOMSVGNumberList* aBaseVal);
00061   
00062 public:
00063   // nsISupports interface:
00064   NS_DECL_ISUPPORTS
00065 
00066   // nsIDOMSVGAnimatedNumberList interface:
00067   NS_DECL_NSIDOMSVGANIMATEDNUMBERLIST
00068 
00069   // remainder of nsISVGValue interface:
00070   NS_IMETHOD SetValueString(const nsAString& aValue);
00071   NS_IMETHOD GetValueString(nsAString& aValue);
00072 
00073   // nsISVGValueObserver
00074   NS_IMETHOD WillModifySVGObservable(nsISVGValue* observable,
00075                                      modificationType aModType);
00076   NS_IMETHOD DidModifySVGObservable (nsISVGValue* observable,
00077                                      modificationType aModType);
00078   
00079   // nsISupportsWeakReference
00080   // implementation inherited from nsSupportsWeakReference
00081   
00082 protected:
00083   nsCOMPtr<nsIDOMSVGNumberList> mBaseVal;
00084 };
00085 
00086 
00087 //----------------------------------------------------------------------
00088 // Implementation
00089 
00090 nsSVGAnimatedNumberList::nsSVGAnimatedNumberList()
00091 {
00092 }
00093 
00094 nsSVGAnimatedNumberList::~nsSVGAnimatedNumberList()
00095 {
00096   nsCOMPtr<nsISVGValue> val = do_QueryInterface(mBaseVal);
00097   if (val)
00098     val->RemoveObserver(this);
00099 }
00100 
00101 nsresult
00102 nsSVGAnimatedNumberList::Init(nsIDOMSVGNumberList* aBaseVal)
00103 {
00104   mBaseVal = aBaseVal;
00105   if (!mBaseVal) return NS_ERROR_FAILURE;
00106   nsCOMPtr<nsISVGValue> val = do_QueryInterface(mBaseVal);
00107   if (!val) return NS_ERROR_FAILURE;
00108   val->AddObserver(this);
00109   return NS_OK;
00110 }
00111 
00112 //----------------------------------------------------------------------
00113 // nsISupports methods:
00114 
00115 NS_IMPL_ADDREF(nsSVGAnimatedNumberList)
00116 NS_IMPL_RELEASE(nsSVGAnimatedNumberList)
00117 
00118 NS_INTERFACE_MAP_BEGIN(nsSVGAnimatedNumberList)
00119   NS_INTERFACE_MAP_ENTRY(nsISVGValue)
00120   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGAnimatedNumberList)
00121   NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
00122   NS_INTERFACE_MAP_ENTRY(nsISVGValueObserver)
00123   NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(SVGAnimatedNumberList)
00124   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsISVGValue)
00125 NS_INTERFACE_MAP_END
00126 
00127 
00128 //----------------------------------------------------------------------
00129 // nsISVGValue methods:
00130 
00131 NS_IMETHODIMP
00132 nsSVGAnimatedNumberList::SetValueString(const nsAString& aValue)
00133 {
00134   nsCOMPtr<nsISVGValue> value = do_QueryInterface(mBaseVal);
00135   NS_ASSERTION(value, "value doesn't support SVGValue interfaces");
00136   return value->SetValueString(aValue);
00137 }
00138 
00139 NS_IMETHODIMP
00140 nsSVGAnimatedNumberList::GetValueString(nsAString& aValue)
00141 {
00142   nsCOMPtr<nsISVGValue> value = do_QueryInterface(mBaseVal);
00143   NS_ASSERTION(value, "value doesn't support SVGValue interfaces");
00144   return value->GetValueString(aValue);
00145 }
00146 
00147 //----------------------------------------------------------------------
00148 // nsIDOMSVGAnimatedNumberList methods:
00149 
00150 /* readonly attribute nsIDOMSVGNumberList aBaseVal; */
00151 NS_IMETHODIMP
00152 nsSVGAnimatedNumberList::GetBaseVal(nsIDOMSVGNumberList * *aBaseVal)
00153 {
00154   *aBaseVal = mBaseVal;
00155   NS_ADDREF(*aBaseVal);
00156   return NS_OK;
00157 }
00158 
00159 /* readonly attribute nsIDOMSVGNumberList animVal; */
00160 NS_IMETHODIMP
00161 nsSVGAnimatedNumberList::GetAnimVal(nsIDOMSVGNumberList * *aAnimVal)
00162 {
00163   *aAnimVal = mBaseVal;
00164   NS_ADDREF(*aAnimVal);
00165   return NS_OK;
00166 }
00167 
00168 //----------------------------------------------------------------------
00169 // nsISVGValueObserver methods
00170 
00171 NS_IMETHODIMP
00172 nsSVGAnimatedNumberList::WillModifySVGObservable(nsISVGValue* observable,
00173                                                  modificationType aModType)
00174 {
00175   WillModify(aModType);
00176   return NS_OK;
00177 }
00178 
00179 NS_IMETHODIMP
00180 nsSVGAnimatedNumberList::DidModifySVGObservable (nsISVGValue* observable,
00181                                                  modificationType aModType)
00182 {
00183   DidModify(aModType);
00184   return NS_OK;
00185 }
00186 
00187 
00189 // Exported creation functions:
00190 
00191 nsresult
00192 NS_NewSVGAnimatedNumberList(nsIDOMSVGAnimatedNumberList** result,
00193                             nsIDOMSVGNumberList* aBaseVal)
00194 {
00195   *result = nsnull;
00196   
00197   nsSVGAnimatedNumberList* animatedNumberList = new nsSVGAnimatedNumberList();
00198   if (!animatedNumberList) return NS_ERROR_OUT_OF_MEMORY;
00199   NS_ADDREF(animatedNumberList);
00200 
00201   if (NS_FAILED(animatedNumberList->Init(aBaseVal))) {
00202     NS_RELEASE(animatedNumberList);
00203     return NS_ERROR_FAILURE;
00204   }
00205   
00206   *result = (nsIDOMSVGAnimatedNumberList*) animatedNumberList;
00207   
00208   return NS_OK;
00209 }
00210 
00211