Chromium Code Reviews| 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) | |
| 62 { | |
| 63 g_constructors->set(tag.localName(), func); | |
| 64 } | |
| 65 | |
| 66 static void createFunctionMap() | 61 static void createFunctionMap() |
| 67 { | 62 { |
| 68 ASSERT(!g_constructors); | 63 ASSERT(!g_constructors); |
| 69 g_constructors = new FunctionMap; | 64 g_constructors = new FunctionMap; |
| 65 struct CreateFunctionMapData { | |
| 66 const QualifiedName& tag; | |
| 67 ConstructorFunction func; | |
| 68 }; | |
| 69 const CreateFunctionMapData data[] = { | |
|
adamk
2014/02/18 18:28:41
Not sure if it matters (since this is only called
Daniel Bratell
2014/02/19 13:41:05
It's a tricky question. For a compile time constan
| |
| 70 {%- for tag in tags|sort if not tag.noConstructor %} | 70 {%- for tag in tags|sort if not tag.noConstructor %} |
| 71 addTag({{tag|symbol}}Tag, {{tag|symbol}}Constructor); | 71 { {{tag|symbol}}Tag, {{tag|symbol}}Constructor }, |
| 72 {%- endfor %} | 72 {%- endfor %} |
| 73 }; | |
| 74 for (size_t i = 0; i < sizeof(data) / sizeof(*data); i++) | |
|
adamk
2014/02/18 18:28:41
Nit: you can use WTF_ARRAY_LENGTH() (from wtf/StdL
Daniel Bratell
2014/02/19 13:41:05
Thanks!
| |
| 75 g_constructors->set(data[i].tag.localName(), data[i].func); | |
| 73 } | 76 } |
| 74 | 77 |
| 75 PassRefPtr<{{namespace}}Element> {{namespace}}ElementFactory::create{{namespace} }Element( | 78 PassRefPtr<{{namespace}}Element> {{namespace}}ElementFactory::create{{namespace} }Element( |
| 76 const AtomicString& localName, | 79 const AtomicString& localName, |
| 77 Document& document, | 80 Document& document, |
| 78 {%- if namespace == 'HTML' %} | 81 {%- if namespace == 'HTML' %} |
| 79 HTMLFormElement* formElement, | 82 HTMLFormElement* formElement, |
| 80 {%- endif %} | 83 {%- endif %} |
| 81 bool createdByParser) | 84 bool createdByParser) |
| 82 { | 85 { |
| 83 if (!g_constructors) | 86 if (!g_constructors) |
| 84 createFunctionMap(); | 87 createFunctionMap(); |
| 85 if (ConstructorFunction function = g_constructors->get(localName)) | 88 if (ConstructorFunction function = g_constructors->get(localName)) |
| 86 return function(document, {%- if namespace == 'HTML' %}formElement,{% en dif %} createdByParser); | 89 return function(document, {%- if namespace == 'HTML' %}formElement,{% en dif %} createdByParser); |
| 87 | 90 |
| 88 if (document.registrationContext() && CustomElement::isValidName(localName)) { | 91 if (document.registrationContext() && CustomElement::isValidName(localName)) { |
| 89 RefPtr<Element> element = document.registrationContext()->createCustomTa gElement(document, QualifiedName(nullAtom, localName, {{namespace_prefix}}Namesp aceURI)); | 92 RefPtr<Element> element = document.registrationContext()->createCustomTa gElement(document, QualifiedName(nullAtom, localName, {{namespace_prefix}}Namesp aceURI)); |
| 90 ASSERT_WITH_SECURITY_IMPLICATION(element->is{{namespace}}Element()); | 93 ASSERT_WITH_SECURITY_IMPLICATION(element->is{{namespace}}Element()); |
| 91 return static_pointer_cast<{{namespace}}Element>(element.release()); | 94 return static_pointer_cast<{{namespace}}Element>(element.release()); |
| 92 } | 95 } |
| 93 | 96 |
| 94 return {{fallback_interface}}::create(QualifiedName(nullAtom, localName, {{n amespace_prefix}}NamespaceURI), document); | 97 return {{fallback_interface}}::create(QualifiedName(nullAtom, localName, {{n amespace_prefix}}NamespaceURI), document); |
| 95 } | 98 } |
| 96 | 99 |
| 97 } // namespace WebCore | 100 } // namespace WebCore |
| OLD | NEW |