Back to index

lightning-sunbird  0.9+nobinonly
nsSVGEllipseElement.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 "nsIDOMSVGEllipseElement.h"
00045 #include "nsCOMPtr.h"
00046 #include "nsISVGSVGElement.h"
00047 #include "nsSVGCoordCtxProvider.h"
00048 
00049 typedef nsSVGGraphicElement nsSVGEllipseElementBase;
00050 
00051 class nsSVGEllipseElement : public nsSVGEllipseElementBase,
00052                             public nsIDOMSVGEllipseElement
00053 {
00054 protected:
00055   friend nsresult NS_NewSVGEllipseElement(nsIContent **aResult,
00056                                          nsINodeInfo *aNodeInfo);
00057   nsSVGEllipseElement(nsINodeInfo *aNodeInfo);
00058   virtual ~nsSVGEllipseElement();
00059   nsresult Init();
00060 
00061 public:
00062   // interfaces:
00063 
00064   NS_DECL_ISUPPORTS_INHERITED
00065   NS_DECL_NSIDOMSVGELLIPSEELEMENT
00066 
00067   // xxx I wish we could use virtual inheritance
00068   NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsSVGEllipseElementBase::)
00069   NS_FORWARD_NSIDOMELEMENT(nsSVGEllipseElementBase::)
00070   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGEllipseElementBase::)
00071 
00072   // nsISVGContent specializations:
00073   virtual void ParentChainChanged();
00074 
00075 protected:
00076 
00077   nsCOMPtr<nsIDOMSVGAnimatedLength> mCx;
00078   nsCOMPtr<nsIDOMSVGAnimatedLength> mCy;
00079   nsCOMPtr<nsIDOMSVGAnimatedLength> mRx;
00080   nsCOMPtr<nsIDOMSVGAnimatedLength> mRy;
00081 
00082 };
00083 
00084 
00085 NS_IMPL_NS_NEW_SVG_ELEMENT(Ellipse)
00086 
00087 
00088 //----------------------------------------------------------------------
00089 // nsISupports methods
00090 
00091 NS_IMPL_ADDREF_INHERITED(nsSVGEllipseElement,nsSVGEllipseElementBase)
00092 NS_IMPL_RELEASE_INHERITED(nsSVGEllipseElement,nsSVGEllipseElementBase)
00093 
00094 NS_INTERFACE_MAP_BEGIN(nsSVGEllipseElement)
00095   NS_INTERFACE_MAP_ENTRY(nsIDOMNode)
00096   NS_INTERFACE_MAP_ENTRY(nsIDOMElement)
00097   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGElement)
00098   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGEllipseElement)
00099   NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(SVGEllipseElement)
00100 NS_INTERFACE_MAP_END_INHERITING(nsSVGEllipseElementBase)
00101 
00102 //----------------------------------------------------------------------
00103 // Implementation
00104 
00105 nsSVGEllipseElement::nsSVGEllipseElement(nsINodeInfo *aNodeInfo)
00106   : nsSVGEllipseElementBase(aNodeInfo)
00107 {
00108 
00109 }
00110 
00111 nsSVGEllipseElement::~nsSVGEllipseElement()
00112 {
00113 }
00114 
00115 
00116 nsresult
00117 nsSVGEllipseElement::Init()
00118 {
00119   nsresult rv = nsSVGEllipseElementBase::Init();
00120   NS_ENSURE_SUCCESS(rv,rv);
00121 
00122   // Create mapped properties:
00123 
00124   // DOM property: cx ,  #IMPLIED attrib: cx
00125   {
00126     nsCOMPtr<nsISVGLength> length;
00127     rv = NS_NewSVGLength(getter_AddRefs(length),
00128                          0.0f);
00129     NS_ENSURE_SUCCESS(rv,rv);
00130     rv = NS_NewSVGAnimatedLength(getter_AddRefs(mCx), length);
00131     NS_ENSURE_SUCCESS(rv,rv);
00132     rv = AddMappedSVGValue(nsSVGAtoms::cx, mCx);
00133     NS_ENSURE_SUCCESS(rv,rv);
00134   }
00135 
00136   // DOM property: cy ,  #IMPLIED attrib: cy
00137   {
00138     nsCOMPtr<nsISVGLength> length;
00139     rv = NS_NewSVGLength(getter_AddRefs(length),
00140                          0.0f);
00141     NS_ENSURE_SUCCESS(rv,rv);
00142     rv = NS_NewSVGAnimatedLength(getter_AddRefs(mCy), length);
00143     NS_ENSURE_SUCCESS(rv,rv);
00144     rv = AddMappedSVGValue(nsSVGAtoms::cy, mCy);
00145     NS_ENSURE_SUCCESS(rv,rv);
00146   }
00147 
00148   // DOM property: rx ,  #REQUIRED  attrib: rx
00149   // XXX: enforce requiredness
00150   {
00151     nsCOMPtr<nsISVGLength> length;
00152     rv = NS_NewSVGLength(getter_AddRefs(length),
00153                          0.0f);
00154     NS_ENSURE_SUCCESS(rv,rv);
00155     rv = NS_NewSVGAnimatedLength(getter_AddRefs(mRx), length);
00156     NS_ENSURE_SUCCESS(rv,rv);
00157     rv = AddMappedSVGValue(nsSVGAtoms::rx, mRx);
00158     NS_ENSURE_SUCCESS(rv,rv);
00159   }
00160 
00161   // DOM property: ry ,  #REQUIRED  attrib: ry
00162   // XXX: enforce requiredness
00163   {
00164     nsCOMPtr<nsISVGLength> length;
00165     rv = NS_NewSVGLength(getter_AddRefs(length),
00166                          0.0f);
00167     NS_ENSURE_SUCCESS(rv,rv);
00168     rv = NS_NewSVGAnimatedLength(getter_AddRefs(mRy), length);
00169     NS_ENSURE_SUCCESS(rv,rv);
00170     rv = AddMappedSVGValue(nsSVGAtoms::ry, mRy);
00171     NS_ENSURE_SUCCESS(rv,rv);
00172   }
00173 
00174   return rv;
00175 }
00176 
00177 //----------------------------------------------------------------------
00178 // nsIDOMNode methods
00179 
00180 
00181 NS_IMPL_DOM_CLONENODE_WITH_INIT(nsSVGEllipseElement)
00182 
00183 
00184 //----------------------------------------------------------------------
00185 // nsIDOMSVGEllipseElement methods
00186 
00187 /* readonly attribute nsIDOMSVGAnimatedLength cx; */
00188 NS_IMETHODIMP nsSVGEllipseElement::GetCx(nsIDOMSVGAnimatedLength * *aCx)
00189 {
00190   *aCx = mCx;
00191   NS_IF_ADDREF(*aCx);
00192   return NS_OK;
00193 }
00194 
00195 /* readonly attribute nsIDOMSVGAnimatedLength cy; */
00196 NS_IMETHODIMP nsSVGEllipseElement::GetCy(nsIDOMSVGAnimatedLength * *aCy)
00197 {
00198   *aCy = mCy;
00199   NS_IF_ADDREF(*aCy);
00200   return NS_OK;
00201 }
00202 
00203 /* readonly attribute nsIDOMSVGAnimatedLength rx; */
00204 NS_IMETHODIMP nsSVGEllipseElement::GetRx(nsIDOMSVGAnimatedLength * *aRx)
00205 {
00206   *aRx = mRx;
00207   NS_IF_ADDREF(*aRx);
00208   return NS_OK;
00209 }
00210 
00211 /* readonly attribute nsIDOMSVGAnimatedLength ry; */
00212 NS_IMETHODIMP nsSVGEllipseElement::GetRy(nsIDOMSVGAnimatedLength * *aRy)
00213 {
00214   *aRy = mRy;
00215   NS_IF_ADDREF(*aRy);
00216   return NS_OK;
00217 }
00218 
00219 //----------------------------------------------------------------------
00220 // nsISVGContent methods
00221 
00222 
00223 void nsSVGEllipseElement::ParentChainChanged()
00224 {
00225   // set new context information on our length-properties:
00226   
00227   nsCOMPtr<nsIDOMSVGSVGElement> dom_elem;
00228   GetOwnerSVGElement(getter_AddRefs(dom_elem));
00229   if (!dom_elem) return;
00230 
00231   nsCOMPtr<nsSVGCoordCtxProvider> ctx = do_QueryInterface(dom_elem);
00232   NS_ASSERTION(ctx, "<svg> element missing interface");
00233 
00234   // cx:
00235   {
00236     nsCOMPtr<nsIDOMSVGLength> dom_length;
00237     mCx->GetAnimVal(getter_AddRefs(dom_length));
00238     nsCOMPtr<nsISVGLength> length = do_QueryInterface(dom_length);
00239     NS_ASSERTION(length, "svg length missing interface");
00240 
00241     length->SetContext(nsRefPtr<nsSVGCoordCtx>(ctx->GetContextX()));
00242   }
00243 
00244   // cy:
00245   {
00246     nsCOMPtr<nsIDOMSVGLength> dom_length;
00247     mCy->GetAnimVal(getter_AddRefs(dom_length));
00248     nsCOMPtr<nsISVGLength> length = do_QueryInterface(dom_length);
00249     NS_ASSERTION(length, "svg length missing interface");
00250 
00251     length->SetContext(nsRefPtr<nsSVGCoordCtx>(ctx->GetContextY()));
00252   }
00253 
00254   // rx:
00255   {
00256     nsCOMPtr<nsIDOMSVGLength> dom_length;
00257     mRx->GetAnimVal(getter_AddRefs(dom_length));
00258     nsCOMPtr<nsISVGLength> length = do_QueryInterface(dom_length);
00259     NS_ASSERTION(length, "svg length missing interface");
00260 
00261     length->SetContext(nsRefPtr<nsSVGCoordCtx>(ctx->GetContextX()));
00262   }
00263   
00264   // rx:
00265   {
00266     nsCOMPtr<nsIDOMSVGLength> dom_length;
00267     mRy->GetAnimVal(getter_AddRefs(dom_length));
00268     nsCOMPtr<nsISVGLength> length = do_QueryInterface(dom_length);
00269     NS_ASSERTION(length, "svg length missing interface");
00270 
00271     length->SetContext(nsRefPtr<nsSVGCoordCtx>(ctx->GetContextY()));
00272   }
00273 
00274   // XXX call baseclass version to recurse into children?
00275 }