Back to index

lightning-sunbird  0.9+nobinonly
nsSVGAnimatedLength.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  * Crocodile Clips Ltd..
00019  * Portions created by the Initial Developer are Copyright (C) 2001
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Alex Fritze <alex.fritze@crocodile-clips.com> (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 "nsSVGAnimatedLength.h"
00042 #include "nsSVGLength.h"
00043 #include "nsContentUtils.h"
00044 
00045 
00047 // nsSVGAnimatedLength
00048 
00049 class nsSVGAnimatedLength : public nsIDOMSVGAnimatedLength,
00050                             public nsSVGValue,
00051                             public nsISVGValueObserver,
00052                             public nsSupportsWeakReference
00053 {
00054 protected:
00055   friend nsresult NS_NewSVGAnimatedLength(nsIDOMSVGAnimatedLength** result,
00056                                           nsIDOMSVGLength* baseVal);
00057   nsSVGAnimatedLength();
00058   ~nsSVGAnimatedLength();
00059   void Init(nsIDOMSVGLength* baseVal);
00060   
00061 public:
00062   // nsISupports interface:
00063   NS_DECL_ISUPPORTS
00064 
00065   // nsIDOMSVGAnimatedLength interface:
00066   NS_DECL_NSIDOMSVGANIMATEDLENGTH
00067 
00068   // remainder of nsISVGValue interface:
00069   NS_IMETHOD SetValueString(const nsAString& aValue);
00070   NS_IMETHOD GetValueString(nsAString& aValue);
00071 
00072   // nsISVGValueObserver
00073   NS_IMETHOD WillModifySVGObservable(nsISVGValue* observable,
00074                                      modificationType aModType);
00075   NS_IMETHOD DidModifySVGObservable (nsISVGValue* observable,
00076                                      modificationType aModType);
00077   
00078   // nsISupportsWeakReference
00079   // implementation inherited from nsSupportsWeakReference
00080   
00081 protected:
00082   nsCOMPtr<nsIDOMSVGLength> mBaseVal;
00083 };
00084 
00085 
00086 
00087 //----------------------------------------------------------------------
00088 // Implementation
00089 
00090 nsSVGAnimatedLength::nsSVGAnimatedLength()
00091 {
00092 }
00093 
00094 nsSVGAnimatedLength::~nsSVGAnimatedLength()
00095 {
00096   if (!mBaseVal) return;
00097   nsCOMPtr<nsISVGValue> val = do_QueryInterface(mBaseVal);
00098   if (!val) return;
00099   val->RemoveObserver(this);
00100 }
00101 
00102 void
00103 nsSVGAnimatedLength::Init(nsIDOMSVGLength* baseVal)
00104 {
00105   mBaseVal = baseVal;
00106   if (!mBaseVal) return;
00107   nsCOMPtr<nsISVGValue> val = do_QueryInterface(mBaseVal);
00108   NS_ASSERTION(val, "baseval needs to implement nsISVGValue interface");
00109   if (!val) return;
00110   val->AddObserver(this);
00111 }
00112 
00113 //----------------------------------------------------------------------
00114 // nsISupports methods:
00115 
00116 NS_IMPL_ADDREF(nsSVGAnimatedLength)
00117 NS_IMPL_RELEASE(nsSVGAnimatedLength)
00118 
00119 
00120 NS_INTERFACE_MAP_BEGIN(nsSVGAnimatedLength)
00121   NS_INTERFACE_MAP_ENTRY(nsISVGValue)
00122   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGAnimatedLength)
00123   NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
00124   NS_INTERFACE_MAP_ENTRY(nsISVGValueObserver)
00125   NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(SVGAnimatedLength)
00126   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsISVGValue)
00127 NS_INTERFACE_MAP_END
00128   
00129 //----------------------------------------------------------------------
00130 // nsISVGValue methods:
00131 
00132 NS_IMETHODIMP
00133 nsSVGAnimatedLength::SetValueString(const nsAString& aValue)
00134 {
00135   nsCOMPtr<nsISVGValue> value = do_QueryInterface(mBaseVal);
00136   return value->SetValueString(aValue);
00137 }
00138 
00139 NS_IMETHODIMP
00140 nsSVGAnimatedLength::GetValueString(nsAString& aValue)
00141 {
00142   nsCOMPtr<nsISVGValue> value = do_QueryInterface(mBaseVal);
00143   return value->GetValueString(aValue);
00144 }
00145 
00146 //----------------------------------------------------------------------
00147 // nsIDOMSVGAnimatedLength methods:
00148 
00149 /* readonly attribute nsIDOMSVGLength baseVal; */
00150 NS_IMETHODIMP
00151 nsSVGAnimatedLength::GetBaseVal(nsIDOMSVGLength * *aBaseVal)
00152 {
00153   *aBaseVal = mBaseVal;
00154   NS_ADDREF(*aBaseVal);
00155   return NS_OK;
00156 }
00157 
00158 /* readonly attribute nsIDOMSVGLength animVal; */
00159 NS_IMETHODIMP
00160 nsSVGAnimatedLength::GetAnimVal(nsIDOMSVGLength * *aAnimVal)
00161 {
00162   *aAnimVal = mBaseVal;
00163   NS_ADDREF(*aAnimVal);
00164   return NS_OK;
00165 }
00166 
00167 //----------------------------------------------------------------------
00168 // nsISVGValueObserver methods
00169 
00170 NS_IMETHODIMP
00171 nsSVGAnimatedLength::WillModifySVGObservable(nsISVGValue* observable,
00172                                              modificationType aModType)
00173 {
00174   WillModify(aModType);
00175   return NS_OK;
00176 }
00177 
00178 NS_IMETHODIMP
00179 nsSVGAnimatedLength::DidModifySVGObservable (nsISVGValue* observable,
00180                                              modificationType aModType)
00181 {
00182   DidModify(aModType);
00183   return NS_OK;
00184 }
00185 
00187 // Exported creation functions
00188 
00189 nsresult
00190 NS_NewSVGAnimatedLength(nsIDOMSVGAnimatedLength** aResult,
00191                         nsIDOMSVGLength* baseVal)
00192 {
00193   *aResult = nsnull;
00194   
00195   nsSVGAnimatedLength* animatedLength = new nsSVGAnimatedLength();
00196   if(!animatedLength) return NS_ERROR_OUT_OF_MEMORY;
00197   NS_ADDREF(animatedLength);
00198 
00199 //  nsCOMPtr<nsIDOMSVGLength> baseVal;
00200 //  NS_NewSVGLength(getter_AddRefs(baseVal), context);
00201   
00202   animatedLength->Init(baseVal);
00203   
00204   *aResult = (nsIDOMSVGAnimatedLength*) animatedLength;
00205   
00206   return NS_OK;
00207 }