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

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

Issue 330093002: Add support in generate scripts to handle Conditional (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 6 months 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 "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 17 matching lines...) Expand all
28 {% if namespace == 'HTML' %} 28 {% if namespace == 'HTML' %}
29 HTMLFormElement*, 29 HTMLFormElement*,
30 {% endif %} 30 {% endif %}
31 bool createdByParser); 31 bool createdByParser);
32 32
33 typedef HashMap<AtomicString, ConstructorFunction> FunctionMap; 33 typedef HashMap<AtomicString, ConstructorFunction> FunctionMap;
34 34
35 static FunctionMap* g_constructors = 0; 35 static FunctionMap* g_constructors = 0;
36 36
37 {% for tag in tags|sort if not tag.noConstructor %} 37 {% for tag in tags|sort if not tag.noConstructor %}
38 {% filter enable_conditional(tag.Conditional) %}
38 static PassRefPtrWillBeRawPtr<{{namespace}}Element> {{tag|symbol}}Constructor( 39 static PassRefPtrWillBeRawPtr<{{namespace}}Element> {{tag|symbol}}Constructor(
39 Document& document, 40 Document& document,
40 {% if namespace == 'HTML' %} 41 {% if namespace == 'HTML' %}
41 HTMLFormElement* formElement, 42 HTMLFormElement* formElement,
42 {% endif %} 43 {% endif %}
43 bool createdByParser) 44 bool createdByParser)
44 { 45 {
45 {% if tag.contextConditional %} 46 {% if tag.contextConditional %}
46 if (!ContextFeatures::{{tag.contextConditional}}Enabled(&document)) 47 if (!ContextFeatures::{{tag.contextConditional}}Enabled(&document))
47 return {{fallback_interface}}::create({{tag|symbol}}Tag, document); 48 return {{fallback_interface}}::create({{tag|symbol}}Tag, document);
48 {% endif %} 49 {% endif %}
49 {% if tag.runtimeEnabled %} 50 {% if tag.runtimeEnabled %}
50 if (!RuntimeEnabledFeatures::{{tag.runtimeEnabled}}Enabled()) 51 if (!RuntimeEnabledFeatures::{{tag.runtimeEnabled}}Enabled())
51 return {{fallback_interface}}::create({{tag|symbol}}Tag, document); 52 return {{fallback_interface}}::create({{tag|symbol}}Tag, document);
52 {% endif %} 53 {% endif %}
53 return {{tag.interface}}::create( 54 return {{tag.interface}}::create(
54 {%- if tag.multipleTagNames %}{{tag|symbol}}Tag, {% endif -%} 55 {%- if tag.multipleTagNames %}{{tag|symbol}}Tag, {% endif -%}
55 document 56 document
56 {%- if namespace == 'HTML' and tag.constructorNeedsFormElement %}, formE lement{% endif -%} 57 {%- if namespace == 'HTML' and tag.constructorNeedsFormElement %}, formE lement{% endif -%}
57 {%- if tag.constructorNeedsCreatedByParser %}, createdByParser{% endif - %} 58 {%- if tag.constructorNeedsCreatedByParser %}, createdByParser{% endif - %}
58 ); 59 );
59 } 60 }
61 {% endfilter %}
60 {% endfor %} 62 {% endfor %}
61 63
62 struct Create{{namespace}}FunctionMapData { 64 struct Create{{namespace}}FunctionMapData {
63 const QualifiedName& tag; 65 const QualifiedName& tag;
64 ConstructorFunction func; 66 ConstructorFunction func;
65 }; 67 };
66 68
67 static void create{{namespace}}FunctionMap() 69 static void create{{namespace}}FunctionMap()
68 { 70 {
69 ASSERT(!g_constructors); 71 ASSERT(!g_constructors);
70 g_constructors = new FunctionMap; 72 g_constructors = new FunctionMap;
71 static const Create{{namespace}}FunctionMapData data[] = { 73 static const Create{{namespace}}FunctionMapData data[] = {
Nils Barth (inactive) 2014/06/13 02:14:24 One subtlety: this definition *fails to compile* o
maheshkk 2014/06/13 20:03:16 That's a good point. I have added comment for now
72 {% for tag in tags|sort if not tag.noConstructor %} 74 {% for tag in tags|sort if not tag.noConstructor %}
75 {% filter enable_conditional(tag.Conditional) %}
73 { {{tag|symbol}}Tag, {{tag|symbol}}Constructor }, 76 { {{tag|symbol}}Tag, {{tag|symbol}}Constructor },
77 {% endfilter %}
74 {% endfor %} 78 {% endfor %}
75 }; 79 };
76 for (size_t i = 0; i < WTF_ARRAY_LENGTH(data); i++) 80 for (size_t i = 0; i < WTF_ARRAY_LENGTH(data); i++)
77 g_constructors->set(data[i].tag.localName(), data[i].func); 81 g_constructors->set(data[i].tag.localName(), data[i].func);
78 } 82 }
79 83
80 PassRefPtrWillBeRawPtr<{{namespace}}Element> {{namespace}}ElementFactory::create {{namespace}}Element( 84 PassRefPtrWillBeRawPtr<{{namespace}}Element> {{namespace}}ElementFactory::create {{namespace}}Element(
81 const AtomicString& localName, 85 const AtomicString& localName,
82 Document& document, 86 Document& document,
83 {% if namespace == 'HTML' %} 87 {% if namespace == 'HTML' %}
84 HTMLFormElement* formElement, 88 HTMLFormElement* formElement,
85 {% endif %} 89 {% endif %}
86 bool createdByParser) 90 bool createdByParser)
87 { 91 {
88 if (!g_constructors) 92 if (!g_constructors)
89 create{{namespace}}FunctionMap(); 93 create{{namespace}}FunctionMap();
90 if (ConstructorFunction function = g_constructors->get(localName)) 94 if (ConstructorFunction function = g_constructors->get(localName))
91 return function(document, {% if namespace == 'HTML' %}formElement, {% en dif %}createdByParser); 95 return function(document, {% if namespace == 'HTML' %}formElement, {% en dif %}createdByParser);
92 96
93 if (document.registrationContext() && CustomElement::isValidName(localName)) { 97 if (document.registrationContext() && CustomElement::isValidName(localName)) {
94 RefPtrWillBeRawPtr<Element> element = document.registrationContext()->cr eateCustomTagElement(document, QualifiedName(nullAtom, localName, {{namespace_pr efix}}NamespaceURI)); 98 RefPtrWillBeRawPtr<Element> element = document.registrationContext()->cr eateCustomTagElement(document, QualifiedName(nullAtom, localName, {{namespace_pr efix}}NamespaceURI));
95 ASSERT_WITH_SECURITY_IMPLICATION(element->is{{namespace}}Element()); 99 ASSERT_WITH_SECURITY_IMPLICATION(element->is{{namespace}}Element());
96 return static_pointer_cast<{{namespace}}Element>(element.release()); 100 return static_pointer_cast<{{namespace}}Element>(element.release());
97 } 101 }
98 102
99 return {{fallback_interface}}::create(QualifiedName(nullAtom, localName, {{n amespace_prefix}}NamespaceURI), document); 103 return {{fallback_interface}}::create(QualifiedName(nullAtom, localName, {{n amespace_prefix}}NamespaceURI), document);
100 } 104 }
101 105
102 } // namespace WebCore 106 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698