Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: third_party/WebKit/Source/build/scripts/templates/ElementFactory.cpp.tmpl

Issue 2561043002: Clean-up after Form Association Refactoring (Closed)
Patch Set: Removed constructorNeedsFormElement from scripts and HTMLTagNames Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/dom/custom/CustomElement.h" 14 #include "core/dom/custom/CustomElement.h"
15 {% endif %} 15 {% endif %}
16 #include "core/dom/custom/V0CustomElement.h" 16 #include "core/dom/custom/V0CustomElement.h"
17 #include "core/dom/custom/V0CustomElementRegistrationContext.h" 17 #include "core/dom/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 "wtf/HashMap.h" 21 #include "wtf/HashMap.h"
22 22
23 namespace blink { 23 namespace blink {
24 24
25 using namespace {{namespace}}Names; 25 using namespace {{namespace}}Names;
26 26
27 typedef {{namespace}}Element* (*ConstructorFunction)( 27 typedef {{namespace}}Element* (*ConstructorFunction)(
28 Document&, 28 Document&,
29 {% if namespace == 'HTML' %}
30 HTMLFormElement*,
31 {% endif %}
32 CreateElementFlags); 29 CreateElementFlags);
33 30
34 typedef HashMap<AtomicString, ConstructorFunction> FunctionMap; 31 typedef HashMap<AtomicString, ConstructorFunction> FunctionMap;
35 32
36 static FunctionMap* g_constructors = 0; 33 static FunctionMap* g_constructors = 0;
37 34
38 {% for tag in tags|sort if not tag.noConstructor %} 35 {% for tag in tags|sort if not tag.noConstructor %}
39 static {{namespace}}Element* {{tag|symbol}}Constructor( 36 static {{namespace}}Element* {{tag|symbol}}Constructor(
40 Document& document, 37 Document& document,
41 {% if namespace == 'HTML' %}
42 HTMLFormElement* formElement,
43 {% endif %}
44 CreateElementFlags flags) { 38 CreateElementFlags flags) {
45 {% if tag.runtimeEnabled %} 39 {% if tag.runtimeEnabled %}
46 if (!RuntimeEnabledFeatures::{{tag.runtimeEnabled}}Enabled()) 40 if (!RuntimeEnabledFeatures::{{tag.runtimeEnabled}}Enabled())
47 return {{fallback_interface}}::create({{tag|symbol}}Tag, document); 41 return {{fallback_interface}}::create({{tag|symbol}}Tag, document);
48 {% endif %} 42 {% endif %}
49 return {{tag.interface}}::create( 43 return {{tag.interface}}::create(
50 {%- if tag.multipleTagNames %}{{tag|symbol}}Tag, {% endif -%} 44 {%- if tag.multipleTagNames %}{{tag|symbol}}Tag, {% endif -%}
51 document 45 document
52 {%- if namespace == 'HTML' and tag.constructorNeedsFormElement %}, formEle ment{% endif -%}
53 {%- if tag.constructorNeedsCreatedByParser %}, flags & CreatedByParser{% e ndif -%} 46 {%- if tag.constructorNeedsCreatedByParser %}, flags & CreatedByParser{% e ndif -%}
54 ); 47 );
55 } 48 }
56 {% endfor %} 49 {% endfor %}
57 50
58 struct Create{{namespace}}FunctionMapData { 51 struct Create{{namespace}}FunctionMapData {
59 const QualifiedName& tag; 52 const QualifiedName& tag;
60 ConstructorFunction func; 53 ConstructorFunction func;
61 }; 54 };
62 55
63 static void create{{namespace}}FunctionMap() { 56 static void create{{namespace}}FunctionMap() {
64 ASSERT(!g_constructors); 57 ASSERT(!g_constructors);
65 g_constructors = new FunctionMap; 58 g_constructors = new FunctionMap;
66 // Empty array initializer lists are illegal [dcl.init.aggr] and will not 59 // Empty array initializer lists are illegal [dcl.init.aggr] and will not
67 // compile in MSVC. If tags list is empty, add check to skip this. 60 // compile in MSVC. If tags list is empty, add check to skip this.
68 static const Create{{namespace}}FunctionMapData data[] = { 61 static const Create{{namespace}}FunctionMapData data[] = {
69 {% for tag in tags|sort if not tag.noConstructor %} 62 {% for tag in tags|sort if not tag.noConstructor %}
70 { {{tag|symbol}}Tag, {{tag|symbol}}Constructor }, 63 { {{tag|symbol}}Tag, {{tag|symbol}}Constructor },
71 {% endfor %} 64 {% endfor %}
72 }; 65 };
73 for (size_t i = 0; i < WTF_ARRAY_LENGTH(data); i++) 66 for (size_t i = 0; i < WTF_ARRAY_LENGTH(data); i++)
74 g_constructors->set(data[i].tag.localName(), data[i].func); 67 g_constructors->set(data[i].tag.localName(), data[i].func);
75 } 68 }
76 69
77 {{namespace}}Element* {{namespace}}ElementFactory::create{{namespace}}Element( 70 {{namespace}}Element* {{namespace}}ElementFactory::create{{namespace}}Element(
78 const AtomicString& localName, 71 const AtomicString& localName,
79 Document& document, 72 Document& document,
80 {% if namespace == 'HTML' %}
81 HTMLFormElement* formElement,
82 {% endif %}
83 CreateElementFlags flags) { 73 CreateElementFlags flags) {
84 if (!g_constructors) 74 if (!g_constructors)
85 create{{namespace}}FunctionMap(); 75 create{{namespace}}FunctionMap();
86 if (ConstructorFunction function = g_constructors->get(localName)) 76 if (ConstructorFunction function = g_constructors->get(localName))
87 return function(document, {% if namespace == 'HTML' %}formElement, {% endif %}flags); 77 return function(document, flags);
88 78
89 {% if namespace == 'HTML' %} 79 {% if namespace == 'HTML' %}
90 // createElement handles custom element creation itself in order to 80 // createElement handles custom element creation itself in order to
91 // transmit exceptions. 81 // transmit exceptions.
92 // TODO(dominicc): When the HTML parser can pass an error 82 // TODO(dominicc): When the HTML parser can pass an error
93 // reporting ExceptionState, and "v0" custom elements have been 83 // reporting ExceptionState, and "v0" custom elements have been
94 // removed, consolidate custom element creation into one place. 84 // removed, consolidate custom element creation into one place.
95 if (flags != CreatedByCreateElement && CustomElement::shouldCreateCustomElemen t(localName)) { 85 if (flags != CreatedByCreateElement && CustomElement::shouldCreateCustomElemen t(localName)) {
96 QualifiedName tagName(nullAtom, localName, HTMLNames::xhtmlNamespaceURI); 86 QualifiedName tagName(nullAtom, localName, HTMLNames::xhtmlNamespaceURI);
97 if (flags & AsynchronousCustomElements) 87 if (flags & AsynchronousCustomElements)
98 return CustomElement::createCustomElementAsync(document, tagName); 88 return CustomElement::createCustomElementAsync(document, tagName);
99 return CustomElement::createCustomElementSync(document, tagName); 89 return CustomElement::createCustomElementSync(document, tagName);
100 } 90 }
101 {% endif %} 91 {% endif %}
102 92
103 if (document.registrationContext() && 93 if (document.registrationContext() &&
104 V0CustomElement::isValidName(localName)) { 94 V0CustomElement::isValidName(localName)) {
105 Element* element = document.registrationContext()->createCustomTagElement( 95 Element* element = document.registrationContext()->createCustomTagElement(
106 document, QualifiedName(nullAtom, localName, {{namespace_prefix}}Namespa ceURI)); 96 document, QualifiedName(nullAtom, localName, {{namespace_prefix}}Namespa ceURI));
107 SECURITY_DCHECK(element->is{{namespace}}Element()); 97 SECURITY_DCHECK(element->is{{namespace}}Element());
108 return to{{namespace}}Element(element); 98 return to{{namespace}}Element(element);
109 } 99 }
110 100
111 return {{fallback_interface}}::create(QualifiedName(nullAtom, localName, {{nam espace_prefix}}NamespaceURI), document); 101 return {{fallback_interface}}::create(QualifiedName(nullAtom, localName, {{nam espace_prefix}}NamespaceURI), document);
112 } 102 }
113 103
114 } // namespace blink 104 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698