1 | /* |
2 | * THIS FILE WAS AUTOMATICALLY GENERATED, DO NOT EDIT. |
3 | * |
4 | * This file was generated by the dom/make_names.pl script. |
5 | * |
6 | * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All rights reserved. |
7 | * |
8 | * Redistribution and use in source and binary forms, with or without |
9 | * modification, are permitted provided that the following conditions |
10 | * are met: |
11 | * 1. Redistributions of source code must retain the above copyright |
12 | * notice, this list of conditions and the following disclaimer. |
13 | * 2. Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the |
15 | * documentation and/or other materials provided with the distribution. |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
18 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
20 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
21 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
23 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
24 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
25 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | */ |
29 | |
30 | #include "config.h" |
31 | |
32 | #if ENABLE(MATHML) |
33 | |
34 | #include "MathMLElementFactory.h" |
35 | |
36 | #include "MathMLNames.h" |
37 | |
38 | #include "MathMLAnnotationElement.h" |
39 | #include "MathMLSelectElement.h" |
40 | #include "MathMLPresentationElement.h" |
41 | #include "MathMLMathElement.h" |
42 | #include "MathMLMencloseElement.h" |
43 | #include "MathMLRowElement.h" |
44 | #include "MathMLFractionElement.h" |
45 | #include "MathMLTokenElement.h" |
46 | #include "MathMLScriptsElement.h" |
47 | #include "MathMLOperatorElement.h" |
48 | #include "MathMLUnderOverElement.h" |
49 | #include "MathMLPaddedElement.h" |
50 | #include "MathMLRootElement.h" |
51 | #include "MathMLSpaceElement.h" |
52 | #include "MathMLUnknownElement.h" |
53 | |
54 | #include "Document.h" |
55 | #include "RuntimeEnabledFeatures.h" |
56 | #include "Settings.h" |
57 | #include <wtf/HashMap.h> |
58 | #include <wtf/NeverDestroyed.h> |
59 | |
60 | namespace WebCore { |
61 | |
62 | using namespace MathMLNames; |
63 | |
64 | typedef Ref<MathMLElement> (*MathMLConstructorFunction)(const QualifiedName&, Document&, bool createdByParser); |
65 | |
66 | static Ref<MathMLElement> annotationConstructor(const QualifiedName& tagName, Document& document, bool) |
67 | { |
68 | return MathMLAnnotationElement::create(tagName, document); |
69 | } |
70 | |
71 | static Ref<MathMLElement> selectConstructor(const QualifiedName& tagName, Document& document, bool) |
72 | { |
73 | return MathMLSelectElement::create(tagName, document); |
74 | } |
75 | |
76 | static Ref<MathMLElement> presentationConstructor(const QualifiedName& tagName, Document& document, bool) |
77 | { |
78 | return MathMLPresentationElement::create(tagName, document); |
79 | } |
80 | |
81 | static Ref<MathMLElement> mathConstructor(const QualifiedName& tagName, Document& document, bool) |
82 | { |
83 | return MathMLMathElement::create(tagName, document); |
84 | } |
85 | |
86 | static Ref<MathMLElement> mencloseConstructor(const QualifiedName& tagName, Document& document, bool) |
87 | { |
88 | return MathMLMencloseElement::create(tagName, document); |
89 | } |
90 | |
91 | static Ref<MathMLElement> rowConstructor(const QualifiedName& tagName, Document& document, bool) |
92 | { |
93 | return MathMLRowElement::create(tagName, document); |
94 | } |
95 | |
96 | static Ref<MathMLElement> fractionConstructor(const QualifiedName& tagName, Document& document, bool) |
97 | { |
98 | return MathMLFractionElement::create(tagName, document); |
99 | } |
100 | |
101 | static Ref<MathMLElement> tokenConstructor(const QualifiedName& tagName, Document& document, bool) |
102 | { |
103 | return MathMLTokenElement::create(tagName, document); |
104 | } |
105 | |
106 | static Ref<MathMLElement> scriptsConstructor(const QualifiedName& tagName, Document& document, bool) |
107 | { |
108 | return MathMLScriptsElement::create(tagName, document); |
109 | } |
110 | |
111 | static Ref<MathMLElement> operatorConstructor(const QualifiedName& tagName, Document& document, bool) |
112 | { |
113 | return MathMLOperatorElement::create(tagName, document); |
114 | } |
115 | |
116 | static Ref<MathMLElement> underoverConstructor(const QualifiedName& tagName, Document& document, bool) |
117 | { |
118 | return MathMLUnderOverElement::create(tagName, document); |
119 | } |
120 | |
121 | static Ref<MathMLElement> paddedConstructor(const QualifiedName& tagName, Document& document, bool) |
122 | { |
123 | return MathMLPaddedElement::create(tagName, document); |
124 | } |
125 | |
126 | static Ref<MathMLElement> rootConstructor(const QualifiedName& tagName, Document& document, bool) |
127 | { |
128 | return MathMLRootElement::create(tagName, document); |
129 | } |
130 | |
131 | static Ref<MathMLElement> spaceConstructor(const QualifiedName& tagName, Document& document, bool) |
132 | { |
133 | return MathMLSpaceElement::create(tagName, document); |
134 | } |
135 | |
136 | |
137 | struct MathMLConstructorFunctionMapEntry { |
138 | MathMLConstructorFunctionMapEntry(MathMLConstructorFunction function, const QualifiedName& name) |
139 | : function(function) |
140 | , qualifiedName(&name) |
141 | { } |
142 | |
143 | MathMLConstructorFunctionMapEntry() |
144 | : function(nullptr) |
145 | , qualifiedName(nullptr) |
146 | { } |
147 | |
148 | MathMLConstructorFunction function; |
149 | const QualifiedName* qualifiedName; // Use pointer instead of reference so that emptyValue() in HashMap is cheap to create. |
150 | }; |
151 | |
152 | static NEVER_INLINE HashMap<AtomicStringImpl*, MathMLConstructorFunctionMapEntry> createMathMLFactoryMap() |
153 | { |
154 | struct TableEntry { |
155 | const QualifiedName& name; |
156 | MathMLConstructorFunction function; |
157 | }; |
158 | |
159 | static const TableEntry table[] = { |
160 | { annotationTag, annotationConstructor }, |
161 | { annotation_xmlTag, annotationConstructor }, |
162 | { mactionTag, selectConstructor }, |
163 | { maligngroupTag, presentationConstructor }, |
164 | { malignmarkTag, presentationConstructor }, |
165 | { mathTag, mathConstructor }, |
166 | { mencloseTag, mencloseConstructor }, |
167 | { merrorTag, rowConstructor }, |
168 | { mfencedTag, rowConstructor }, |
169 | { mfracTag, fractionConstructor }, |
170 | { mglyphTag, presentationConstructor }, |
171 | { miTag, tokenConstructor }, |
172 | { mlabeledtrTag, presentationConstructor }, |
173 | { mlongdivTag, presentationConstructor }, |
174 | { mmultiscriptsTag, scriptsConstructor }, |
175 | { mnTag, tokenConstructor }, |
176 | { moTag, operatorConstructor }, |
177 | { moverTag, underoverConstructor }, |
178 | { mpaddedTag, paddedConstructor }, |
179 | { mphantomTag, rowConstructor }, |
180 | { mprescriptsTag, presentationConstructor }, |
181 | { mrootTag, rootConstructor }, |
182 | { mrowTag, rowConstructor }, |
183 | { msTag, tokenConstructor }, |
184 | { mscarriesTag, presentationConstructor }, |
185 | { mscarryTag, presentationConstructor }, |
186 | { msgroupTag, presentationConstructor }, |
187 | { mslineTag, presentationConstructor }, |
188 | { mspaceTag, spaceConstructor }, |
189 | { msqrtTag, rootConstructor }, |
190 | { msrowTag, presentationConstructor }, |
191 | { mstackTag, presentationConstructor }, |
192 | { mstyleTag, rowConstructor }, |
193 | { msubTag, scriptsConstructor }, |
194 | { msubsupTag, scriptsConstructor }, |
195 | { msupTag, scriptsConstructor }, |
196 | { mtableTag, presentationConstructor }, |
197 | { mtdTag, presentationConstructor }, |
198 | { mtextTag, tokenConstructor }, |
199 | { mtrTag, presentationConstructor }, |
200 | { munderTag, underoverConstructor }, |
201 | { munderoverTag, underoverConstructor }, |
202 | { noneTag, presentationConstructor }, |
203 | { semanticsTag, selectConstructor }, |
204 | }; |
205 | |
206 | HashMap<AtomicStringImpl*, MathMLConstructorFunctionMapEntry> map; |
207 | for (auto& entry : table) |
208 | map.add(entry.name.localName().impl(), MathMLConstructorFunctionMapEntry(entry.function, entry.name)); |
209 | return map; |
210 | } |
211 | |
212 | static MathMLConstructorFunctionMapEntry findMathMLElementConstructorFunction(const AtomicString& localName) |
213 | { |
214 | static const auto map = makeNeverDestroyed(createMathMLFactoryMap()); |
215 | return map.get().get(localName.impl()); |
216 | } |
217 | |
218 | RefPtr<MathMLElement> MathMLElementFactory::createKnownElement(const AtomicString& localName, Document& document, bool createdByParser) |
219 | { |
220 | const MathMLConstructorFunctionMapEntry& entry = findMathMLElementConstructorFunction(localName); |
221 | if (LIKELY(entry.function)) { |
222 | ASSERT(entry.qualifiedName); |
223 | const auto& name = *entry.qualifiedName; |
224 | return entry.function(name, document, createdByParser); |
225 | } |
226 | return nullptr; |
227 | } |
228 | |
229 | RefPtr<MathMLElement> MathMLElementFactory::createKnownElement(const QualifiedName& name, Document& document, bool createdByParser) |
230 | { |
231 | const MathMLConstructorFunctionMapEntry& entry = findMathMLElementConstructorFunction(name.localName()); |
232 | if (LIKELY(entry.function)) |
233 | return entry.function(name, document, createdByParser); |
234 | return nullptr; |
235 | } |
236 | |
237 | Ref<MathMLElement> MathMLElementFactory::createElement(const AtomicString& localName, Document& document, bool createdByParser) |
238 | { |
239 | const MathMLConstructorFunctionMapEntry& entry = findMathMLElementConstructorFunction(localName); |
240 | if (LIKELY(entry.function)) { |
241 | ASSERT(entry.qualifiedName); |
242 | const auto& name = *entry.qualifiedName; |
243 | return entry.function(name, document, createdByParser); |
244 | } |
245 | return MathMLUnknownElement::create(QualifiedName(nullAtom(), localName, mathmlNamespaceURI), document); |
246 | } |
247 | |
248 | Ref<MathMLElement> MathMLElementFactory::createElement(const QualifiedName& name, Document& document, bool createdByParser) |
249 | { |
250 | const MathMLConstructorFunctionMapEntry& entry = findMathMLElementConstructorFunction(name.localName()); |
251 | if (LIKELY(entry.function)) |
252 | return entry.function(name, document, createdByParser); |
253 | return MathMLUnknownElement::create(name, document); |
254 | } |
255 | |
256 | } // namespace WebCore |
257 | |
258 | #endif |
259 | |