Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / build / scripts / templates / ElementTypeHelpers.h.tmpl
1 {% from "macros.tmpl" import license %}
2 {{ license() }}
3
4 #ifndef {{namespace}}ElementTypeHelpers_h
5 #define {{namespace}}ElementTypeHelpers_h
6
7 #include "core/dom/Element.h"
8 #include "{{namespace}}Names.h"
9 #include "platform/RuntimeEnabledFeatures.h"
10
11 namespace blink {
12 // Type checking.
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.
18
19 inline bool is{{tag.interface}}(const {{namespace}}Element& element) {
20     {% if tag.runtimeEnabled %}
21     if (!RuntimeEnabledFeatures::{{tag.runtimeEnabled}}Enabled())
22         return false;
23     {% endif %}
24     return element.hasTagName({{namespace}}Names::{{tag|symbol}}Tag);
25 }
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); }
33 {% endfilter %}
34
35 {% endfor %}
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.
38
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)
42 {% endfilter %}
43 {% endfor %}
44 } // namespace blink
45
46 #endif