1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is the Mozilla SVG project.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Crocodile Clips Ltd..
19 : * Portions created by the Initial Developer are Copyright (C) 2001
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Alex Fritze <alex.fritze@crocodile-clips.com> (original author)
24 : * Chris Double <chris.double@double.co.nz>
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either of the GNU General Public License Version 2 or later (the "GPL"),
28 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 : * in which case the provisions of the GPL or the LGPL are applicable instead
30 : * of those above. If you wish to allow use of your version of this file only
31 : * under the terms of either the GPL or the LGPL, and not to allow others to
32 : * use your version of this file under the terms of the MPL, indicate your
33 : * decision by deleting the provisions above and replace them with the notice
34 : * and other provisions required by the GPL or the LGPL. If you do not delete
35 : * the provisions above, a recipient may use your version of this file under
36 : * the terms of any one of the MPL, the GPL or the LGPL.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : #include "nsCOMPtr.h"
41 : #include "nsContentCreatorFunctions.h"
42 : #include "nsIAtom.h"
43 : #include "nsINodeInfo.h"
44 : #include "nsGkAtoms.h"
45 : #include "nsContentDLF.h"
46 : #include "nsContentUtils.h"
47 : #include "nsSVGUtils.h"
48 : #include "nsDebug.h"
49 :
50 : using namespace mozilla::dom;
51 :
52 : nsresult
53 : NS_NewSVGAElement(nsIContent **aResult,
54 : already_AddRefed<nsINodeInfo> aNodeInfo);
55 : nsresult
56 : NS_NewSVGAltGlyphElement(nsIContent **aResult,
57 : already_AddRefed<nsINodeInfo> aNodeInfo);
58 : nsresult
59 : NS_NewSVGPolylineElement(nsIContent **aResult,
60 : already_AddRefed<nsINodeInfo> aNodeInfo);
61 : nsresult
62 : NS_NewSVGPolygonElement(nsIContent **aResult,
63 : already_AddRefed<nsINodeInfo> aNodeInfo);
64 : nsresult
65 : NS_NewSVGCircleElement(nsIContent **aResult,
66 : already_AddRefed<nsINodeInfo> aNodeInfo);
67 : nsresult
68 : NS_NewSVGEllipseElement(nsIContent **aResult,
69 : already_AddRefed<nsINodeInfo> aNodeInfo);
70 : nsresult
71 : NS_NewSVGLineElement(nsIContent **aResult,
72 : already_AddRefed<nsINodeInfo> aNodeInfo);
73 : nsresult
74 : NS_NewSVGRectElement(nsIContent **aResult,
75 : already_AddRefed<nsINodeInfo> aNodeInfo);
76 : nsresult
77 : NS_NewSVGGElement(nsIContent **aResult,
78 : already_AddRefed<nsINodeInfo> aNodeInfo);
79 : nsresult
80 : NS_NewSVGSVGElement(nsIContent **aResult,
81 : already_AddRefed<nsINodeInfo> aNodeInfo,
82 : FromParser aFromParser);
83 : nsresult
84 : NS_NewSVGForeignObjectElement(nsIContent **aResult,
85 : already_AddRefed<nsINodeInfo> aNodeInfo);
86 : nsresult
87 : NS_NewSVGPathElement(nsIContent **aResult,
88 : already_AddRefed<nsINodeInfo> aNodeInfo);
89 : nsresult
90 : NS_NewSVGTextElement(nsIContent **aResult,
91 : already_AddRefed<nsINodeInfo> aNodeInfo);
92 : nsresult
93 : NS_NewSVGTSpanElement(nsIContent **aResult,
94 : already_AddRefed<nsINodeInfo> aNodeInfo);
95 : nsresult
96 : NS_NewSVGImageElement(nsIContent **aResult,
97 : already_AddRefed<nsINodeInfo> aNodeInfo);
98 : nsresult
99 : NS_NewSVGStyleElement(nsIContent **aResult,
100 : already_AddRefed<nsINodeInfo> aNodeInfo);
101 : nsresult
102 : NS_NewSVGLinearGradientElement(nsIContent **aResult,
103 : already_AddRefed<nsINodeInfo> aNodeInfo);
104 : nsresult
105 : NS_NewSVGMetadataElement(nsIContent **aResult,
106 : already_AddRefed<nsINodeInfo> aNodeInfo);
107 : nsresult
108 : NS_NewSVGRadialGradientElement(nsIContent **aResult,
109 : already_AddRefed<nsINodeInfo> aNodeInfo);
110 : nsresult
111 : NS_NewSVGStopElement(nsIContent **aResult,
112 : already_AddRefed<nsINodeInfo> aNodeInfo);
113 : nsresult
114 : NS_NewSVGDefsElement(nsIContent **aResult,
115 : already_AddRefed<nsINodeInfo> aNodeInfo);
116 : nsresult
117 : NS_NewSVGDescElement(nsIContent **aResult,
118 : already_AddRefed<nsINodeInfo> aNodeInfo);
119 : nsresult
120 : NS_NewSVGScriptElement(nsIContent **aResult,
121 : already_AddRefed<nsINodeInfo> aNodeInfo,
122 : FromParser aFromParser);
123 : nsresult
124 : NS_NewSVGUseElement(nsIContent **aResult,
125 : already_AddRefed<nsINodeInfo> aNodeInfo);
126 : nsresult
127 : NS_NewSVGSymbolElement(nsIContent **aResult,
128 : already_AddRefed<nsINodeInfo> aNodeInfo);
129 : nsresult
130 : NS_NewSVGMarkerElement(nsIContent **aResult,
131 : already_AddRefed<nsINodeInfo> aNodeInfo);
132 : nsresult
133 : NS_NewSVGTitleElement(nsIContent **aResult,
134 : already_AddRefed<nsINodeInfo> aNodeInfo);
135 : nsresult
136 : NS_NewSVGClipPathElement(nsIContent **aResult,
137 : already_AddRefed<nsINodeInfo> aNodeInfo);
138 : nsresult
139 : NS_NewSVGTextPathElement(nsIContent **aResult,
140 : already_AddRefed<nsINodeInfo> aNodeInfo);
141 : nsresult
142 : NS_NewSVGFilterElement(nsIContent **aResult,
143 : already_AddRefed<nsINodeInfo> aNodeInfo);
144 : nsresult
145 : NS_NewSVGFEBlendElement(nsIContent **aResult,
146 : already_AddRefed<nsINodeInfo> aNodeInfo);
147 : nsresult
148 : NS_NewSVGFEColorMatrixElement(nsIContent **aResult,
149 : already_AddRefed<nsINodeInfo> aNodeInfo);
150 : nsresult
151 : NS_NewSVGFEComponentTransferElement(nsIContent **aResult,
152 : already_AddRefed<nsINodeInfo> aNodeInfo);
153 : nsresult
154 : NS_NewSVGFECompositeElement(nsIContent **aResult,
155 : already_AddRefed<nsINodeInfo> aNodeInfo);
156 : nsresult
157 : NS_NewSVGFEFuncRElement(nsIContent **aResult,
158 : already_AddRefed<nsINodeInfo> aNodeInfo);
159 : nsresult
160 : NS_NewSVGFEFuncGElement(nsIContent **aResult,
161 : already_AddRefed<nsINodeInfo> aNodeInfo);
162 : nsresult
163 : NS_NewSVGFEFuncBElement(nsIContent **aResult,
164 : already_AddRefed<nsINodeInfo> aNodeInfo);
165 : nsresult
166 : NS_NewSVGFEFuncAElement(nsIContent **aResult,
167 : already_AddRefed<nsINodeInfo> aNodeInfo);
168 : nsresult
169 : NS_NewSVGFEGaussianBlurElement(nsIContent **aResult,
170 : already_AddRefed<nsINodeInfo> aNodeInfo);
171 : nsresult
172 : NS_NewSVGFEMergeElement(nsIContent **aResult,
173 : already_AddRefed<nsINodeInfo> aNodeInfo);
174 : nsresult
175 : NS_NewSVGFEMergeNodeElement(nsIContent **aResult,
176 : already_AddRefed<nsINodeInfo> aNodeInfo);
177 : nsresult
178 : NS_NewSVGFEMorphologyElement(nsIContent **aResult,
179 : already_AddRefed<nsINodeInfo> aNodeInfo);
180 : nsresult
181 : NS_NewSVGFEOffsetElement(nsIContent **aResult,
182 : already_AddRefed<nsINodeInfo> aNodeInfo);
183 : nsresult
184 : NS_NewSVGPatternElement(nsIContent **aResult,
185 : already_AddRefed<nsINodeInfo> aNodeInfo);
186 : nsresult
187 : NS_NewSVGMaskElement(nsIContent **aResult,
188 : already_AddRefed<nsINodeInfo> aNodeInfo);
189 : nsresult
190 : NS_NewSVGFEFloodElement(nsIContent **aResult,
191 : already_AddRefed<nsINodeInfo> aNodeInfo);
192 : nsresult
193 : NS_NewSVGFETileElement(nsIContent **aResult,
194 : already_AddRefed<nsINodeInfo> aNodeInfo);
195 : nsresult
196 : NS_NewSVGFETurbulenceElement(nsIContent **aResult,
197 : already_AddRefed<nsINodeInfo> aNodeInfo);
198 : nsresult
199 : NS_NewSVGSwitchElement(nsIContent **aResult,
200 : already_AddRefed<nsINodeInfo> aNodeInfo);
201 : nsresult
202 : NS_NewSVGFEConvolveMatrixElement(nsIContent **aResult,
203 : already_AddRefed<nsINodeInfo> aNodeInfo);
204 : nsresult
205 : NS_NewSVGFEDistantLightElement(nsIContent **aResult,
206 : already_AddRefed<nsINodeInfo> aNodeInfo);
207 : nsresult
208 : NS_NewSVGFEPointLightElement(nsIContent **aResult,
209 : already_AddRefed<nsINodeInfo> aNodeInfo);
210 : nsresult
211 : NS_NewSVGFESpotLightElement(nsIContent **aResult,
212 : already_AddRefed<nsINodeInfo> aNodeInfo);
213 : nsresult
214 : NS_NewSVGFEDiffuseLightingElement(nsIContent **aResult,
215 : already_AddRefed<nsINodeInfo> aNodeInfo);
216 : nsresult
217 : NS_NewSVGFESpecularLightingElement(nsIContent **aResult,
218 : already_AddRefed<nsINodeInfo> aNodeInfo);
219 : nsresult
220 : NS_NewSVGFEImageElement(nsIContent **aResult,
221 : already_AddRefed<nsINodeInfo> aNodeInfo);
222 : nsresult
223 : NS_NewSVGFEDisplacementMapElement(nsIContent **aResult,
224 : already_AddRefed<nsINodeInfo> aNodeInfo);
225 :
226 : nsresult
227 : NS_NewSVGAnimateElement(nsIContent **aResult,
228 : already_AddRefed<nsINodeInfo> aNodeInfo);
229 : nsresult
230 : NS_NewSVGAnimateTransformElement(nsIContent **aResult,
231 : already_AddRefed<nsINodeInfo> aNodeInfo);
232 : nsresult
233 : NS_NewSVGAnimateMotionElement(nsIContent **aResult,
234 : already_AddRefed<nsINodeInfo> aNodeInfo);
235 : nsresult
236 : NS_NewSVGMpathElement(nsIContent **aResult,
237 : already_AddRefed<nsINodeInfo> aNodeInfo);
238 : nsresult
239 : NS_NewSVGSetElement(nsIContent **aResult,
240 : already_AddRefed<nsINodeInfo> aNodeInfo);
241 :
242 : nsresult
243 : NS_NewSVGUnknownElement(nsIContent **aResult,
244 : already_AddRefed<nsINodeInfo> aNodeInfo);
245 :
246 : nsresult
247 0 : NS_NewSVGElement(nsIContent** aResult, already_AddRefed<nsINodeInfo> aNodeInfo,
248 : FromParser aFromParser)
249 : {
250 : static const char kSVGStyleSheetURI[] = "resource://gre/res/svg.css";
251 :
252 : // this bit of code is to load svg.css on demand
253 0 : nsIDocument *doc = aNodeInfo.get()->GetDocument();
254 0 : if (doc)
255 0 : doc->EnsureCatalogStyleSheet(kSVGStyleSheetURI);
256 :
257 0 : nsIAtom *name = aNodeInfo.get()->NameAtom();
258 :
259 0 : if (name == nsGkAtoms::a)
260 0 : return NS_NewSVGAElement(aResult, aNodeInfo);
261 0 : if (name == nsGkAtoms::altGlyph)
262 0 : return NS_NewSVGAltGlyphElement(aResult, aNodeInfo);
263 0 : if (name == nsGkAtoms::polyline)
264 0 : return NS_NewSVGPolylineElement(aResult, aNodeInfo);
265 0 : if (name == nsGkAtoms::polygon)
266 0 : return NS_NewSVGPolygonElement(aResult, aNodeInfo);
267 0 : if (name == nsGkAtoms::circle)
268 0 : return NS_NewSVGCircleElement(aResult, aNodeInfo);
269 0 : if (name == nsGkAtoms::ellipse)
270 0 : return NS_NewSVGEllipseElement(aResult, aNodeInfo);
271 0 : if (name == nsGkAtoms::line)
272 0 : return NS_NewSVGLineElement(aResult, aNodeInfo);
273 0 : if (name == nsGkAtoms::rect)
274 0 : return NS_NewSVGRectElement(aResult, aNodeInfo);
275 0 : if (name == nsGkAtoms::svg)
276 0 : return NS_NewSVGSVGElement(aResult, aNodeInfo, aFromParser);
277 0 : if (name == nsGkAtoms::g)
278 0 : return NS_NewSVGGElement(aResult, aNodeInfo);
279 0 : if (name == nsGkAtoms::foreignObject)
280 0 : return NS_NewSVGForeignObjectElement(aResult, aNodeInfo);
281 0 : if (name == nsGkAtoms::path)
282 0 : return NS_NewSVGPathElement(aResult, aNodeInfo);
283 0 : if (name == nsGkAtoms::text)
284 0 : return NS_NewSVGTextElement(aResult, aNodeInfo);
285 0 : if (name == nsGkAtoms::tspan)
286 0 : return NS_NewSVGTSpanElement(aResult, aNodeInfo);
287 0 : if (name == nsGkAtoms::image)
288 0 : return NS_NewSVGImageElement(aResult, aNodeInfo);
289 0 : if (name == nsGkAtoms::style)
290 0 : return NS_NewSVGStyleElement(aResult, aNodeInfo);
291 0 : if (name == nsGkAtoms::linearGradient)
292 0 : return NS_NewSVGLinearGradientElement(aResult, aNodeInfo);
293 0 : if (name == nsGkAtoms::metadata)
294 0 : return NS_NewSVGMetadataElement(aResult, aNodeInfo);
295 0 : if (name == nsGkAtoms::radialGradient)
296 0 : return NS_NewSVGRadialGradientElement(aResult, aNodeInfo);
297 0 : if (name == nsGkAtoms::stop)
298 0 : return NS_NewSVGStopElement(aResult, aNodeInfo);
299 0 : if (name == nsGkAtoms::defs)
300 0 : return NS_NewSVGDefsElement(aResult, aNodeInfo);
301 0 : if (name == nsGkAtoms::desc)
302 0 : return NS_NewSVGDescElement(aResult, aNodeInfo);
303 0 : if (name == nsGkAtoms::script)
304 0 : return NS_NewSVGScriptElement(aResult, aNodeInfo, aFromParser);
305 0 : if (name == nsGkAtoms::use)
306 0 : return NS_NewSVGUseElement(aResult, aNodeInfo);
307 0 : if (name == nsGkAtoms::symbol)
308 0 : return NS_NewSVGSymbolElement(aResult, aNodeInfo);
309 0 : if (name == nsGkAtoms::marker)
310 0 : return NS_NewSVGMarkerElement(aResult, aNodeInfo);
311 0 : if (name == nsGkAtoms::title)
312 0 : return NS_NewSVGTitleElement(aResult, aNodeInfo);
313 0 : if (name == nsGkAtoms::clipPath)
314 0 : return NS_NewSVGClipPathElement(aResult, aNodeInfo);
315 0 : if (name == nsGkAtoms::textPath)
316 0 : return NS_NewSVGTextPathElement(aResult, aNodeInfo);
317 0 : if (name == nsGkAtoms::filter)
318 0 : return NS_NewSVGFilterElement(aResult, aNodeInfo);
319 0 : if (name == nsGkAtoms::feBlend)
320 0 : return NS_NewSVGFEBlendElement(aResult, aNodeInfo);
321 0 : if (name == nsGkAtoms::feColorMatrix)
322 0 : return NS_NewSVGFEColorMatrixElement(aResult, aNodeInfo);
323 0 : if (name == nsGkAtoms::feComponentTransfer)
324 0 : return NS_NewSVGFEComponentTransferElement(aResult, aNodeInfo);
325 0 : if (name == nsGkAtoms::feComposite)
326 0 : return NS_NewSVGFECompositeElement(aResult, aNodeInfo);
327 0 : if (name == nsGkAtoms::feFuncR)
328 0 : return NS_NewSVGFEFuncRElement(aResult, aNodeInfo);
329 0 : if (name == nsGkAtoms::feFuncG)
330 0 : return NS_NewSVGFEFuncGElement(aResult, aNodeInfo);
331 0 : if (name == nsGkAtoms::feFuncB)
332 0 : return NS_NewSVGFEFuncBElement(aResult, aNodeInfo);
333 0 : if (name == nsGkAtoms::feFuncA)
334 0 : return NS_NewSVGFEFuncAElement(aResult, aNodeInfo);
335 0 : if (name == nsGkAtoms::feGaussianBlur)
336 0 : return NS_NewSVGFEGaussianBlurElement(aResult, aNodeInfo);
337 0 : if (name == nsGkAtoms::feMerge)
338 0 : return NS_NewSVGFEMergeElement(aResult, aNodeInfo);
339 0 : if (name == nsGkAtoms::feMergeNode)
340 0 : return NS_NewSVGFEMergeNodeElement(aResult, aNodeInfo);
341 0 : if (name == nsGkAtoms::feMorphology)
342 0 : return NS_NewSVGFEMorphologyElement(aResult, aNodeInfo);
343 0 : if (name == nsGkAtoms::feOffset)
344 0 : return NS_NewSVGFEOffsetElement(aResult, aNodeInfo);
345 0 : if (name == nsGkAtoms::feFlood)
346 0 : return NS_NewSVGFEFloodElement(aResult, aNodeInfo);
347 0 : if (name == nsGkAtoms::feTile)
348 0 : return NS_NewSVGFETileElement(aResult, aNodeInfo);
349 0 : if (name == nsGkAtoms::feTurbulence)
350 0 : return NS_NewSVGFETurbulenceElement(aResult, aNodeInfo);
351 0 : if (name == nsGkAtoms::feConvolveMatrix)
352 0 : return NS_NewSVGFEConvolveMatrixElement(aResult, aNodeInfo);
353 0 : if (name == nsGkAtoms::feDistantLight)
354 0 : return NS_NewSVGFEDistantLightElement(aResult, aNodeInfo);
355 0 : if (name == nsGkAtoms::fePointLight)
356 0 : return NS_NewSVGFEPointLightElement(aResult, aNodeInfo);
357 0 : if (name == nsGkAtoms::feSpotLight)
358 0 : return NS_NewSVGFESpotLightElement(aResult, aNodeInfo);
359 0 : if (name == nsGkAtoms::feDiffuseLighting)
360 0 : return NS_NewSVGFEDiffuseLightingElement(aResult, aNodeInfo);
361 0 : if (name == nsGkAtoms::feSpecularLighting)
362 0 : return NS_NewSVGFESpecularLightingElement(aResult, aNodeInfo);
363 0 : if (name == nsGkAtoms::feImage)
364 0 : return NS_NewSVGFEImageElement(aResult, aNodeInfo);
365 0 : if (name == nsGkAtoms::feDisplacementMap)
366 0 : return NS_NewSVGFEDisplacementMapElement(aResult, aNodeInfo);
367 0 : if (name == nsGkAtoms::pattern)
368 0 : return NS_NewSVGPatternElement(aResult, aNodeInfo);
369 0 : if (name == nsGkAtoms::mask)
370 0 : return NS_NewSVGMaskElement(aResult, aNodeInfo);
371 0 : if (name == nsGkAtoms::svgSwitch)
372 0 : return NS_NewSVGSwitchElement(aResult, aNodeInfo);
373 0 : if (NS_SMILEnabled()) {
374 0 : if (name == nsGkAtoms::animate)
375 0 : return NS_NewSVGAnimateElement(aResult, aNodeInfo);
376 0 : if (name == nsGkAtoms::animateTransform)
377 0 : return NS_NewSVGAnimateTransformElement(aResult, aNodeInfo);
378 0 : if (name == nsGkAtoms::animateMotion)
379 0 : return NS_NewSVGAnimateMotionElement(aResult, aNodeInfo);
380 0 : if (name == nsGkAtoms::mpath)
381 0 : return NS_NewSVGMpathElement(aResult, aNodeInfo);
382 0 : if (name == nsGkAtoms::set)
383 0 : return NS_NewSVGSetElement(aResult, aNodeInfo);
384 : }
385 :
386 : // if we don't know what to create, just create a standard svg element:
387 0 : return NS_NewSVGUnknownElement(aResult, aNodeInfo);
388 : }
389 :
|