Back to index

lightning-sunbird  0.9+nobinonly
nsSVGLineElement.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 "nsIDOMSVGLineElement.h"
00045 #include "nsCOMPtr.h"
00046 #include "nsISVGSVGElement.h"
00047 #include "nsSVGCoordCtxProvider.h"
00048 
00049 typedef nsSVGGraphicElement nsSVGLineElementBase;
00050 
00051 class nsSVGLineElement : public nsSVGLineElementBase,
00052                          public nsIDOMSVGLineElement
00053 {
00054 protected:
00055   friend nsresult NS_NewSVGLineElement(nsIContent **aResult,
00056                                          nsINodeInfo *aNodeInfo);
00057   nsSVGLineElement(nsINodeInfo *aNodeInfo);
00058   virtual ~nsSVGLineElement();
00059   nsresult Init();
00060 
00061 public:
00062   // interfaces:
00063 
00064   NS_DECL_ISUPPORTS_INHERITED
00065   NS_DECL_NSIDOMSVGLINEELEMENT
00066 
00067   // xxx I wish we could use virtual inheritance
00068   NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsSVGLineElementBase::)
00069   NS_FORWARD_NSIDOMELEMENT(nsSVGLineElementBase::)
00070   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGLineElementBase::)
00071 
00072   // nsISVGContent specializations:
00073   virtual void ParentChainChanged();
00074 
00075   // nsIStyledContent interface
00076   NS_IMETHODIMP_(PRBool) IsAttributeMapped(const nsIAtom* name) const;
00077 
00078 protected:
00079   
00080   nsCOMPtr<nsIDOMSVGAnimatedLength> mX1;
00081   nsCOMPtr<nsIDOMSVGAnimatedLength> mY1;
00082   nsCOMPtr<nsIDOMSVGAnimatedLength> mX2;
00083   nsCOMPtr<nsIDOMSVGAnimatedLength> mY2;
00084 
00085 };
00086 
00087 
00088 NS_IMPL_NS_NEW_SVG_ELEMENT(Line)
00089 
00090 
00091 //----------------------------------------------------------------------
00092 // nsISupports methods
00093 
00094 NS_IMPL_ADDREF_INHERITED(nsSVGLineElement,nsSVGLineElementBase)
00095 NS_IMPL_RELEASE_INHERITED(nsSVGLineElement,nsSVGLineElementBase)
00096 
00097 NS_INTERFACE_MAP_BEGIN(nsSVGLineElement)
00098   NS_INTERFACE_MAP_ENTRY(nsIDOMNode)
00099   NS_INTERFACE_MAP_ENTRY(nsIDOMElement)
00100   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGElement)
00101   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGLineElement)
00102   NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(SVGLineElement)
00103 NS_INTERFACE_MAP_END_INHERITING(nsSVGLineElementBase)
00104 
00105 //----------------------------------------------------------------------
00106 // Implementation
00107 
00108 nsSVGLineElement::nsSVGLineElement(nsINodeInfo *aNodeInfo)
00109   : nsSVGLineElementBase(aNodeInfo)
00110 {
00111 
00112 }
00113 
00114 nsSVGLineElement::~nsSVGLineElement()
00115 {
00116 }
00117 
00118 
00119 nsresult
00120 nsSVGLineElement::Init()
00121 {
00122   nsresult rv = nsSVGLineElementBase::Init();
00123   NS_ENSURE_SUCCESS(rv,rv);
00124 
00125   // Create mapped properties:
00126 
00127   // DOM property: x1 ,  #IMPLIED attrib: x1
00128   {
00129     nsCOMPtr<nsISVGLength> length;
00130     rv = NS_NewSVGLength(getter_AddRefs(length),
00131                          0.0f);
00132     NS_ENSURE_SUCCESS(rv,rv);
00133     rv = NS_NewSVGAnimatedLength(getter_AddRefs(mX1), length);
00134     NS_ENSURE_SUCCESS(rv,rv);
00135     rv = AddMappedSVGValue(nsSVGAtoms::x1, mX1);
00136     NS_ENSURE_SUCCESS(rv,rv);
00137   }
00138 
00139   // DOM property: y1 ,  #IMPLIED attrib: y1
00140   {
00141     nsCOMPtr<nsISVGLength> length;
00142     rv = NS_NewSVGLength(getter_AddRefs(length),
00143                          0.0f);
00144     NS_ENSURE_SUCCESS(rv,rv);
00145     rv = NS_NewSVGAnimatedLength(getter_AddRefs(mY1), length);
00146     NS_ENSURE_SUCCESS(rv,rv);
00147     rv = AddMappedSVGValue(nsSVGAtoms::y1, mY1);
00148     NS_ENSURE_SUCCESS(rv,rv);
00149   }
00150 
00151   // DOM property: x2 ,  #IMPLIED  attrib: x2
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(mX2), length);
00158     NS_ENSURE_SUCCESS(rv,rv);
00159     rv = AddMappedSVGValue(nsSVGAtoms::x2, mX2);
00160     NS_ENSURE_SUCCESS(rv,rv);
00161   }
00162 
00163   // DOM property: y2 ,  #IMPLIED  attrib: y2
00164   {
00165     nsCOMPtr<nsISVGLength> length;
00166     rv = NS_NewSVGLength(getter_AddRefs(length),
00167                          0.0f);
00168     NS_ENSURE_SUCCESS(rv,rv);
00169     rv = NS_NewSVGAnimatedLength(getter_AddRefs(mY2), length);
00170     NS_ENSURE_SUCCESS(rv,rv);
00171     rv = AddMappedSVGValue(nsSVGAtoms::y2, mY2);
00172     NS_ENSURE_SUCCESS(rv,rv);
00173   }
00174 
00175   return rv;
00176 }
00177 
00178 //----------------------------------------------------------------------
00179 // nsIDOMNode methods
00180 
00181 
00182 NS_IMPL_DOM_CLONENODE_WITH_INIT(nsSVGLineElement)
00183 
00184 
00185 //----------------------------------------------------------------------
00186 // nsIDOMSVGLineElement methods
00187 
00188 /* readonly attribute nsIDOMSVGAnimatedLength cx; */
00189 NS_IMETHODIMP nsSVGLineElement::GetX1(nsIDOMSVGAnimatedLength * *aX1)
00190 {
00191   *aX1 = mX1;
00192   NS_IF_ADDREF(*aX1);
00193   return NS_OK;
00194 }
00195 
00196 /* readonly attribute nsIDOMSVGAnimatedLength cy; */
00197 NS_IMETHODIMP nsSVGLineElement::GetY1(nsIDOMSVGAnimatedLength * *aY1)
00198 {
00199   *aY1 = mY1;
00200   NS_IF_ADDREF(*aY1);
00201   return NS_OK;
00202 }
00203 
00204 /* readonly attribute nsIDOMSVGAnimatedLength rx; */
00205 NS_IMETHODIMP nsSVGLineElement::GetX2(nsIDOMSVGAnimatedLength * *aX2)
00206 {
00207   *aX2 = mX2;
00208   NS_IF_ADDREF(*aX2);
00209   return NS_OK;
00210 }
00211 
00212 /* readonly attribute nsIDOMSVGAnimatedLength ry; */
00213 NS_IMETHODIMP nsSVGLineElement::GetY2(nsIDOMSVGAnimatedLength * *aY2)
00214 {
00215   *aY2 = mY2;
00216   NS_IF_ADDREF(*aY2);
00217   return NS_OK;
00218 }
00219 
00220 //----------------------------------------------------------------------
00221 // nsISVGContent methods
00222 
00223 void nsSVGLineElement::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   // x1:
00235   {
00236     nsCOMPtr<nsIDOMSVGLength> dom_length;
00237     mX1->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   // y1:
00245   {
00246     nsCOMPtr<nsIDOMSVGLength> dom_length;
00247     mY1->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   // x2:
00255   {
00256     nsCOMPtr<nsIDOMSVGLength> dom_length;
00257     mX2->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   // y2:
00265   {
00266     nsCOMPtr<nsIDOMSVGLength> dom_length;
00267     mY2->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 }  
00276 
00277 //----------------------------------------------------------------------
00278 // nsIStyledContent methods
00279 
00280 NS_IMETHODIMP_(PRBool)
00281 nsSVGLineElement::IsAttributeMapped(const nsIAtom* name) const
00282 {
00283   static const MappedAttributeEntry* const map[] = {
00284     sMarkersMap,
00285   };
00286   
00287   return FindAttributeDependence(name, map, NS_ARRAY_LENGTH(map)) ||
00288     nsSVGLineElementBase::IsAttributeMapped(name);
00289 }