Back to index

lightning-sunbird  0.9+nobinonly
nsSVGAnimatedEnumeration.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  * IBM Corporation
00019  * Portions created by the Initial Developer are Copyright (C) 2004
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Tim Rowley <tor@acm.org> (original author)
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or 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 "nsSVGValue.h"
00040 #include "nsWeakReference.h"
00041 #include "nsSVGAnimatedEnumeration.h"
00042 #include "nsISVGEnum.h"
00043 #include "nsContentUtils.h"
00044 
00046 // nsSVGAnimatedEnumeration
00047 
00048 class nsSVGAnimatedEnumeration : public nsIDOMSVGAnimatedEnumeration,
00049                                  public nsSVGValue,
00050                                  public nsISVGValueObserver,
00051                                  public nsSupportsWeakReference
00052 {
00053 protected:
00054   friend nsresult NS_NewSVGAnimatedEnumeration(nsIDOMSVGAnimatedEnumeration** result,
00055                                                nsISVGEnum* aBaseVal);
00056   nsSVGAnimatedEnumeration();
00057   ~nsSVGAnimatedEnumeration();
00058   nsresult Init(nsISVGEnum* aBaseVal);
00059   
00060 public:
00061   // nsISupports interface:
00062   NS_DECL_ISUPPORTS
00063 
00064   // nsIDOMSVGAnimatedEnumeration interface:
00065   NS_DECL_NSIDOMSVGANIMATEDENUMERATION
00066 
00067   // remainder of nsISVGValue interface:
00068   NS_IMETHOD SetValueString(const nsAString& aValue);
00069   NS_IMETHOD GetValueString(nsAString& aValue);
00070 
00071   // nsISVGValueObserver
00072   NS_IMETHOD WillModifySVGObservable(nsISVGValue* observable,
00073                                      modificationType aModType);
00074   NS_IMETHOD DidModifySVGObservable (nsISVGValue* observable,
00075                                      modificationType aModType);
00076   
00077   // nsISupportsWeakReference
00078   // implementation inherited from nsSupportsWeakReference
00079   
00080 protected:
00081   nsCOMPtr<nsISVGEnum> mBaseVal;
00082 };
00083 
00084 
00085 
00086 //----------------------------------------------------------------------
00087 // Implementation
00088 
00089 nsSVGAnimatedEnumeration::nsSVGAnimatedEnumeration()
00090 {
00091 }
00092 
00093 nsSVGAnimatedEnumeration::~nsSVGAnimatedEnumeration()
00094 {
00095   nsCOMPtr<nsISVGValue> val = do_QueryInterface(mBaseVal);
00096   if (val) val->RemoveObserver(this);
00097 }
00098 
00099 nsresult
00100 nsSVGAnimatedEnumeration::Init(nsISVGEnum* aBaseVal)
00101 {
00102   mBaseVal = aBaseVal;
00103   if (!mBaseVal) return NS_ERROR_FAILURE;
00104   nsCOMPtr<nsISVGValue> val = do_QueryInterface(mBaseVal);
00105   NS_ASSERTION(val, "baseval needs to implement nsISVGValue interface");
00106   if (!val) return NS_ERROR_FAILURE;
00107   val->AddObserver(this);
00108   return NS_OK;
00109 }
00110 
00111 //----------------------------------------------------------------------
00112 // nsISupports methods:
00113 
00114 NS_IMPL_ADDREF(nsSVGAnimatedEnumeration)
00115 NS_IMPL_RELEASE(nsSVGAnimatedEnumeration)
00116 
00117 
00118 NS_INTERFACE_MAP_BEGIN(nsSVGAnimatedEnumeration)
00119   NS_INTERFACE_MAP_ENTRY(nsISVGValue)
00120   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGAnimatedEnumeration)
00121   NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
00122   NS_INTERFACE_MAP_ENTRY(nsISVGValueObserver)
00123   NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(SVGAnimatedEnumeration)
00124   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsISVGValue)
00125 NS_INTERFACE_MAP_END
00126   
00127 //----------------------------------------------------------------------
00128 // nsISVGValue methods:
00129 
00130 NS_IMETHODIMP
00131 nsSVGAnimatedEnumeration::SetValueString(const nsAString& aValue)
00132 {
00133   nsCOMPtr<nsISVGValue> value = do_QueryInterface(mBaseVal);
00134   NS_ASSERTION(value, "svg animated enumeration base value has wrong interface!");
00135   return value->SetValueString(aValue);
00136 }
00137 
00138 NS_IMETHODIMP
00139 nsSVGAnimatedEnumeration::GetValueString(nsAString& aValue)
00140 {
00141   nsCOMPtr<nsISVGValue> value = do_QueryInterface(mBaseVal);
00142   NS_ASSERTION(value, "svg animated enumeration base value has wrong interface!");
00143   return value->GetValueString(aValue);
00144 }
00145 
00146 //----------------------------------------------------------------------
00147 // nsIDOMSVGAnimatedEnumeration methods:
00148 
00149 /* attribute unsigned short baseVal; */
00150 NS_IMETHODIMP
00151 nsSVGAnimatedEnumeration::GetBaseVal(PRUint16 *aBaseVal)
00152 {
00153   mBaseVal->GetIntegerValue(*aBaseVal);
00154   return NS_OK;
00155 }
00156 
00157 NS_IMETHODIMP
00158 nsSVGAnimatedEnumeration::SetBaseVal(PRUint16 aBaseVal)
00159 {
00160   return mBaseVal->SetIntegerValue(aBaseVal);
00161 }
00162 
00163 /* readonly attribute unsigned short animVal; */
00164 NS_IMETHODIMP
00165 nsSVGAnimatedEnumeration::GetAnimVal(PRUint16 *aAnimVal)
00166 {
00167   mBaseVal->GetIntegerValue(*aAnimVal);
00168   return NS_OK;
00169 }
00170 
00171 //----------------------------------------------------------------------
00172 // nsISVGValueObserver methods
00173 
00174 NS_IMETHODIMP
00175 nsSVGAnimatedEnumeration::WillModifySVGObservable(nsISVGValue* observable,
00176                                                   modificationType aModType)
00177 {
00178   WillModify(aModType);
00179   return NS_OK;
00180 }
00181 
00182 NS_IMETHODIMP
00183 nsSVGAnimatedEnumeration::DidModifySVGObservable (nsISVGValue* observable,
00184                                                   modificationType aModType)
00185 {
00186   DidModify(aModType);
00187   return NS_OK;
00188 }
00189 
00191 // Exported creation functions
00192 
00193 nsresult
00194 NS_NewSVGAnimatedEnumeration(nsIDOMSVGAnimatedEnumeration** aResult,
00195                              nsISVGEnum* aBaseVal)
00196 {
00197   *aResult = nsnull;
00198   
00199   nsSVGAnimatedEnumeration* animatedEnum = new nsSVGAnimatedEnumeration();
00200   if (!animatedEnum) return NS_ERROR_OUT_OF_MEMORY;
00201   NS_ADDREF(animatedEnum);
00202 
00203   nsresult rv = animatedEnum->Init(aBaseVal);
00204   
00205   *aResult = (nsIDOMSVGAnimatedEnumeration*) animatedEnum;
00206   
00207   return rv;
00208 }
00209 
00210