Back to index

lightning-sunbird  0.9+nobinonly
nsSVGAnimatedPreserveAspectRatio.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 Mozilla SVG Project code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Jonathan Watt.
00019  * Portions created by the Initial Developer are Copyright (C) 2004
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Jonathan Watt <jonathan.watt@strath.ac.uk> (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 "nsSVGAnimatedPreserveAspectRatio.h"
00040 #include "nsSVGPreserveAspectRatio.h"
00041 #include "nsSVGValue.h"
00042 #include "nsWeakReference.h"
00043 #include "nsContentUtils.h"
00044 
00046 // nsSVGAnimatedPreserveAspectRatio
00047 
00048 class nsSVGAnimatedPreserveAspectRatio : public nsIDOMSVGAnimatedPreserveAspectRatio,
00049                                          public nsSVGValue,
00050                                          public nsISVGValueObserver,
00051                                          public nsSupportsWeakReference
00052 {
00053 protected:
00054   friend nsresult NS_NewSVGAnimatedPreserveAspectRatio(
00055                                  nsIDOMSVGAnimatedPreserveAspectRatio** result,
00056                                  nsIDOMSVGPreserveAspectRatio* baseVal);
00057 
00058   nsSVGAnimatedPreserveAspectRatio();
00059   ~nsSVGAnimatedPreserveAspectRatio();
00060   void Init(nsIDOMSVGPreserveAspectRatio* baseVal);
00061 
00062 public:
00063   // nsISupports interface:
00064   NS_DECL_ISUPPORTS
00065 
00066   // nsIDOMSVGAnimatedPreserveAspectRatio interface:
00067   NS_DECL_NSIDOMSVGANIMATEDPRESERVEASPECTRATIO
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<nsIDOMSVGPreserveAspectRatio> mBaseVal;
00084 };
00085 
00086 
00087 //----------------------------------------------------------------------
00088 // Implementation
00089 
00090 nsSVGAnimatedPreserveAspectRatio::nsSVGAnimatedPreserveAspectRatio()
00091 {
00092 }
00093 
00094 nsSVGAnimatedPreserveAspectRatio::~nsSVGAnimatedPreserveAspectRatio()
00095 {
00096   nsCOMPtr<nsISVGValue> val( do_QueryInterface(mBaseVal) );
00097   if (!val) return;
00098   val->RemoveObserver(this);
00099 }
00100 
00101 void
00102 nsSVGAnimatedPreserveAspectRatio::Init(nsIDOMSVGPreserveAspectRatio* aBaseVal)
00103 {
00104   mBaseVal = aBaseVal;
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(nsSVGAnimatedPreserveAspectRatio)
00115 NS_IMPL_RELEASE(nsSVGAnimatedPreserveAspectRatio)
00116 
00117 NS_INTERFACE_MAP_BEGIN(nsSVGAnimatedPreserveAspectRatio)
00118   NS_INTERFACE_MAP_ENTRY(nsISVGValue)
00119   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGAnimatedPreserveAspectRatio)
00120   NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
00121   NS_INTERFACE_MAP_ENTRY(nsISVGValueObserver)
00122   NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(SVGAnimatedPreserveAspectRatio)
00123   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsISVGValue)
00124 NS_INTERFACE_MAP_END
00125 
00126 //----------------------------------------------------------------------
00127 // nsISVGValue methods:
00128 
00129 NS_IMETHODIMP
00130 nsSVGAnimatedPreserveAspectRatio::SetValueString(const nsAString& aValue)
00131 {
00132   nsresult rv;
00133   nsCOMPtr<nsISVGValue> val( do_QueryInterface(mBaseVal, &rv) );
00134   return NS_FAILED(rv)? rv: val->SetValueString(aValue);
00135 }
00136 
00137 NS_IMETHODIMP
00138 nsSVGAnimatedPreserveAspectRatio::GetValueString(nsAString& aValue)
00139 {
00140   nsresult rv;
00141   nsCOMPtr<nsISVGValue> val( do_QueryInterface(mBaseVal, &rv) );
00142   return NS_FAILED(rv)? rv: val->GetValueString(aValue);
00143 }
00144 
00145 //----------------------------------------------------------------------
00146 // nsIDOMSVGAnimatedPreserveAspectRatio methods:
00147 
00148 /* readonly attribute nsIDOMSVGPreserveAspectRatio baseVal; */
00149 NS_IMETHODIMP
00150 nsSVGAnimatedPreserveAspectRatio::GetBaseVal(nsIDOMSVGPreserveAspectRatio** aBaseVal)
00151 {
00152   *aBaseVal = mBaseVal;
00153   NS_ADDREF(*aBaseVal);
00154   return NS_OK;
00155 }
00156 
00157 /* readonly attribute nsIDOMSVGPreserveAspectRatio animVal; */
00158 NS_IMETHODIMP
00159 nsSVGAnimatedPreserveAspectRatio::GetAnimVal(nsIDOMSVGPreserveAspectRatio** aAnimVal)
00160 {
00161   *aAnimVal = mBaseVal;
00162   NS_ADDREF(*aAnimVal);
00163   return NS_OK;
00164 }
00165 
00166 //----------------------------------------------------------------------
00167 // nsISVGValueObserver methods
00168 
00169 NS_IMETHODIMP
00170 nsSVGAnimatedPreserveAspectRatio::WillModifySVGObservable(nsISVGValue* observable,
00171                                                           modificationType aModType)
00172 {
00173   WillModify(aModType);
00174   return NS_OK;
00175 }
00176 
00177 NS_IMETHODIMP
00178 nsSVGAnimatedPreserveAspectRatio::DidModifySVGObservable (nsISVGValue* observable,
00179                                                           modificationType aModType)
00180 {
00181   DidModify(aModType);
00182   return NS_OK;
00183 }
00184 
00186 // Exported creation functions:
00187 
00188 nsresult
00189 NS_NewSVGAnimatedPreserveAspectRatio(nsIDOMSVGAnimatedPreserveAspectRatio** result,
00190                                      nsIDOMSVGPreserveAspectRatio* baseVal)
00191 {
00192   *result = nsnull;
00193 
00194   if (!baseVal) {
00195     NS_ERROR("need baseVal");
00196     return NS_ERROR_FAILURE;
00197   }
00198 
00199   nsSVGAnimatedPreserveAspectRatio* animatedPreserveAspectRatio = new nsSVGAnimatedPreserveAspectRatio();
00200   if (!animatedPreserveAspectRatio)
00201     return NS_ERROR_OUT_OF_MEMORY;
00202 
00203   NS_ADDREF(animatedPreserveAspectRatio);
00204   animatedPreserveAspectRatio->Init(baseVal);
00205   *result = (nsIDOMSVGAnimatedPreserveAspectRatio*) animatedPreserveAspectRatio;
00206 
00207   return NS_OK;
00208 }