Back to index

lightning-sunbird  0.9+nobinonly
nsSVGElementFactory.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 "nsCOMPtr.h"
00040 #include "nsContentCreatorFunctions.h"
00041 #include "nsIAtom.h"
00042 #include "nsINodeInfo.h"
00043 #include "nsSVGAtoms.h"
00044 #include "nsContentDLF.h"
00045 #include "nsContentUtils.h"
00046 #include "nsSVGUtils.h"
00047 #include "nsDebug.h"
00048 
00049 nsresult
00050 NS_NewSVGPolylineElement(nsIContent **aResult, nsINodeInfo *aNodeInfo);
00051 nsresult
00052 NS_NewSVGPolygonElement(nsIContent **aResult, nsINodeInfo *aNodeInfo);
00053 nsresult
00054 NS_NewSVGCircleElement(nsIContent **aResult, nsINodeInfo *aNodeInfo);
00055 nsresult
00056 NS_NewSVGEllipseElement(nsIContent **aResult, nsINodeInfo *aNodeInfo);
00057 nsresult
00058 NS_NewSVGLineElement(nsIContent **aResult, nsINodeInfo *aNodeInfo);
00059 nsresult
00060 NS_NewSVGRectElement(nsIContent **aResult, nsINodeInfo *aNodeInfo);
00061 nsresult
00062 NS_NewSVGGElement(nsIContent **aResult, nsINodeInfo *aNodeInfo);
00063 nsresult
00064 NS_NewSVGSVGElement(nsIContent **aResult, nsINodeInfo *aNodeInfo);
00065 #ifdef MOZ_SVG_FOREIGNOBJECT
00066 nsresult
00067 NS_NewSVGForeignObjectElement(nsIContent **aResult, nsINodeInfo *aNodeInfo);
00068 #endif
00069 nsresult
00070 NS_NewSVGPathElement(nsIContent **aResult, nsINodeInfo *aNodeInfo);
00071 nsresult
00072 NS_NewSVGTextElement(nsIContent **aResult, nsINodeInfo *aNodeInfo);
00073 nsresult
00074 NS_NewSVGTSpanElement(nsIContent **aResult, nsINodeInfo *aNodeInfo);
00075 nsresult
00076 NS_NewSVGImageElement(nsIContent **aResult, nsINodeInfo *aNodeInfo);
00077 nsresult
00078 NS_NewSVGStyleElement(nsIContent **aResult, nsINodeInfo *aNodeInfo);
00079 nsresult
00080 NS_NewSVGLinearGradientElement(nsIContent **aResult, nsINodeInfo *aNodeInfo);
00081 nsresult
00082 NS_NewSVGMetadataElement(nsIContent **aResult, nsINodeInfo *aNodeInfo);
00083 nsresult
00084 NS_NewSVGRadialGradientElement(nsIContent **aResult, nsINodeInfo *aNodeInfo);
00085 nsresult
00086 NS_NewSVGStopElement(nsIContent **aResult, nsINodeInfo *aNodeInfo);
00087 nsresult
00088 NS_NewSVGDefsElement(nsIContent **aResult, nsINodeInfo *aNodeInfo);
00089 nsresult
00090 NS_NewSVGDescElement(nsIContent **aResult, nsINodeInfo *aNodeInfo);
00091 nsresult
00092 NS_NewSVGScriptElement(nsIContent **aResult, nsINodeInfo *aNodeInfo);
00093 nsresult
00094 NS_NewSVGUseElement(nsIContent **aResult, nsINodeInfo *aNodeInfo);
00095 nsresult
00096 NS_NewSVGSymbolElement(nsIContent **aResult, nsINodeInfo *aNodeInfo);
00097 nsresult
00098 NS_NewSVGMarkerElement(nsIContent **aResult, nsINodeInfo *aNodeInfo);
00099 nsresult
00100 NS_NewSVGTitleElement(nsIContent **aResult, nsINodeInfo *aNodeInfo);
00101 nsresult
00102 NS_NewSVGClipPathElement(nsIContent **aResult, nsINodeInfo *aNodeInfo);
00103 nsresult
00104 NS_NewSVGTextPathElement(nsIContent **aResult, nsINodeInfo *aNodeInfo);
00105 
00106 
00107 nsresult
00108 NS_NewSVGElement(nsIContent** aResult, nsINodeInfo *aNodeInfo)
00109 {
00110   NS_PRECONDITION(nsSVGUtils::SVGEnabled(),
00111                   "creating an SVG element while SVG disabled");
00112 
00113   static const char kSVGStyleSheetURI[] = "resource://gre/res/svg.css";
00114 
00115   // this bit of code is to load svg.css on demand
00116   nsIDocument* doc = nsContentUtils::GetDocument(aNodeInfo);
00117   if (doc)
00118     doc->EnsureCatalogStyleSheet(kSVGStyleSheetURI);
00119 
00120   nsIAtom *name = aNodeInfo->NameAtom();
00121   
00122   if (name == nsSVGAtoms::polyline)
00123     return NS_NewSVGPolylineElement(aResult, aNodeInfo);
00124   if (name == nsSVGAtoms::polygon)
00125     return NS_NewSVGPolygonElement(aResult, aNodeInfo);
00126   if (name == nsSVGAtoms::circle)
00127     return NS_NewSVGCircleElement(aResult, aNodeInfo);
00128   if (name == nsSVGAtoms::ellipse)
00129     return NS_NewSVGEllipseElement(aResult, aNodeInfo);
00130   if (name == nsSVGAtoms::line)
00131     return NS_NewSVGLineElement(aResult, aNodeInfo);
00132   if (name == nsSVGAtoms::rect)
00133     return NS_NewSVGRectElement(aResult, aNodeInfo);
00134   if (name == nsSVGAtoms::svg)
00135     return NS_NewSVGSVGElement(aResult, aNodeInfo);
00136   if (name == nsSVGAtoms::g)
00137     return NS_NewSVGGElement(aResult, aNodeInfo);
00138 #ifdef MOZ_SVG_FOREIGNOBJECT
00139   if (name == nsSVGAtoms::foreignObject)
00140     return NS_NewSVGForeignObjectElement(aResult, aNodeInfo);
00141 #endif
00142   if (name == nsSVGAtoms::path)
00143     return NS_NewSVGPathElement(aResult, aNodeInfo);
00144   if (name == nsSVGAtoms::text)
00145     return NS_NewSVGTextElement(aResult, aNodeInfo);
00146   if (name == nsSVGAtoms::tspan)
00147     return NS_NewSVGTSpanElement(aResult, aNodeInfo);
00148   if (name == nsSVGAtoms::image)
00149     return NS_NewSVGImageElement(aResult, aNodeInfo);
00150   if (name == nsSVGAtoms::style)
00151     return NS_NewSVGStyleElement(aResult, aNodeInfo);
00152   if (name == nsSVGAtoms::linearGradient)
00153     return NS_NewSVGLinearGradientElement(aResult, aNodeInfo);
00154   if (name == nsSVGAtoms::metadata)
00155     return NS_NewSVGMetadataElement(aResult, aNodeInfo);
00156   if (name == nsSVGAtoms::radialGradient)
00157     return NS_NewSVGRadialGradientElement(aResult, aNodeInfo);
00158   if (name == nsSVGAtoms::stop)
00159     return NS_NewSVGStopElement(aResult, aNodeInfo);
00160   if (name == nsSVGAtoms::defs)
00161     return NS_NewSVGDefsElement(aResult, aNodeInfo);
00162   if (name == nsSVGAtoms::desc)
00163     return NS_NewSVGDescElement(aResult, aNodeInfo);
00164   if (name == nsSVGAtoms::script)
00165     return NS_NewSVGScriptElement(aResult, aNodeInfo);
00166   if (name == nsSVGAtoms::use)
00167     return NS_NewSVGUseElement(aResult, aNodeInfo);
00168   if (name == nsSVGAtoms::symbol)
00169     return NS_NewSVGSymbolElement(aResult, aNodeInfo);
00170   if (name == nsSVGAtoms::marker)
00171     return NS_NewSVGMarkerElement(aResult, aNodeInfo);
00172   if (name == nsSVGAtoms::title)
00173     return NS_NewSVGTitleElement(aResult, aNodeInfo);
00174   if (name == nsSVGAtoms::clipPath)
00175     return NS_NewSVGClipPathElement(aResult, aNodeInfo);
00176   if (name == nsSVGAtoms::textPath)
00177     return NS_NewSVGTextPathElement(aResult, aNodeInfo);
00178 
00179   // if we don't know what to create, just create a standard xml element:
00180   return NS_NewXMLElement(aResult, aNodeInfo);
00181 }
00182