1 {% from "macros.tmpl" import license %}
4 #ifndef {{namespace}}ElementTypeHelpers_h
5 #define {{namespace}}ElementTypeHelpers_h
7 #include "core/dom/Element.h"
8 #include "{{namespace}}Names.h"
9 #include "platform/RuntimeEnabledFeatures.h"
13 {% for tag in tags|sort if not tag.multipleTagNames and not tag.noTypeHelpers %}
14 {% filter enable_conditional(tag.Conditional) %}
15 class {{tag.interface}};
16 void is{{tag.interface}}(const {{tag.interface}}&); // Catch unnecessary runtime check of type known at compile time.
17 void is{{tag.interface}}(const {{tag.interface}}*); // Catch unnecessary runtime check of type known at compile time.
19 inline bool is{{tag.interface}}(const {{namespace}}Element& element) {
20 {% if tag.runtimeEnabled %}
21 if (!RuntimeEnabledFeatures::{{tag.runtimeEnabled}}Enabled())
24 return element.hasTagName({{namespace}}Names::{{tag|symbol}}Tag);
26 inline bool is{{tag.interface}}(const {{namespace}}Element* element) { return element && is{{tag.interface}}(*element); }
27 template<typename T> inline bool is{{tag.interface}}(const PassRefPtr<T>& node) { return is{{tag.interface}}(node.get()); }
28 template<typename T> inline bool is{{tag.interface}}(const RefPtr<T>& node) { return is{{tag.interface}}(node.get()); }
29 inline bool is{{tag.interface}}(const Node& node) { return node.is{{namespace}}Element() && is{{tag.interface}}(to{{namespace}}Element(node)); }
30 inline bool is{{tag.interface}}(const Node* node) { return node && is{{tag.interface}}(*node); }
31 template <> inline bool isElementOfType<const {{tag.interface}}>(const Node& node) { return is{{tag.interface}}(node); }
32 template <> inline bool isElementOfType<const {{tag.interface}}>(const {{namespace}}Element& element) { return is{{tag.interface}}(element); }
36 // Using macros because the types are forward-declared and we don't want to use reinterpret_cast in the
37 // casting functions above. reinterpret_cast would be unsafe due to multiple inheritence.
39 {% for tag in tags|sort if not tag.multipleTagNames and not tag.noTypeHelpers %}
40 {% filter enable_conditional(tag.Conditional) %}
41 #define to{{tag.interface}}(x) blink::toElement<blink::{{tag.interface}}>(x)