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

Unified Diff: third_party/WebKit/Source/build/scripts/templates/ElementTypeHelpers.cpp.tmpl

Issue 2419383002: Add function to check what HTML Element interface corresponds to a given tag name. (Closed)
Patch Set: Made changes Created 4 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
Index: third_party/WebKit/Source/build/scripts/templates/ElementTypeHelpers.cpp.tmpl
diff --git a/third_party/WebKit/Source/build/scripts/templates/ElementTypeHelpers.cpp.tmpl b/third_party/WebKit/Source/build/scripts/templates/ElementTypeHelpers.cpp.tmpl
new file mode 100644
index 0000000000000000000000000000000000000000..9134e3e774af0e8ff163f2f31d6547e38c2dccd9
--- /dev/null
+++ b/third_party/WebKit/Source/build/scripts/templates/ElementTypeHelpers.cpp.tmpl
@@ -0,0 +1,42 @@
+{% from "macros.tmpl" import license %}
+{{ license() }}
+
+#include "{{namespace}}ElementTypeHelpers.h"
+
+#include "core/dom/Document.h"
+#include "platform/RuntimeEnabledFeatures.h"
+#include "wtf/HashMap.h"
+
+namespace blink {
+{% if namespace == "HTML" %}
+using HTMLTypeMap = HashMap<AtomicString, HTMLElementType>;
+
+static HTMLTypeMap* html_type_map = 0;
+
+void createHTMLTypeMap() {
+ DCHECK(!html_type_map);
+ html_type_map = new HTMLTypeMap;
+ {% for tag in tags|sort %}
+ html_type_map->set(AtomicString("{{tag.name}}"), HTMLElementType::k{{tag.interface}});
+ {% endfor %}
+}
+
+HTMLElementType htmlElementTypeForTag(const AtomicString& tagName) {
+ if (!html_type_map) createHTMLTypeMap();
+ if (html_type_map->contains(tagName)) {
+ {% for tag in tags|sort %}
+ {% if tag.runtimeEnabled %}
+ if (tagName == "{{tag.name}}") {
+ if (!RuntimeEnabledFeatures::{{tag.runtimeEnabled}}Enabled()) {
+ return HTMLElementType::kHTMLUnknownElement;
+ }
+ }
+ {% endif %}
+ {% endfor %}
+ return html_type_map->get(tagName);
+ } else {
+ return HTMLElementType::kHTMLUnknownElement;
+ }
+}
+{% endif %}
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698