Back to index

lightning-sunbird  0.9+nobinonly
nsSVGSymbolElement.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 IBM Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 2004
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either of the GNU General Public License Version 2 or later (the "GPL"),
00025  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00026  * in which case the provisions of the GPL or the LGPL are applicable instead
00027  * of those above. If you wish to allow use of your version of this file only
00028  * under the terms of either the GPL or the LGPL, and not to allow others to
00029  * use your version of this file under the terms of the MPL, indicate your
00030  * decision by deleting the provisions above and replace them with the notice
00031  * and other provisions required by the GPL or the LGPL. If you do not delete
00032  * the provisions above, a recipient may use your version of this file under
00033  * the terms of any one of the MPL, the GPL or the LGPL.
00034  *
00035  * ***** END LICENSE BLOCK ***** */
00036 
00037 #include "nsIDOMSVGSymbolElement.h"
00038 #include "nsSVGStylableElement.h"
00039 #include "nsSVGAnimatedPreserveAspectRatio.h"
00040 #include "nsSVGPreserveAspectRatio.h"
00041 #include "nsIDOMSVGRect.h"
00042 #include "nsIDOMSVGLength.h"
00043 #include "nsIDOMSVGFitToViewBox.h"
00044 #include "nsSVGRect.h"
00045 #include "nsSVGAnimatedRect.h"
00046 #include "nsSVGAtoms.h"
00047 
00048 typedef nsSVGStylableElement nsSVGSymbolElementBase;
00049 
00050 class nsSVGSymbolElement : public nsSVGSymbolElementBase,
00051                            public nsIDOMSVGFitToViewBox,
00052                            public nsIDOMSVGSymbolElement
00053 {
00054 protected:
00055   friend nsresult NS_NewSVGSymbolElement(nsIContent **aResult,
00056                                          nsINodeInfo *aNodeInfo);
00057   nsSVGSymbolElement(nsINodeInfo* aNodeInfo);
00058   virtual ~nsSVGSymbolElement();
00059   nsresult Init();
00060 
00061 public:
00062   // interfaces:
00063 
00064   NS_DECL_ISUPPORTS_INHERITED
00065   NS_DECL_NSIDOMSVGSYMBOLELEMENT
00066   NS_DECL_NSIDOMSVGFITTOVIEWBOX
00067 
00068   // xxx I wish we could use virtual inheritance
00069   NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsSVGElement::)
00070   NS_FORWARD_NSIDOMELEMENT(nsSVGElement::)
00071   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGElement::)
00072 
00073   // nsIContent interface
00074   NS_IMETHODIMP_(PRBool) IsAttributeMapped(const nsIAtom* name) const;
00075 
00076 protected:
00077 
00078   nsCOMPtr<nsIDOMSVGAnimatedRect> mViewBox;
00079   nsCOMPtr<nsIDOMSVGAnimatedPreserveAspectRatio> mPreserveAspectRatio;
00080 };
00081 
00082 NS_IMPL_NS_NEW_SVG_ELEMENT(Symbol)
00083 
00084 //----------------------------------------------------------------------
00085 // nsISupports methods
00086 
00087 NS_IMPL_ADDREF_INHERITED(nsSVGSymbolElement,nsSVGSymbolElementBase)
00088 NS_IMPL_RELEASE_INHERITED(nsSVGSymbolElement,nsSVGSymbolElementBase)
00089 
00090 NS_INTERFACE_MAP_BEGIN(nsSVGSymbolElement)
00091   NS_INTERFACE_MAP_ENTRY(nsIDOMNode)
00092   NS_INTERFACE_MAP_ENTRY(nsIDOMElement)
00093   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGElement)
00094   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGFitToViewBox)
00095   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGSymbolElement)
00096   NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(SVGSymbolElement)
00097 NS_INTERFACE_MAP_END_INHERITING(nsSVGSymbolElementBase)
00098 
00099 //----------------------------------------------------------------------
00100 // Implementation
00101 
00102 nsSVGSymbolElement::nsSVGSymbolElement(nsINodeInfo *aNodeInfo)
00103   : nsSVGSymbolElementBase(aNodeInfo)
00104 {
00105 }
00106 
00107 nsSVGSymbolElement::~nsSVGSymbolElement()
00108 {
00109 }
00110 
00111 nsresult
00112 nsSVGSymbolElement::Init()
00113 {
00114   nsresult rv = nsSVGSymbolElementBase::Init();
00115   NS_ENSURE_SUCCESS(rv,rv);
00116 
00117 
00118   // DOM property: viewBox
00119   {
00120     nsCOMPtr<nsIDOMSVGRect> viewbox;
00121     rv = NS_NewSVGRect(getter_AddRefs(viewbox));
00122     NS_ENSURE_SUCCESS(rv,rv);
00123     rv = NS_NewSVGAnimatedRect(getter_AddRefs(mViewBox), viewbox);
00124     NS_ENSURE_SUCCESS(rv,rv);
00125     rv = AddMappedSVGValue(nsSVGAtoms::viewBox, mViewBox);
00126     NS_ENSURE_SUCCESS(rv,rv);
00127   }
00128 
00129   // DOM property: preserveAspectRatio
00130   {
00131     nsCOMPtr<nsIDOMSVGPreserveAspectRatio> preserveAspectRatio;
00132     rv = NS_NewSVGPreserveAspectRatio(getter_AddRefs(preserveAspectRatio));
00133     NS_ENSURE_SUCCESS(rv,rv);
00134     rv = NS_NewSVGAnimatedPreserveAspectRatio(
00135                                           getter_AddRefs(mPreserveAspectRatio),
00136                                           preserveAspectRatio);
00137     NS_ENSURE_SUCCESS(rv,rv);
00138     rv = AddMappedSVGValue(nsSVGAtoms::preserveAspectRatio,
00139                            mPreserveAspectRatio);
00140     NS_ENSURE_SUCCESS(rv,rv);
00141   }
00142 
00143   return NS_OK;
00144 }
00145 
00146 //----------------------------------------------------------------------
00147 // nsIDOMNode methods
00148 
00149 NS_IMPL_DOM_CLONENODE_WITH_INIT(nsSVGSymbolElement)
00150 
00151 //----------------------------------------------------------------------
00152 // nsIDOMSVGFitToViewBox methods
00153 
00154 /* readonly attribute nsIDOMSVGAnimatedRect viewBox; */
00155 NS_IMETHODIMP nsSVGSymbolElement::GetViewBox(nsIDOMSVGAnimatedRect * *aViewBox)
00156 {
00157   *aViewBox = mViewBox;
00158   NS_ADDREF(*aViewBox);
00159   return NS_OK;
00160 }
00161 
00162 /* readonly attribute nsIDOMSVGAnimatedPreserveAspectRatio preserveAspectRatio; */
00163 NS_IMETHODIMP
00164 nsSVGSymbolElement::GetPreserveAspectRatio(nsIDOMSVGAnimatedPreserveAspectRatio * *aPreserveAspectRatio)
00165 {
00166   *aPreserveAspectRatio = mPreserveAspectRatio;
00167   NS_ADDREF(*aPreserveAspectRatio);
00168   return NS_OK;
00169 }
00170 
00171 //----------------------------------------------------------------------
00172 // nsIContent methods
00173 
00174 NS_IMETHODIMP_(PRBool)
00175 nsSVGSymbolElement::IsAttributeMapped(const nsIAtom* name) const
00176 {
00177   static const MappedAttributeEntry* const map[] = {
00178     sViewportsMap,
00179   };
00180   
00181   return FindAttributeDependence(name, map, NS_ARRAY_LENGTH(map)) ||
00182     nsSVGSymbolElementBase::IsAttributeMapped(name);
00183 }