OLD | NEW |
(Empty) | |
| 1 {% from "macros.tmpl" import license -%} |
| 2 {{ license() }} |
| 3 |
| 4 #include "config.h" |
| 5 #include "{{namespace}}ElementFactory.h" |
| 6 |
| 7 #include "RuntimeEnabledFeatures.h" |
| 8 #include "{{namespace}}Names.h" |
| 9 {%- for tag in tags|sort %} |
| 10 #include "core/{{namespace|lower}}/{{tag|interface}}.h" |
| 11 {%- endfor %} |
| 12 {%- if fallback_interface %} |
| 13 #include "core/{{namespace|lower}}/{{fallback_interface}}.h" |
| 14 {%- endif %} |
| 15 #include "core/dom/ContextFeatures.h" |
| 16 #include "core/dom/custom/CustomElement.h" |
| 17 #include "core/dom/custom/CustomElementRegistrationContext.h" |
| 18 #include "core/dom/Document.h" |
| 19 #include "core/page/Settings.h" |
| 20 #include "wtf/HashMap.h" |
| 21 |
| 22 namespace WebCore { |
| 23 |
| 24 using namespace {{namespace}}Names; |
| 25 |
| 26 typedef PassRefPtr<{{namespace}}Element> (*ConstructorFunction)(const QualifiedN
ame&, Document&, HTMLFormElement*, bool createdByParser); |
| 27 typedef HashMap<StringImpl*, ConstructorFunction> FunctionMap; |
| 28 |
| 29 static FunctionMap* g_constructors = 0; |
| 30 |
| 31 {%- for tag in tags|sort if not tag.mapToTagName and not tag.noConstructor %} |
| 32 static PassRefPtr<{{namespace}}Element> {{tag|symbol}}Constructor(const Qualifie
dName& tagName, Document& document, HTMLFormElement* formElement, bool createdBy
Parser) |
| 33 { |
| 34 {%- if tag.wrapperOnlyIfMediaIsAvailable %} |
| 35 Settings* settings = document.settings(); |
| 36 if (!RuntimeEnabledFeatures::mediaEnabled() || (settings && !settings->media
Enabled())) |
| 37 return 0; |
| 38 {%- endif %} |
| 39 {%- if tag.contextConditional %} |
| 40 if (!ContextFeatures::{{tag.contextConditional}}Enabled(&document)) |
| 41 return 0; |
| 42 {%- endif %} |
| 43 return {{tag|interface}}::create(tagName, document |
| 44 {%- if tag.constructorNeedsFormElement %}, formElement{% endif -%} |
| 45 {%- if tag.constructorNeedsCreatedByParser %}, createdByParser{% endif -%} |
| 46 ); |
| 47 } |
| 48 {%- endfor %} |
| 49 |
| 50 {%- for tag in tags|sort if tag.mapToTagName %} |
| 51 static PassRefPtr<HTMLElement> {{tag|symbol}}Constructor(const QualifiedName& ta
gName, Document& document, HTMLFormElement* formElement, bool createdByParser) |
| 52 { |
| 53 return {{tag.mapToTagName}}Constructor(QualifiedName(tagName.prefix(), {{tag
.mapToTagName}}Tag.localName(), tagName.namespaceURI()), document, formElement,
createdByParser); |
| 54 } |
| 55 {%- endfor %} |
| 56 |
| 57 static void addTag(const QualifiedName& tag, ConstructorFunction func) |
| 58 { |
| 59 g_constructors->set(tag.localName().impl(), func); |
| 60 } |
| 61 |
| 62 static void createFunctionMap() |
| 63 { |
| 64 ASSERT(!g_constructors); |
| 65 g_constructors = new FunctionMap; |
| 66 {%- for tag in tags|sort if not tag.noConstructor %} |
| 67 addTag({{tag|symbol}}Tag, {{tag|symbol}}Constructor); |
| 68 {%- endfor %} |
| 69 } |
| 70 |
| 71 PassRefPtr<{{namespace}}Element> {{namespace}}ElementFactory::create{{namespace}
}Element(const QualifiedName& qName, Document* document, HTMLFormElement* formEl
ement, bool createdByParser) |
| 72 { |
| 73 if (!document) |
| 74 return 0; |
| 75 |
| 76 if (CustomElement::isValidName(qName.localName()) && document->registrationC
ontext()) { |
| 77 RefPtr<Element> element = document->registrationContext()->createCustomT
agElement(*document, qName, createdByParser ? CustomElementRegistrationContext::
CreatedByParser : CustomElementRegistrationContext::NotCreatedByParser); |
| 78 ASSERT_WITH_SECURITY_IMPLICATION(element->is{{namespace}}Element()); |
| 79 return static_pointer_cast<{{namespace}}Element>(element.release()); |
| 80 } |
| 81 |
| 82 if (!g_constructors) |
| 83 createFunctionMap(); |
| 84 if (ConstructorFunction function = g_constructors->get(qName.localName().imp
l())) { |
| 85 if (PassRefPtr<{{namespace}}Element> element = function(qName, *document
, formElement, createdByParser)) |
| 86 return element; |
| 87 } |
| 88 |
| 89 return {{fallback_interface}}::create(qName, *document); |
| 90 } |
| 91 |
| 92 } // namespace WebCore |
OLD | NEW |