OLD | NEW |
1 {% from "macros.tmpl" import license -%} | 1 {% from "macros.tmpl" import license -%} |
2 {{ license() }} | 2 {{ license() }} |
3 | 3 |
4 #include "config.h" | 4 #include "config.h" |
5 #include "{{namespace}}ElementFactory.h" | 5 #include "{{namespace}}ElementFactory.h" |
6 | 6 |
7 #include "RuntimeEnabledFeatures.h" | 7 #include "RuntimeEnabledFeatures.h" |
8 #include "{{namespace}}Names.h" | 8 #include "{{namespace}}Names.h" |
9 {%- for tag in tags|sort %} | 9 {%- for tag in tags|sort %} |
10 #include "core/{{namespace|lower}}/{{tag.interface}}.h" | 10 #include "core/{{namespace|lower}}/{{tag.interface}}.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 {%- endif %} | 51 {%- endif %} |
52 return {{tag.interface}}::create( | 52 return {{tag.interface}}::create( |
53 {%- if tag.multipleTagNames -%} {{tag|symbol}}Tag, {% endif -%} | 53 {%- if tag.multipleTagNames -%} {{tag|symbol}}Tag, {% endif -%} |
54 document | 54 document |
55 {%- if namespace == 'HTML' and tag.constructorNeedsFormElement %}, formElement{%
endif -%} | 55 {%- if namespace == 'HTML' and tag.constructorNeedsFormElement %}, formElement{%
endif -%} |
56 {%- if tag.constructorNeedsCreatedByParser %}, createdByParser{% endif -%} | 56 {%- if tag.constructorNeedsCreatedByParser %}, createdByParser{% endif -%} |
57 ); | 57 ); |
58 } | 58 } |
59 {%- endfor %} | 59 {%- endfor %} |
60 | 60 |
61 static void addTag(const QualifiedName& tag, ConstructorFunction func) | 61 struct Create{{namespace}}FunctionMapData { |
62 { | 62 const QualifiedName& tag; |
63 g_constructors->set(tag.localName(), func); | 63 ConstructorFunction func; |
64 } | 64 }; |
65 | 65 |
66 static void createFunctionMap() | 66 static void create{{namespace}}FunctionMap() |
67 { | 67 { |
68 ASSERT(!g_constructors); | 68 ASSERT(!g_constructors); |
69 g_constructors = new FunctionMap; | 69 g_constructors = new FunctionMap; |
| 70 static const Create{{namespace}}FunctionMapData data[] = { |
70 {%- for tag in tags|sort if not tag.noConstructor %} | 71 {%- for tag in tags|sort if not tag.noConstructor %} |
71 addTag({{tag|symbol}}Tag, {{tag|symbol}}Constructor); | 72 { {{tag|symbol}}Tag, {{tag|symbol}}Constructor }, |
72 {%- endfor %} | 73 {%- endfor %} |
| 74 }; |
| 75 for (size_t i = 0; i < WTF_ARRAY_LENGTH(data); i++) |
| 76 g_constructors->set(data[i].tag.localName(), data[i].func); |
73 } | 77 } |
74 | 78 |
75 PassRefPtr<{{namespace}}Element> {{namespace}}ElementFactory::create{{namespace}
}Element( | 79 PassRefPtr<{{namespace}}Element> {{namespace}}ElementFactory::create{{namespace}
}Element( |
76 const AtomicString& localName, | 80 const AtomicString& localName, |
77 Document& document, | 81 Document& document, |
78 {%- if namespace == 'HTML' %} | 82 {%- if namespace == 'HTML' %} |
79 HTMLFormElement* formElement, | 83 HTMLFormElement* formElement, |
80 {%- endif %} | 84 {%- endif %} |
81 bool createdByParser) | 85 bool createdByParser) |
82 { | 86 { |
83 if (!g_constructors) | 87 if (!g_constructors) |
84 createFunctionMap(); | 88 create{{namespace}}FunctionMap(); |
85 if (ConstructorFunction function = g_constructors->get(localName)) | 89 if (ConstructorFunction function = g_constructors->get(localName)) |
86 return function(document, {%- if namespace == 'HTML' %}formElement,{% en
dif %} createdByParser); | 90 return function(document, {%- if namespace == 'HTML' %}formElement,{% en
dif %} createdByParser); |
87 | 91 |
88 if (document.registrationContext() && CustomElement::isValidName(localName))
{ | 92 if (document.registrationContext() && CustomElement::isValidName(localName))
{ |
89 RefPtr<Element> element = document.registrationContext()->createCustomTa
gElement(document, QualifiedName(nullAtom, localName, {{namespace_prefix}}Namesp
aceURI)); | 93 RefPtr<Element> element = document.registrationContext()->createCustomTa
gElement(document, QualifiedName(nullAtom, localName, {{namespace_prefix}}Namesp
aceURI)); |
90 ASSERT_WITH_SECURITY_IMPLICATION(element->is{{namespace}}Element()); | 94 ASSERT_WITH_SECURITY_IMPLICATION(element->is{{namespace}}Element()); |
91 return static_pointer_cast<{{namespace}}Element>(element.release()); | 95 return static_pointer_cast<{{namespace}}Element>(element.release()); |
92 } | 96 } |
93 | 97 |
94 return {{fallback_interface}}::create(QualifiedName(nullAtom, localName, {{n
amespace_prefix}}NamespaceURI), document); | 98 return {{fallback_interface}}::create(QualifiedName(nullAtom, localName, {{n
amespace_prefix}}NamespaceURI), document); |
95 } | 99 } |
96 | 100 |
97 } // namespace WebCore | 101 } // namespace WebCore |
OLD | NEW |