OLD | NEW |
1 {% from "macros.tmpl" import license %} | 1 {% from "macros.tmpl" import license %} |
2 {{ license() }} | 2 {{ license() }} |
3 | 3 |
4 #include "{{namespace}}ElementFactory.h" | 4 #include "{{namespace}}ElementFactory.h" |
5 | 5 |
6 #include "{{namespace}}Names.h" | 6 #include "{{namespace}}Names.h" |
7 {% for tag in tags|groupby('interface') %} | 7 {% for tag in tags|groupby('interface') %} |
8 #include "core/{{namespace|lower}}/{{tag[0]}}.h" | 8 #include "core/{{namespace|lower}}/{{tag[0]}}.h" |
9 {% endfor %} | 9 {% endfor %} |
10 {% if fallback_interface %} | 10 {% if fallback_interface %} |
11 #include "core/{{namespace|lower}}/{{fallback_interface}}.h" | 11 #include "core/{{namespace|lower}}/{{fallback_interface}}.h" |
12 {% endif %} | 12 {% endif %} |
13 {% if namespace == 'HTML' %} | 13 {% if namespace == 'HTML' %} |
14 #include "core/html/custom/CustomElement.h" | 14 #include "core/html/custom/CustomElement.h" |
15 {% endif %} | 15 {% endif %} |
16 #include "core/html/custom/V0CustomElement.h" | 16 #include "core/html/custom/V0CustomElement.h" |
17 #include "core/html/custom/V0CustomElementRegistrationContext.h" | 17 #include "core/html/custom/V0CustomElementRegistrationContext.h" |
18 #include "core/dom/Document.h" | 18 #include "core/dom/Document.h" |
19 #include "core/frame/Settings.h" | 19 #include "core/frame/Settings.h" |
20 #include "platform/RuntimeEnabledFeatures.h" | 20 #include "platform/RuntimeEnabledFeatures.h" |
21 #include "platform/wtf/HashMap.h" | 21 #include "platform/wtf/HashMap.h" |
22 | 22 |
23 namespace blink { | 23 namespace blink { |
24 | 24 |
25 using namespace {{namespace}}Names; | 25 typedef {{namespace}}Element* (*{{namespace}}ConstructorFunction)( |
26 | |
27 typedef {{namespace}}Element* (*ConstructorFunction)( | |
28 Document&, | 26 Document&, |
29 CreateElementFlags); | 27 CreateElementFlags); |
30 | 28 |
31 typedef HashMap<AtomicString, ConstructorFunction> FunctionMap; | 29 typedef HashMap<AtomicString, {{namespace}}ConstructorFunction> {{namespace}}Fun
ctionMap; |
32 | 30 |
33 static FunctionMap* g_constructors = 0; | 31 static {{namespace}}FunctionMap* g_{{namespace}}_constructors = 0; |
34 | 32 |
35 {% for tag in tags|sort if not tag.noConstructor %} | 33 {% for tag in tags|sort if not tag.noConstructor %} |
36 static {{namespace}}Element* {{tag|symbol}}Constructor( | 34 static {{namespace}}Element* {{namespace}}{{tag|symbol}}Constructor( |
37 Document& document, | 35 Document& document, |
38 CreateElementFlags flags) { | 36 CreateElementFlags flags) { |
39 {% if tag.runtimeEnabled %} | 37 {% if tag.runtimeEnabled %} |
40 if (!RuntimeEnabledFeatures::{{tag.runtimeEnabled}}Enabled()) | 38 if (!RuntimeEnabledFeatures::{{tag.runtimeEnabled}}Enabled()) |
41 return {{fallback_interface}}::Create({{tag|symbol}}Tag, document); | 39 return {{fallback_interface}}::Create({{namespace}}Names::{{tag|symbol}}Tag,
document); |
42 {% endif %} | 40 {% endif %} |
43 return {{tag.interface}}::Create( | 41 return {{tag.interface}}::Create( |
44 {%- if tag.multipleTagNames %}{{tag|symbol}}Tag, {% endif -%} | 42 {%- if tag.multipleTagNames %}{{namespace}}Names::{{tag|symbol}}Tag, {% en
dif -%} |
45 document | 43 document |
46 {%- if tag.constructorNeedsCreatedByParser %}, flags & kCreatedByParser{%
endif -%} | 44 {%- if tag.constructorNeedsCreatedByParser %}, flags & kCreatedByParser{%
endif -%} |
47 ); | 45 ); |
48 } | 46 } |
49 {% endfor %} | 47 {% endfor %} |
50 | 48 |
51 struct Create{{namespace}}FunctionMapData { | 49 struct Create{{namespace}}FunctionMapData { |
52 const QualifiedName& tag; | 50 const QualifiedName& tag; |
53 ConstructorFunction func; | 51 {{namespace}}ConstructorFunction func; |
54 }; | 52 }; |
55 | 53 |
56 static void create{{namespace}}FunctionMap() { | 54 static void create{{namespace}}FunctionMap() { |
57 DCHECK(!g_constructors); | 55 DCHECK(!g_{{namespace}}_constructors); |
58 g_constructors = new FunctionMap; | 56 g_{{namespace}}_constructors = new {{namespace}}FunctionMap; |
59 // Empty array initializer lists are illegal [dcl.init.aggr] and will not | 57 // Empty array initializer lists are illegal [dcl.init.aggr] and will not |
60 // compile in MSVC. If tags list is empty, add check to skip this. | 58 // compile in MSVC. If tags list is empty, add check to skip this. |
61 static const Create{{namespace}}FunctionMapData data[] = { | 59 static const Create{{namespace}}FunctionMapData data[] = { |
62 {% for tag in tags|sort if not tag.noConstructor %} | 60 {% for tag in tags|sort if not tag.noConstructor %} |
63 { {{tag|symbol}}Tag, {{tag|symbol}}Constructor }, | 61 { {{namespace}}Names::{{tag|symbol}}Tag, {{namespace}}{{tag|symbol}}Construc
tor }, |
64 {% endfor %} | 62 {% endfor %} |
65 }; | 63 }; |
66 for (size_t i = 0; i < WTF_ARRAY_LENGTH(data); i++) | 64 for (size_t i = 0; i < WTF_ARRAY_LENGTH(data); i++) |
67 g_constructors->Set(data[i].tag.LocalName(), data[i].func); | 65 g_{{namespace}}_constructors->Set(data[i].tag.LocalName(), data[i].func); |
68 } | 66 } |
69 | 67 |
70 {{namespace}}Element* {{namespace}}ElementFactory::create{{namespace}}Element( | 68 {{namespace}}Element* {{namespace}}ElementFactory::create{{namespace}}Element( |
71 const AtomicString& localName, | 69 const AtomicString& localName, |
72 Document& document, | 70 Document& document, |
73 CreateElementFlags flags) { | 71 CreateElementFlags flags) { |
74 if (!g_constructors) | 72 if (!g_{{namespace}}_constructors) |
75 create{{namespace}}FunctionMap(); | 73 create{{namespace}}FunctionMap(); |
76 if (ConstructorFunction function = g_constructors->at(localName)) | 74 if ({{namespace}}ConstructorFunction function = g_{{namespace}}_constructors->
at(localName)) |
77 return function(document, flags); | 75 return function(document, flags); |
78 | 76 |
79 {% if namespace == 'HTML' %} | 77 {% if namespace == 'HTML' %} |
80 // createElement handles custom element creation itself in order to | 78 // createElement handles custom element creation itself in order to |
81 // transmit exceptions. | 79 // transmit exceptions. |
82 // TODO(dominicc): When the HTML parser can pass an error | 80 // TODO(dominicc): When the HTML parser can pass an error |
83 // reporting ExceptionState, and "v0" custom elements have been | 81 // reporting ExceptionState, and "v0" custom elements have been |
84 // removed, consolidate custom element creation into one place. | 82 // removed, consolidate custom element creation into one place. |
85 if (flags != kCreatedByCreateElement && CustomElement::ShouldCreateCustomEleme
nt(localName)) { | 83 if (flags != kCreatedByCreateElement && CustomElement::ShouldCreateCustomEleme
nt(localName)) { |
86 QualifiedName tagName(g_null_atom, localName, HTMLNames::xhtmlNamespaceURI); | 84 QualifiedName tagName(g_null_atom, localName, HTMLNames::xhtmlNamespaceURI); |
87 if (flags & kAsynchronousCustomElements) | 85 if (flags & kAsynchronousCustomElements) |
88 return CustomElement::CreateCustomElementAsync(document, tagName); | 86 return CustomElement::CreateCustomElementAsync(document, tagName); |
89 return CustomElement::CreateCustomElementSync(document, tagName); | 87 return CustomElement::CreateCustomElementSync(document, tagName); |
90 } | 88 } |
91 {% endif %} | 89 {% endif %} |
92 | 90 |
93 if (document.RegistrationContext() && | 91 if (document.RegistrationContext() && |
94 V0CustomElement::IsValidName(localName)) { | 92 V0CustomElement::IsValidName(localName)) { |
95 Element* element = document.RegistrationContext()->CreateCustomTagElement( | 93 Element* element = document.RegistrationContext()->CreateCustomTagElement( |
96 document, QualifiedName(g_null_atom, localName, {{namespace_prefix}}Name
spaceURI)); | 94 document, QualifiedName(g_null_atom, localName, {{namespace}}Names::{{na
mespace_prefix}}NamespaceURI)); |
97 SECURITY_DCHECK(element->Is{{namespace}}Element()); | 95 SECURITY_DCHECK(element->Is{{namespace}}Element()); |
98 return To{{namespace}}Element(element); | 96 return To{{namespace}}Element(element); |
99 } | 97 } |
100 | 98 |
101 return {{fallback_interface}}::Create(QualifiedName(g_null_atom, localName, {{
namespace_prefix}}NamespaceURI), document); | 99 return {{fallback_interface}}::Create(QualifiedName(g_null_atom, localName, {{
namespace}}Names::{{namespace_prefix}}NamespaceURI), document); |
102 } | 100 } |
103 | 101 |
104 } // namespace blink | 102 } // namespace blink |
OLD | NEW |