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

Unified Diff: Source/build/scripts/templates/ElementFactory.cpp.tmpl

Issue 27009005: Generate HTMLElementFactory with Python (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Actually use the code Created 7 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/build/scripts/name_utilities.py ('k') | Source/build/scripts/templates/ElementFactory.h.tmpl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/build/scripts/templates/ElementFactory.cpp.tmpl
diff --git a/Source/build/scripts/templates/ElementFactory.cpp.tmpl b/Source/build/scripts/templates/ElementFactory.cpp.tmpl
new file mode 100644
index 0000000000000000000000000000000000000000..6f2bd4e682abf66f281923edaff8bb47ca53a15b
--- /dev/null
+++ b/Source/build/scripts/templates/ElementFactory.cpp.tmpl
@@ -0,0 +1,92 @@
+{% from "macros.tmpl" import license -%}
+{{ license() }}
+
+#include "config.h"
+#include "{{namespace}}ElementFactory.h"
+
+#include "RuntimeEnabledFeatures.h"
+#include "{{namespace}}Names.h"
+{%- for tag in tags|sort %}
+#include "core/{{namespace|lower}}/{{tag|interface}}.h"
+{%- endfor %}
+{%- if fallback_interface %}
+#include "core/{{namespace|lower}}/{{fallback_interface}}.h"
+{%- endif %}
+#include "core/dom/ContextFeatures.h"
+#include "core/dom/custom/CustomElement.h"
+#include "core/dom/custom/CustomElementRegistrationContext.h"
+#include "core/dom/Document.h"
+#include "core/page/Settings.h"
+#include "wtf/HashMap.h"
+
+namespace WebCore {
+
+using namespace {{namespace}}Names;
+
+typedef PassRefPtr<{{namespace}}Element> (*ConstructorFunction)(const QualifiedName&, Document&, HTMLFormElement*, bool createdByParser);
+typedef HashMap<StringImpl*, ConstructorFunction> FunctionMap;
+
+static FunctionMap* g_constructors = 0;
+
+{%- for tag in tags|sort if not tag.mapToTagName and not tag.noConstructor %}
+static PassRefPtr<{{namespace}}Element> {{tag|symbol}}Constructor(const QualifiedName& tagName, Document& document, HTMLFormElement* formElement, bool createdByParser)
+{
+{%- if tag.wrapperOnlyIfMediaIsAvailable %}
+ Settings* settings = document.settings();
+ if (!RuntimeEnabledFeatures::mediaEnabled() || (settings && !settings->mediaEnabled()))
+ return 0;
+{%- endif %}
+{%- if tag.contextConditional %}
+ if (!ContextFeatures::{{tag.contextConditional}}Enabled(&document))
+ return 0;
+{%- endif %}
+ return {{tag|interface}}::create(tagName, document
+{%- if tag.constructorNeedsFormElement %}, formElement{% endif -%}
+{%- if tag.constructorNeedsCreatedByParser %}, createdByParser{% endif -%}
+ );
+}
+{%- endfor %}
+
+{%- for tag in tags|sort if tag.mapToTagName %}
+static PassRefPtr<HTMLElement> {{tag|symbol}}Constructor(const QualifiedName& tagName, Document& document, HTMLFormElement* formElement, bool createdByParser)
+{
+ return {{tag.mapToTagName}}Constructor(QualifiedName(tagName.prefix(), {{tag.mapToTagName}}Tag.localName(), tagName.namespaceURI()), document, formElement, createdByParser);
+}
+{%- endfor %}
+
+static void addTag(const QualifiedName& tag, ConstructorFunction func)
+{
+ g_constructors->set(tag.localName().impl(), func);
+}
+
+static void createFunctionMap()
+{
+ ASSERT(!g_constructors);
+ g_constructors = new FunctionMap;
+{%- for tag in tags|sort if not tag.noConstructor %}
+ addTag({{tag|symbol}}Tag, {{tag|symbol}}Constructor);
+{%- endfor %}
+}
+
+PassRefPtr<{{namespace}}Element> {{namespace}}ElementFactory::create{{namespace}}Element(const QualifiedName& qName, Document* document, HTMLFormElement* formElement, bool createdByParser)
+{
+ if (!document)
+ return 0;
+
+ if (CustomElement::isValidName(qName.localName()) && document->registrationContext()) {
+ RefPtr<Element> element = document->registrationContext()->createCustomTagElement(*document, qName, createdByParser ? CustomElementRegistrationContext::CreatedByParser : CustomElementRegistrationContext::NotCreatedByParser);
+ ASSERT_WITH_SECURITY_IMPLICATION(element->is{{namespace}}Element());
+ return static_pointer_cast<{{namespace}}Element>(element.release());
+ }
+
+ if (!g_constructors)
+ createFunctionMap();
+ if (ConstructorFunction function = g_constructors->get(qName.localName().impl())) {
+ if (PassRefPtr<{{namespace}}Element> element = function(qName, *document, formElement, createdByParser))
+ return element;
+ }
+
+ return {{fallback_interface}}::create(qName, *document);
+}
+
+} // namespace WebCore
« no previous file with comments | « Source/build/scripts/name_utilities.py ('k') | Source/build/scripts/templates/ElementFactory.h.tmpl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698