Back to index

lightning-sunbird  0.9+nobinonly
nsSVGStopElement.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  * Scooter Morris.
00019  * Portions created by the Initial Developer are Copyright (C) 2004
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Scooter Morris <scootermorris@comcast.net>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * 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 "nsSVGStylableElement.h"
00040 #include "nsSVGAtoms.h"
00041 #include "nsIDOMSVGStopElement.h"
00042 #include "nsCOMPtr.h"
00043 #include "nsSVGAnimatedNumberList.h"
00044 #include "nsISVGSVGElement.h"
00045 #include "nsSVGNumber.h"
00046 #include "nsSVGAnimatedNumber.h"
00047 
00048 typedef nsSVGStylableElement nsSVGStopElementBase;
00049 
00050 class nsSVGStopElement : public nsSVGStopElementBase,
00051                          public nsIDOMSVGStopElement
00052 {
00053 protected:
00054   friend nsresult NS_NewSVGStopElement(nsIContent **aResult,
00055                                        nsINodeInfo *aNodeInfo);
00056   nsSVGStopElement(nsINodeInfo* aNodeInfo);
00057   virtual ~nsSVGStopElement();
00058   nsresult Init();
00059   
00060 public:
00061   // interfaces:
00062   
00063   NS_DECL_ISUPPORTS_INHERITED
00064   NS_DECL_NSIDOMSVGSTOPELEMENT
00065 
00066   // xxx If xpcom allowed virtual inheritance we wouldn't need to
00067   // forward here :-(
00068   NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsSVGStopElementBase::)
00069   NS_FORWARD_NSIDOMELEMENT(nsSVGStopElementBase::)
00070   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGStopElementBase::)
00071 
00072   // nsIStyledContent interface
00073   NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const;
00074 
00075 protected:
00076 
00077   // nsIDOMSVGStopElement properties:
00078   nsCOMPtr<nsIDOMSVGAnimatedNumber> mOffset;
00079 };
00080 
00081 NS_IMPL_NS_NEW_SVG_ELEMENT(Stop)
00082 
00083 //----------------------------------------------------------------------
00084 // nsISupports methods
00085 
00086 NS_IMPL_ADDREF_INHERITED(nsSVGStopElement,nsSVGStopElementBase)
00087 NS_IMPL_RELEASE_INHERITED(nsSVGStopElement,nsSVGStopElementBase)
00088 
00089 NS_INTERFACE_MAP_BEGIN(nsSVGStopElement)
00090   NS_INTERFACE_MAP_ENTRY(nsIDOMNode)
00091   NS_INTERFACE_MAP_ENTRY(nsIDOMElement)
00092   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGElement)
00093   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGStopElement)
00094   NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(SVGStopElement)
00095 NS_INTERFACE_MAP_END_INHERITING(nsSVGStopElementBase)
00096 
00097 //----------------------------------------------------------------------
00098 // Implementation
00099 
00100 nsSVGStopElement::nsSVGStopElement(nsINodeInfo* aNodeInfo)
00101   : nsSVGStopElementBase(aNodeInfo)
00102 {
00103 
00104 }
00105 
00106 nsSVGStopElement::~nsSVGStopElement()
00107 {
00108 }
00109 
00110   
00111 nsresult
00112 nsSVGStopElement::Init()
00113 {
00114   nsresult rv = nsSVGStopElementBase::Init();
00115   NS_ENSURE_SUCCESS(rv,rv);
00116 
00117   // Create mapped properties:
00118 
00119   // DOM property: nsIDOMSVGStopElement::offset, #IMPLIED attrib: offset
00120   {
00121     rv = NS_NewSVGAnimatedNumber(getter_AddRefs(mOffset),
00122                                  0.0);
00123     NS_ENSURE_SUCCESS(rv,rv);
00124     rv = AddMappedSVGValue(nsSVGAtoms::offset, mOffset);
00125     NS_ENSURE_SUCCESS(rv,rv);
00126   }
00127   return NS_OK;
00128 }
00129 
00130 //----------------------------------------------------------------------
00131 // nsIDOMNode methods
00132 
00133 NS_IMPL_DOM_CLONENODE_WITH_INIT(nsSVGStopElement)
00134 
00135 //----------------------------------------------------------------------
00136 // nsIDOMSVGStopElement methods
00137 
00138 /* readonly attribute nsIDOMSVGAnimatedLengthList x; */
00139 NS_IMETHODIMP nsSVGStopElement::GetOffset(nsIDOMSVGAnimatedNumber * *aOffset)
00140 {
00141   *aOffset = mOffset;
00142   NS_IF_ADDREF(*aOffset);
00143   return NS_OK;
00144 }
00145 
00146 //----------------------------------------------------------------------
00147 // nsIStyledContent methods
00148 
00149 NS_IMETHODIMP_(PRBool)
00150 nsSVGStopElement::IsAttributeMapped(const nsIAtom* name) const
00151 {
00152   static const MappedAttributeEntry* const map[] = {
00153     sGradientStopMap
00154   };
00155   
00156   return FindAttributeDependence(name, map, NS_ARRAY_LENGTH(map)) ||
00157     nsSVGStopElementBase::IsAttributeMapped(name);
00158 }
00159 
00160