Back to index

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