Back to index

lightning-sunbird  0.9+nobinonly
nsSVGRectElement.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  *   William Cook <william.cook@crocodile-clips.com> (original author)
00024  *   Alex Fritze <alex.fritze@crocodile-clips.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either of the GNU General Public License Version 2 or later (the "GPL"),
00028  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #include "nsSVGGraphicElement.h"
00041 #include "nsSVGAtoms.h"
00042 #include "nsSVGAnimatedLength.h"
00043 #include "nsSVGLength.h"
00044 #include "nsIDOMSVGRectElement.h"
00045 #include "nsCOMPtr.h"
00046 #include "nsISVGSVGElement.h"
00047 #include "nsSVGCoordCtxProvider.h"
00048 
00049 typedef nsSVGGraphicElement nsSVGRectElementBase;
00050 
00051 class nsSVGRectElement : public nsSVGRectElementBase,
00052                          public nsIDOMSVGRectElement
00053 {
00054 protected:
00055   friend nsresult NS_NewSVGRectElement(nsIContent **aResult,
00056                                        nsINodeInfo *aNodeInfo);
00057   nsSVGRectElement(nsINodeInfo* aNodeInfo);
00058   virtual ~nsSVGRectElement();
00059   nsresult Init();
00060 
00061 public:
00062   // interfaces:
00063 
00064   NS_DECL_ISUPPORTS_INHERITED
00065   NS_DECL_NSIDOMSVGRECTELEMENT
00066 
00067   // xxx I wish we could use virtual inheritance
00068   NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsSVGRectElementBase::)
00069   NS_FORWARD_NSIDOMELEMENT(nsSVGRectElementBase::)
00070   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGRectElementBase::)
00071 
00072   // nsISVGContent specializations:
00073   virtual void ParentChainChanged();
00074 
00075 protected:
00076   
00077   nsCOMPtr<nsIDOMSVGAnimatedLength> mX;
00078   nsCOMPtr<nsIDOMSVGAnimatedLength> mY;
00079   nsCOMPtr<nsIDOMSVGAnimatedLength> mWidth;
00080   nsCOMPtr<nsIDOMSVGAnimatedLength> mHeight;
00081   nsCOMPtr<nsIDOMSVGAnimatedLength> mRx;
00082   nsCOMPtr<nsIDOMSVGAnimatedLength> mRy;
00083 
00084 };
00085 
00086 
00087 NS_IMPL_NS_NEW_SVG_ELEMENT(Rect)
00088 
00089 
00090 //----------------------------------------------------------------------
00091 // nsISupports methods
00092 
00093 NS_IMPL_ADDREF_INHERITED(nsSVGRectElement,nsSVGRectElementBase)
00094 NS_IMPL_RELEASE_INHERITED(nsSVGRectElement,nsSVGRectElementBase)
00095 
00096 NS_INTERFACE_MAP_BEGIN(nsSVGRectElement)
00097   NS_INTERFACE_MAP_ENTRY(nsIDOMNode)
00098   NS_INTERFACE_MAP_ENTRY(nsIDOMElement)
00099   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGElement)
00100   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGRectElement)
00101   NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(SVGRectElement)
00102 NS_INTERFACE_MAP_END_INHERITING(nsSVGRectElementBase)
00103 
00104 //----------------------------------------------------------------------
00105 // Implementation
00106 
00107 nsSVGRectElement::nsSVGRectElement(nsINodeInfo *aNodeInfo)
00108   : nsSVGRectElementBase(aNodeInfo)
00109 {
00110 
00111 }
00112 
00113 nsSVGRectElement::~nsSVGRectElement()
00114 {
00115 }
00116 
00117 
00118 nsresult
00119 nsSVGRectElement::Init()
00120 {
00121   nsresult rv = nsSVGRectElementBase::Init();
00122   NS_ENSURE_SUCCESS(rv,rv);
00123 
00124   // Create mapped properties:
00125 
00126   // DOM property: x ,  #IMPLIED attrib: x
00127   {
00128     nsCOMPtr<nsISVGLength> length;
00129     rv = NS_NewSVGLength(getter_AddRefs(length),
00130                          0.0f);
00131     NS_ENSURE_SUCCESS(rv,rv);
00132     rv = NS_NewSVGAnimatedLength(getter_AddRefs(mX), length);
00133     NS_ENSURE_SUCCESS(rv,rv);
00134     rv = AddMappedSVGValue(nsSVGAtoms::x, mX);
00135     NS_ENSURE_SUCCESS(rv,rv);
00136   }
00137 
00138   // DOM property: y ,  #IMPLIED attrib: y
00139   {
00140     nsCOMPtr<nsISVGLength> length;
00141     rv = NS_NewSVGLength(getter_AddRefs(length),
00142                          0.0f);
00143     NS_ENSURE_SUCCESS(rv,rv);
00144     rv = NS_NewSVGAnimatedLength(getter_AddRefs(mY), length);
00145     NS_ENSURE_SUCCESS(rv,rv);
00146     rv = AddMappedSVGValue(nsSVGAtoms::y, mY);
00147     NS_ENSURE_SUCCESS(rv,rv);
00148   }
00149 
00150   // DOM property: width ,  #REQUIRED  attrib: width
00151   // XXX: enforce requiredness
00152   {
00153     nsCOMPtr<nsISVGLength> length;
00154     rv = NS_NewSVGLength(getter_AddRefs(length),
00155                          0.0f);
00156     NS_ENSURE_SUCCESS(rv,rv);
00157     rv = NS_NewSVGAnimatedLength(getter_AddRefs(mWidth), length);
00158     NS_ENSURE_SUCCESS(rv,rv);
00159     rv = AddMappedSVGValue(nsSVGAtoms::width, mWidth);
00160     NS_ENSURE_SUCCESS(rv,rv);
00161   }
00162 
00163   // DOM property: height ,  #REQUIRED  attrib: height
00164   // XXX: enforce requiredness
00165   {
00166     nsCOMPtr<nsISVGLength> length;
00167     rv = NS_NewSVGLength(getter_AddRefs(length),
00168                          0.0f);
00169     NS_ENSURE_SUCCESS(rv,rv);
00170     rv = NS_NewSVGAnimatedLength(getter_AddRefs(mHeight), length);
00171     NS_ENSURE_SUCCESS(rv,rv);
00172     rv = AddMappedSVGValue(nsSVGAtoms::height, mHeight);
00173     NS_ENSURE_SUCCESS(rv,rv);
00174   }
00175   // DOM property: rx ,  #IMPLIED  attrib: rx
00176   // XXX: enforce requiredness
00177   {
00178     nsCOMPtr<nsISVGLength> length;
00179     rv = NS_NewSVGLength(getter_AddRefs(length),
00180                          0.0f);
00181     NS_ENSURE_SUCCESS(rv,rv);
00182     rv = NS_NewSVGAnimatedLength(getter_AddRefs(mRx), length);
00183     NS_ENSURE_SUCCESS(rv,rv);
00184     rv = AddMappedSVGValue(nsSVGAtoms::rx, mRx);
00185     NS_ENSURE_SUCCESS(rv,rv);
00186   }
00187 
00188   // DOM property: ry ,  #IMPLIED  attrib: ry
00189   // XXX: enforce requiredness
00190   {
00191     nsCOMPtr<nsISVGLength> length;
00192     rv = NS_NewSVGLength(getter_AddRefs(length),
00193                          0.0f);
00194     NS_ENSURE_SUCCESS(rv,rv);
00195     rv = NS_NewSVGAnimatedLength(getter_AddRefs(mRy), length);
00196     NS_ENSURE_SUCCESS(rv,rv);
00197     rv = AddMappedSVGValue(nsSVGAtoms::ry, mRy);
00198     NS_ENSURE_SUCCESS(rv,rv);
00199   }
00200 
00201   return rv;
00202 }
00203 
00204 //----------------------------------------------------------------------
00205 // nsIDOMNode methods
00206 
00207 
00208 NS_IMPL_DOM_CLONENODE_WITH_INIT(nsSVGRectElement)
00209 
00210 
00211 //----------------------------------------------------------------------
00212 // nsIDOMSVGRectElement methods
00213 
00214 /* readonly attribute nsIDOMSVGAnimatedLength x; */
00215 NS_IMETHODIMP nsSVGRectElement::GetX(nsIDOMSVGAnimatedLength * *aX)
00216 {
00217   *aX = mX;
00218   NS_IF_ADDREF(*aX);
00219   return NS_OK;
00220 }
00221 
00222 /* readonly attribute nsIDOMSVGAnimatedLength y; */
00223 NS_IMETHODIMP nsSVGRectElement::GetY(nsIDOMSVGAnimatedLength * *aY)
00224 {
00225   *aY = mY;
00226   NS_IF_ADDREF(*aY);
00227   return NS_OK;
00228 }
00229 
00230 /* readonly attribute nsIDOMSVGAnimatedLength width; */
00231 NS_IMETHODIMP nsSVGRectElement::GetWidth(nsIDOMSVGAnimatedLength * *aWidth)
00232 {
00233   *aWidth = mWidth;
00234   NS_IF_ADDREF(*aWidth);
00235   return NS_OK;
00236 }
00237 
00238 /* readonly attribute nsIDOMSVGAnimatedLength height; */
00239 NS_IMETHODIMP nsSVGRectElement::GetHeight(nsIDOMSVGAnimatedLength * *aHeight)
00240 {
00241   *aHeight = mHeight;
00242   NS_IF_ADDREF(*aHeight);
00243   return NS_OK;
00244 }
00245 
00246 /* readonly attribute nsIDOMSVGAnimatedLength rx; */
00247 NS_IMETHODIMP nsSVGRectElement::GetRx(nsIDOMSVGAnimatedLength * *aRx)
00248 {
00249   *aRx = mRx;
00250   NS_IF_ADDREF(*aRx);
00251   return NS_OK;
00252 }
00253 
00254 /* readonly attribute nsIDOMSVGAnimatedLength ry; */
00255 NS_IMETHODIMP nsSVGRectElement::GetRy(nsIDOMSVGAnimatedLength * *aRy)
00256 {
00257   *aRy = mRy;
00258   NS_IF_ADDREF(*aRy);
00259   return NS_OK;
00260 }
00261 
00262 //----------------------------------------------------------------------
00263 // nsISVGContent methods
00264 
00265 void nsSVGRectElement::ParentChainChanged()
00266 {
00267   // set new context information on our length-properties:
00268   
00269   nsCOMPtr<nsIDOMSVGSVGElement> dom_elem;
00270   GetOwnerSVGElement(getter_AddRefs(dom_elem));
00271   if (!dom_elem) return;
00272 
00273   nsCOMPtr<nsSVGCoordCtxProvider> ctx = do_QueryInterface(dom_elem);
00274   NS_ASSERTION(ctx, "<svg> element missing interface");
00275 
00276   // x:
00277   {
00278     nsCOMPtr<nsIDOMSVGLength> dom_length;
00279     mX->GetAnimVal(getter_AddRefs(dom_length));
00280     nsCOMPtr<nsISVGLength> length = do_QueryInterface(dom_length);
00281     NS_ASSERTION(length, "svg length missing interface");
00282     
00283     length->SetContext(nsRefPtr<nsSVGCoordCtx>(ctx->GetContextX()));
00284   }
00285 
00286   // y:
00287   {
00288     nsCOMPtr<nsIDOMSVGLength> dom_length;
00289     mY->GetAnimVal(getter_AddRefs(dom_length));
00290     nsCOMPtr<nsISVGLength> length = do_QueryInterface(dom_length);
00291     NS_ASSERTION(length, "svg length missing interface");
00292     
00293     length->SetContext(nsRefPtr<nsSVGCoordCtx>(ctx->GetContextY()));
00294   }
00295 
00296   // width:
00297   {
00298     nsCOMPtr<nsIDOMSVGLength> dom_length;
00299     mWidth->GetAnimVal(getter_AddRefs(dom_length));
00300     nsCOMPtr<nsISVGLength> length = do_QueryInterface(dom_length);
00301     NS_ASSERTION(length, "svg length missing interface");
00302     
00303     length->SetContext(nsRefPtr<nsSVGCoordCtx>(ctx->GetContextX()));
00304   }
00305 
00306   // height:
00307   {
00308     nsCOMPtr<nsIDOMSVGLength> dom_length;
00309     mHeight->GetAnimVal(getter_AddRefs(dom_length));
00310     nsCOMPtr<nsISVGLength> length = do_QueryInterface(dom_length);
00311     NS_ASSERTION(length, "svg length missing interface");
00312     
00313     length->SetContext(nsRefPtr<nsSVGCoordCtx>(ctx->GetContextY()));
00314   }
00315   
00316   // rx:
00317   {
00318     nsCOMPtr<nsIDOMSVGLength> dom_length;
00319     mRx->GetAnimVal(getter_AddRefs(dom_length));
00320     nsCOMPtr<nsISVGLength> length = do_QueryInterface(dom_length);
00321     NS_ASSERTION(length, "svg length missing interface");
00322     
00323     length->SetContext(nsRefPtr<nsSVGCoordCtx>(ctx->GetContextX()));
00324   }
00325 
00326   // ry:
00327   {
00328     nsCOMPtr<nsIDOMSVGLength> dom_length;
00329     mRy->GetAnimVal(getter_AddRefs(dom_length));
00330     nsCOMPtr<nsISVGLength> length = do_QueryInterface(dom_length);
00331     NS_ASSERTION(length, "svg length missing interface");
00332 
00333     length->SetContext(nsRefPtr<nsSVGCoordCtx>(ctx->GetContextY()));
00334   }
00335 
00336   // XXX call baseclass version to recurse into children?
00337 }