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

Unified Diff: Source/build/scripts/templates/ElementTypeHelpers.h.tmpl

Issue 195993009: Generate better isFooElement() helper functions for HTML Elements (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 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 | « no previous file | Source/core/html/HTMLElement.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/build/scripts/templates/ElementTypeHelpers.h.tmpl
diff --git a/Source/build/scripts/templates/ElementTypeHelpers.h.tmpl b/Source/build/scripts/templates/ElementTypeHelpers.h.tmpl
index e4b9fab6d67522b34089e48893b9e76fef01c17c..623877e7e73be873d5d64bfac8e5c3d83690f174 100644
--- a/Source/build/scripts/templates/ElementTypeHelpers.h.tmpl
+++ b/Source/build/scripts/templates/ElementTypeHelpers.h.tmpl
@@ -15,6 +15,21 @@ namespace WebCore {
class {{tag.interface}};
void is{{tag.interface}}(const {{tag.interface}}&); // Catch unnecessary runtime check of type known at compile time.
void is{{tag.interface}}(const {{tag.interface}}*); // Catch unnecessary runtime check of type known at compile time.
+
+{# For HTML Elements, call hasLocalName() instead of hasTagName() to avoid checking the namespace unnecessarily #}
+{%- if namespace == "HTML" -%}
+inline bool is{{tag.interface}}(const HTMLElement& element) {
+{%- if tag.runtimeEnabled or tag.contextConditional %}
+ if (element.isHTMLUnknownElement())
+ return false;
+{%- endif %}
+ return element.hasLocalName(HTMLNames::{{tag|symbol}}Tag);
+}
+inline bool is{{tag.interface}}(const Element& element) {
+ return element.isHTMLElement() && is{{tag.interface}}(toHTMLElement(element));
+}
+inline bool is{{tag.interface}}(const HTMLElement* element) { return element && is{{tag.interface}}(*element); }
+{% else %}
inline bool is{{tag.interface}}(const Element& element) {
{%- if tag.contextConditional %}
if (!ContextFeatures::{{tag.contextConditional}}Enabled(&element.document()))
@@ -26,12 +41,18 @@ inline bool is{{tag.interface}}(const Element& element) {
{%- endif %}
return element.hasTagName({{namespace}}Names::{{tag|symbol}}Tag);
}
+{%- endif -%}
+
inline bool is{{tag.interface}}(const Element* element) { return element && is{{tag.interface}}(*element); }
template<typename T> inline bool is{{tag.interface}}(const PassRefPtr<T>& node) { return is{{tag.interface}}(node.get()); }
template<typename T> inline bool is{{tag.interface}}(const RefPtr<T>& node) { return is{{tag.interface}}(node.get()); }
inline bool is{{tag.interface}}(const Node& node) { return node.isElementNode() ? is{{tag.interface}}(toElement(node)) : false; }
inline bool is{{tag.interface}}(const Node* node) { return node && node->isElementNode() ? is{{tag.interface}}(*toElement(node)) : false; }
template <> inline bool isElementOfType<const {{tag.interface}}>(const Element& element) { return is{{tag.interface}}(element); }
+{%- if namespace == "HTML" %}
+template <> inline bool isElementOfType<const {{tag.interface}}>(const HTMLElement& element) { return is{{tag.interface}}(element); }
+{%- endif %}
+
{% endfor %}
// Using macros because the types are forward-declared and we don't want to use reinterpret_cast in the
« no previous file with comments | « no previous file | Source/core/html/HTMLElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698