Back to index

lightning-sunbird  0.9+nobinonly
nsSVGAnimatedAngle.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 IBM Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 2004
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either of the GNU General Public License Version 2 or later (the "GPL"),
00025  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00026  * in which case the provisions of the GPL or the LGPL are applicable instead
00027  * of those above. If you wish to allow use of your version of this file only
00028  * under the terms of either the GPL or the LGPL, and not to allow others to
00029  * use your version of this file under the terms of the MPL, indicate your
00030  * decision by deleting the provisions above and replace them with the notice
00031  * and other provisions required by the GPL or the LGPL. If you do not delete
00032  * the provisions above, a recipient may use your version of this file under
00033  * the terms of any one of the MPL, the GPL or the LGPL.
00034  *
00035  * ***** END LICENSE BLOCK ***** */
00036 
00037 #include "nsSVGValue.h"
00038 #include "nsWeakReference.h"
00039 #include "nsSVGAnimatedAngle.h"
00040 #include "nsSVGLength.h"
00041 #include "nsContentUtils.h"
00042 
00043 
00045 // nsSVGAnimatedAngle
00046 
00047 class nsSVGAnimatedAngle : public nsIDOMSVGAnimatedAngle,
00048                            public nsSVGValue,
00049                            public nsISVGValueObserver,
00050                            public nsSupportsWeakReference
00051 {
00052 protected:
00053   friend nsresult NS_NewSVGAnimatedAngle(nsIDOMSVGAnimatedAngle** result,
00054                                          nsIDOMSVGAngle* baseVal);
00055   nsSVGAnimatedAngle();
00056   ~nsSVGAnimatedAngle();
00057   void Init(nsIDOMSVGAngle* baseVal);
00058   
00059 public:
00060   // nsISupports interface:
00061   NS_DECL_ISUPPORTS
00062 
00063   // nsIDOMSVGAnimatedAngle interface:
00064   NS_DECL_NSIDOMSVGANIMATEDANGLE
00065 
00066   // remainder of nsISVGValue interface:
00067   NS_IMETHOD SetValueString(const nsAString& aValue);
00068   NS_IMETHOD GetValueString(nsAString& aValue);
00069 
00070   // nsISVGValueObserver
00071   NS_IMETHOD WillModifySVGObservable(nsISVGValue* observable,
00072                                      modificationType aModType);
00073   NS_IMETHOD DidModifySVGObservable (nsISVGValue* observable,
00074                                      modificationType aModType);
00075   
00076   // nsISupportsWeakReference
00077   // implementation inherited from nsSupportsWeakReference
00078   
00079 protected:
00080   nsCOMPtr<nsIDOMSVGAngle> mBaseVal;
00081 };
00082 
00083 
00084 
00085 //----------------------------------------------------------------------
00086 // Implementation
00087 
00088 nsSVGAnimatedAngle::nsSVGAnimatedAngle()
00089 {
00090 }
00091 
00092 nsSVGAnimatedAngle::~nsSVGAnimatedAngle()
00093 {
00094   if (!mBaseVal) return;
00095   nsCOMPtr<nsISVGValue> val = do_QueryInterface(mBaseVal);
00096   if (!val) return;
00097   val->RemoveObserver(this);
00098 }
00099 
00100 void
00101 nsSVGAnimatedAngle::Init(nsIDOMSVGAngle* baseVal)
00102 {
00103   mBaseVal = baseVal;
00104   if (!mBaseVal) return;
00105   nsCOMPtr<nsISVGValue> val = do_QueryInterface(mBaseVal);
00106   NS_ASSERTION(val, "baseval needs to implement nsISVGValue interface");
00107   if (!val) return;
00108   val->AddObserver(this);
00109 }
00110 
00111 //----------------------------------------------------------------------
00112 // nsISupports methods:
00113 
00114 NS_IMPL_ADDREF(nsSVGAnimatedAngle)
00115 NS_IMPL_RELEASE(nsSVGAnimatedAngle)
00116 
00117 
00118 NS_INTERFACE_MAP_BEGIN(nsSVGAnimatedAngle)
00119   NS_INTERFACE_MAP_ENTRY(nsISVGValue)
00120   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGAnimatedAngle)
00121   NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
00122   NS_INTERFACE_MAP_ENTRY(nsISVGValueObserver)
00123   NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(SVGAnimatedAngle)
00124   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsISVGValue)
00125 NS_INTERFACE_MAP_END
00126   
00127 //----------------------------------------------------------------------
00128 // nsISVGValue methods:
00129 
00130 NS_IMETHODIMP
00131 nsSVGAnimatedAngle::SetValueString(const nsAString& aValue)
00132 {
00133   nsCOMPtr<nsISVGValue> value = do_QueryInterface(mBaseVal);
00134   return value->SetValueString(aValue);
00135 }
00136 
00137 NS_IMETHODIMP
00138 nsSVGAnimatedAngle::GetValueString(nsAString& aValue)
00139 {
00140   nsCOMPtr<nsISVGValue> value = do_QueryInterface(mBaseVal);
00141   return value->GetValueString(aValue);
00142 }
00143 
00144 //----------------------------------------------------------------------
00145 // nsIDOMSVGAnimatedAngle methods:
00146 
00147 /* readonly attribute nsIDOMSVGAngle baseVal; */
00148 NS_IMETHODIMP
00149 nsSVGAnimatedAngle::GetBaseVal(nsIDOMSVGAngle * *aBaseVal)
00150 {
00151   *aBaseVal = mBaseVal;
00152   NS_ADDREF(*aBaseVal);
00153   return NS_OK;
00154 }
00155 
00156 /* readonly attribute nsIDOMSVGAngle animVal; */
00157 NS_IMETHODIMP
00158 nsSVGAnimatedAngle::GetAnimVal(nsIDOMSVGAngle * *aAnimVal)
00159 {
00160   *aAnimVal = mBaseVal;
00161   NS_ADDREF(*aAnimVal);
00162   return NS_OK;
00163 }
00164 
00165 //----------------------------------------------------------------------
00166 // nsISVGValueObserver methods
00167 
00168 NS_IMETHODIMP
00169 nsSVGAnimatedAngle::WillModifySVGObservable(nsISVGValue* observable,
00170                                             modificationType aModType)
00171 {
00172   WillModify(aModType);
00173   return NS_OK;
00174 }
00175 
00176 NS_IMETHODIMP
00177 nsSVGAnimatedAngle::DidModifySVGObservable (nsISVGValue* observable,
00178                                             modificationType aModType)
00179 {
00180   DidModify(aModType);
00181   return NS_OK;
00182 }
00183 
00185 // Exported creation functions
00186 
00187 nsresult
00188 NS_NewSVGAnimatedAngle(nsIDOMSVGAnimatedAngle** aResult,
00189                        nsIDOMSVGAngle* baseVal)
00190 {
00191   *aResult = nsnull;
00192   
00193   nsSVGAnimatedAngle* animatedLength = new nsSVGAnimatedAngle();
00194   if(!animatedLength) return NS_ERROR_OUT_OF_MEMORY;
00195   NS_ADDREF(animatedLength);
00196 
00197   animatedLength->Init(baseVal);
00198   
00199   *aResult = (nsIDOMSVGAnimatedAngle*) animatedLength;
00200   
00201   return NS_OK;
00202 }