Back to index

lightning-sunbird  0.9+nobinonly
nsSVGPolylineElement.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 "nsSVGPointList.h"
00042 #include "nsIDOMSVGPolylineElement.h"
00043 #include "nsIDOMSVGAnimatedPoints.h"
00044 #include "nsCOMPtr.h"
00045 
00046 typedef nsSVGGraphicElement nsSVGPolylineElementBase;
00047 
00048 class nsSVGPolylineElement : public nsSVGPolylineElementBase,
00049                              public nsIDOMSVGPolylineElement,
00050                              public nsIDOMSVGAnimatedPoints
00051 {
00052 protected:
00053   friend nsresult NS_NewSVGPolylineElement(nsIContent **aResult,
00054                                            nsINodeInfo *aNodeInfo);
00055   nsSVGPolylineElement(nsINodeInfo* aNodeInfo);
00056   virtual ~nsSVGPolylineElement();
00057   nsresult Init();
00058   
00059 public:
00060   // interfaces:
00061   
00062   NS_DECL_ISUPPORTS_INHERITED
00063   NS_DECL_NSIDOMSVGPOLYLINEELEMENT
00064   NS_DECL_NSIDOMSVGANIMATEDPOINTS
00065 
00066   // xxx I wish we could use virtual inheritance
00067   NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsSVGPolylineElementBase::)
00068   NS_FORWARD_NSIDOMELEMENT(nsSVGPolylineElementBase::)
00069   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGPolylineElementBase::)
00070 
00071   // nsIStyledContent interface
00072   NS_IMETHODIMP_(PRBool) IsAttributeMapped(const nsIAtom* name) const;
00073   
00074 protected:
00075   nsCOMPtr<nsIDOMSVGPointList> mPoints;
00076 };
00077 
00078 
00079 NS_IMPL_NS_NEW_SVG_ELEMENT(Polyline)
00080 
00081 
00082 //----------------------------------------------------------------------
00083 // nsISupports methods
00084 
00085 NS_IMPL_ADDREF_INHERITED(nsSVGPolylineElement,nsSVGPolylineElementBase)
00086 NS_IMPL_RELEASE_INHERITED(nsSVGPolylineElement,nsSVGPolylineElementBase)
00087 
00088 NS_INTERFACE_MAP_BEGIN(nsSVGPolylineElement)
00089   NS_INTERFACE_MAP_ENTRY(nsIDOMNode)
00090   NS_INTERFACE_MAP_ENTRY(nsIDOMElement)
00091   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGElement)
00092   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGPolylineElement)
00093   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGAnimatedPoints)
00094   NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(SVGPolylineElement)
00095 NS_INTERFACE_MAP_END_INHERITING(nsSVGPolylineElementBase)
00096 
00097 //----------------------------------------------------------------------
00098 // Implementation
00099 
00100 nsSVGPolylineElement::nsSVGPolylineElement(nsINodeInfo* aNodeInfo)
00101   : nsSVGPolylineElementBase(aNodeInfo)
00102 {
00103 
00104 }
00105 
00106 nsSVGPolylineElement::~nsSVGPolylineElement()
00107 {
00108 }
00109 
00110   
00111 nsresult
00112 nsSVGPolylineElement::Init()
00113 {
00114   nsresult rv = nsSVGPolylineElementBase::Init();
00115   NS_ENSURE_SUCCESS(rv,rv);
00116 
00117   // Create mapped properties:
00118   
00119   // points #IMPLIED
00120   rv = nsSVGPointList::Create(getter_AddRefs(mPoints));
00121   NS_ENSURE_SUCCESS(rv,rv);
00122   rv = AddMappedSVGValue(nsSVGAtoms::points, mPoints);
00123   NS_ENSURE_SUCCESS(rv,rv);
00124 
00125   return rv;
00126 }
00127 
00128 //----------------------------------------------------------------------
00129 // nsIDOMNode methods
00130 
00131 
00132 NS_IMPL_DOM_CLONENODE_WITH_INIT(nsSVGPolylineElement)
00133 
00134 
00135 //----------------------------------------------------------------------
00136 // nsIDOMSGAnimatedPoints methods:
00137 
00138 /* readonly attribute nsIDOMSVGPointList points; */
00139 NS_IMETHODIMP nsSVGPolylineElement::GetPoints(nsIDOMSVGPointList * *aPoints)
00140 {
00141   *aPoints = mPoints;
00142   NS_ADDREF(*aPoints);
00143   return NS_OK;
00144 }
00145 
00146 /* readonly attribute nsIDOMSVGPointList animatedPoints; */
00147 NS_IMETHODIMP nsSVGPolylineElement::GetAnimatedPoints(nsIDOMSVGPointList * *aAnimatedPoints)
00148 {
00149   *aAnimatedPoints = mPoints;
00150   NS_ADDREF(*aAnimatedPoints);
00151   return NS_OK;
00152 }
00153 
00154 //----------------------------------------------------------------------
00155 // nsIStyledContent methods
00156 
00157 NS_IMETHODIMP_(PRBool)
00158 nsSVGPolylineElement::IsAttributeMapped(const nsIAtom* name) const
00159 {
00160   static const MappedAttributeEntry* const map[] = {
00161     sMarkersMap,
00162   };
00163   
00164   return FindAttributeDependence(name, map, NS_ARRAY_LENGTH(map)) ||
00165     nsSVGPolylineElementBase::IsAttributeMapped(name);
00166 }