1 {% from "macros.tmpl" import license %}
5 #include "{{namespace}}ElementFactory.h"
7 #include "{{namespace}}Names.h"
8 {% for tag in tags|groupby('interface') %}
9 #include "core/{{namespace|lower}}/{{tag[0]}}.h"
11 {% if fallback_interface %}
12 #include "core/{{namespace|lower}}/{{fallback_interface}}.h"
14 #include "core/dom/custom/CustomElement.h"
15 #include "core/dom/custom/CustomElementRegistrationContext.h"
16 #include "core/dom/Document.h"
17 #include "core/frame/Settings.h"
18 #include "platform/RuntimeEnabledFeatures.h"
19 #include "wtf/HashMap.h"
23 using namespace {{namespace}}Names;
25 typedef PassRefPtrWillBeRawPtr<{{namespace}}Element> (*ConstructorFunction)(
27 {% if namespace == 'HTML' %}
30 bool createdByParser);
32 typedef HashMap<AtomicString, ConstructorFunction> FunctionMap;
34 static FunctionMap* g_constructors = 0;
36 {% for tag in tags|sort if not tag.noConstructor %}
37 {% filter enable_conditional(tag.Conditional) %}
38 static PassRefPtrWillBeRawPtr<{{namespace}}Element> {{tag|symbol}}Constructor(
40 {% if namespace == 'HTML' %}
41 HTMLFormElement* formElement,
45 {% if tag.runtimeEnabled %}
46 if (!RuntimeEnabledFeatures::{{tag.runtimeEnabled}}Enabled())
47 return {{fallback_interface}}::create({{tag|symbol}}Tag, document);
49 return {{tag.interface}}::create(
50 {%- if tag.multipleTagNames %}{{tag|symbol}}Tag, {% endif -%}
52 {%- if namespace == 'HTML' and tag.constructorNeedsFormElement %}, formElement{% endif -%}
53 {%- if tag.constructorNeedsCreatedByParser %}, createdByParser{% endif -%}
59 struct Create{{namespace}}FunctionMapData {
60 const QualifiedName& tag;
61 ConstructorFunction func;
64 static void create{{namespace}}FunctionMap()
66 ASSERT(!g_constructors);
67 g_constructors = new FunctionMap;
68 // Empty array initializer lists are illegal [dcl.init.aggr] and will not
69 // compile in MSVC. If tags list is empty, add check to skip this.
70 static const Create{{namespace}}FunctionMapData data[] = {
71 {% for tag in tags|sort if not tag.noConstructor %}
72 {% filter enable_conditional(tag.Conditional) %}
73 { {{tag|symbol}}Tag, {{tag|symbol}}Constructor },
77 for (size_t i = 0; i < WTF_ARRAY_LENGTH(data); i++)
78 g_constructors->set(data[i].tag.localName(), data[i].func);
81 PassRefPtrWillBeRawPtr<{{namespace}}Element> {{namespace}}ElementFactory::create{{namespace}}Element(
82 const AtomicString& localName,
84 {% if namespace == 'HTML' %}
85 HTMLFormElement* formElement,
90 create{{namespace}}FunctionMap();
91 if (ConstructorFunction function = g_constructors->get(localName))
92 return function(document, {% if namespace == 'HTML' %}formElement, {% endif %}createdByParser);
94 if (document.registrationContext() && CustomElement::isValidName(localName)) {
95 RefPtrWillBeRawPtr<Element> element = document.registrationContext()->createCustomTagElement(document, QualifiedName(nullAtom, localName, {{namespace_prefix}}NamespaceURI));
96 ASSERT_WITH_SECURITY_IMPLICATION(element->is{{namespace}}Element());
97 return static_pointer_cast<{{namespace}}Element>(element.release());
100 return {{fallback_interface}}::create(QualifiedName(nullAtom, localName, {{namespace_prefix}}NamespaceURI), document);