Back to index

lightning-sunbird  0.9+nobinonly
nsSVGAnimatedRect.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 "nsSVGAnimatedRect.h"
00040 #include "nsSVGRect.h"
00041 #include "nsSVGValue.h"
00042 #include "nsWeakReference.h"
00043 #include "nsContentUtils.h"
00044 
00046 // nsSVGAnimatedRect
00047 
00048 class nsSVGAnimatedRect : public nsIDOMSVGAnimatedRect,
00049                           public nsSVGValue,
00050                           public nsISVGValueObserver,
00051                           public nsSupportsWeakReference
00052 {  
00053 protected:
00054   friend nsresult NS_NewSVGAnimatedRect(nsIDOMSVGAnimatedRect** result,
00055                                         nsIDOMSVGRect* baseVal);
00056 
00057   nsSVGAnimatedRect();
00058   ~nsSVGAnimatedRect();
00059   void Init(nsIDOMSVGRect* baseVal);
00060   
00061 public:
00062   // nsISupports interface:
00063   NS_DECL_ISUPPORTS
00064 
00065   // nsIDOMSVGAnimatedRect interface:
00066   NS_DECL_NSIDOMSVGANIMATEDRECT
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<nsIDOMSVGRect> mBaseVal;
00083 };
00084 
00085 
00086 //----------------------------------------------------------------------
00087 // Implementation
00088 
00089 nsSVGAnimatedRect::nsSVGAnimatedRect()
00090 {
00091 }
00092 
00093 nsSVGAnimatedRect::~nsSVGAnimatedRect()
00094 {
00095   if (!mBaseVal) return;
00096     nsCOMPtr<nsISVGValue> val = do_QueryInterface(mBaseVal);
00097   if (!val) return;
00098   val->RemoveObserver(this);
00099 }
00100 
00101 void
00102 nsSVGAnimatedRect::Init(nsIDOMSVGRect* baseVal)
00103 {
00104   mBaseVal = baseVal;
00105   if (!mBaseVal) return;
00106   nsCOMPtr<nsISVGValue> val = do_QueryInterface(mBaseVal);
00107   if (!val) return;
00108   val->AddObserver(this);
00109 }
00110 
00111 //----------------------------------------------------------------------
00112 // nsISupports methods:
00113 
00114 NS_IMPL_ADDREF(nsSVGAnimatedRect)
00115 NS_IMPL_RELEASE(nsSVGAnimatedRect)
00116 
00117 NS_INTERFACE_MAP_BEGIN(nsSVGAnimatedRect)
00118   NS_INTERFACE_MAP_ENTRY(nsISVGValue)
00119   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGAnimatedRect)
00120   NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
00121   NS_INTERFACE_MAP_ENTRY(nsISVGValueObserver)
00122   NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(SVGAnimatedRect)
00123   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsISVGValue)
00124 NS_INTERFACE_MAP_END
00125 
00126 //----------------------------------------------------------------------
00127 // nsISVGValue methods:
00128 
00129 NS_IMETHODIMP
00130 nsSVGAnimatedRect::SetValueString(const nsAString& aValue)
00131 {
00132   nsCOMPtr<nsISVGValue> value = do_QueryInterface(mBaseVal);
00133   return value->SetValueString(aValue);
00134 }
00135 
00136 NS_IMETHODIMP
00137 nsSVGAnimatedRect::GetValueString(nsAString& aValue)
00138 {
00139   nsCOMPtr<nsISVGValue> value = do_QueryInterface(mBaseVal);
00140   return value->GetValueString(aValue);
00141 }
00142 
00143 //----------------------------------------------------------------------
00144 // nsIDOMSVGAnimatedRect methods:
00145 
00146 /* readonly attribute nsIDOMSVGRect baseVal; */
00147 NS_IMETHODIMP
00148 nsSVGAnimatedRect::GetBaseVal(nsIDOMSVGRect * *aBaseVal)
00149 {
00150   *aBaseVal = mBaseVal;
00151   NS_ADDREF(*aBaseVal);
00152   return NS_OK;
00153 }
00154 
00155 /* readonly attribute nsIDOMSVGRect animVal; */
00156 NS_IMETHODIMP
00157 nsSVGAnimatedRect::GetAnimVal(nsIDOMSVGRect * *aAnimVal)
00158 {
00159   *aAnimVal = mBaseVal;
00160   NS_ADDREF(*aAnimVal);
00161   return NS_OK;
00162 }
00163 
00164 //----------------------------------------------------------------------
00165 // nsISVGValueObserver methods
00166 
00167 NS_IMETHODIMP
00168 nsSVGAnimatedRect::WillModifySVGObservable(nsISVGValue* observable,
00169                                            modificationType aModType)
00170 {
00171   WillModify(aModType);
00172   return NS_OK;
00173 }
00174 
00175 NS_IMETHODIMP
00176 nsSVGAnimatedRect::DidModifySVGObservable (nsISVGValue* observable,
00177                                            modificationType aModType)
00178 {
00179   DidModify(aModType);
00180   return NS_OK;
00181 }
00182 
00183 
00185 // Exported creation functions:
00186 
00187 nsresult
00188 NS_NewSVGAnimatedRect(nsIDOMSVGAnimatedRect** result,
00189                       nsIDOMSVGRect* baseVal)
00190 {
00191   *result = nsnull;
00192   
00193   nsSVGAnimatedRect* animatedRect = new nsSVGAnimatedRect();
00194   if(!animatedRect) return NS_ERROR_OUT_OF_MEMORY;
00195   NS_ADDREF(animatedRect);
00196 
00197   animatedRect->Init(baseVal);
00198   
00199   *result = (nsIDOMSVGAnimatedRect*) animatedRect;
00200   
00201   return NS_OK;
00202 }
00203