1 {% from "macros.tmpl" import license %}
4 #ifndef {{namespace}}ElementTypeHelpers_h
5 #define {{namespace}}ElementTypeHelpers_h
7 #include "core/dom/ContextFeatures.h"
8 #include "core/dom/Element.h"
9 #include "{{namespace}}Names.h"
10 #include "RuntimeEnabledFeatures.h"
14 {% for tag in tags|sort if not tag.multipleTagNames and not tag.noTypeHelpers %}
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 {# For HTML Elements, call hasLocalName() instead of hasTagName() to avoid checking the namespace unnecessarily #}
20 {% if namespace == 'HTML' %}
21 inline bool is{{tag.interface}}(const HTMLElement& element) {
22 {% if tag.runtimeEnabled or tag.contextConditional %}
23 if (element.isHTMLUnknownElement())
26 return element.hasLocalName(HTMLNames::{{tag|symbol}}Tag);
28 inline bool is{{tag.interface}}(const Element& element) {
29 return element.isHTMLElement() && is{{tag.interface}}(toHTMLElement(element));
31 inline bool is{{tag.interface}}(const HTMLElement* element) { return element && is{{tag.interface}}(*element); }
33 inline bool is{{tag.interface}}(const Element& element) {
34 {% if tag.contextConditional %}
35 if (!ContextFeatures::{{tag.contextConditional}}Enabled(&element.document()))
38 {% if tag.runtimeEnabled %}
39 if (!RuntimeEnabledFeatures::{{tag.runtimeEnabled}}Enabled())
42 return element.hasTagName({{namespace}}Names::{{tag|symbol}}Tag);
45 inline bool is{{tag.interface}}(const Element* element) { return element && is{{tag.interface}}(*element); }
46 template<typename T> inline bool is{{tag.interface}}(const PassRefPtr<T>& node) { return is{{tag.interface}}(node.get()); }
47 template<typename T> inline bool is{{tag.interface}}(const RefPtr<T>& node) { return is{{tag.interface}}(node.get()); }
48 inline bool is{{tag.interface}}(const Node& node) { return node.isElementNode() ? is{{tag.interface}}(toElement(node)) : false; }
49 inline bool is{{tag.interface}}(const Node* node) { return node && node->isElementNode() ? is{{tag.interface}}(*toElement(node)) : false; }
50 template <> inline bool isElementOfType<const {{tag.interface}}>(const Element& element) { return is{{tag.interface}}(element); }
51 {% if namespace == "HTML" %}
52 template <> inline bool isElementOfType<const {{tag.interface}}>(const HTMLElement& element) { return is{{tag.interface}}(element); }
56 // Using macros because the types are forward-declared and we don't want to use reinterpret_cast in the
57 // casting functions above. reinterpret_cast would be unsafe due to multiple inheritence.
59 {% for tag in tags|sort if not tag.multipleTagNames and not tag.noTypeHelpers %}
60 #define to{{tag.interface}}(x) WebCore::toElement<WebCore::{{tag.interface}}>(x)