OLD | NEW |
1 {% from "macros.tmpl" import license %} | 1 {% from "macros.tmpl" import license %} |
2 {{ license() }} | 2 {{ license() }} |
3 | 3 |
4 #ifndef {{namespace}}ElementTypeHelpers_h | 4 #ifndef {{namespace}}ElementTypeHelpers_h |
5 #define {{namespace}}ElementTypeHelpers_h | 5 #define {{namespace}}ElementTypeHelpers_h |
6 | 6 |
7 #include "core/dom/Element.h" | 7 #include "core/dom/Element.h" |
8 #include "{{namespace}}Names.h" | 8 #include "{{namespace}}Names.h" |
9 #include "platform/RuntimeEnabledFeatures.h" | 9 #include "platform/RuntimeEnabledFeatures.h" |
10 | 10 |
11 namespace blink { | 11 namespace blink { |
12 // Type checking. | 12 // Type checking. |
13 {% for tag in tags|sort if not tag.multipleTagNames and not tag.noTypeHelpers %} | 13 {% for tag in tags|sort if not tag.multipleTagNames and not tag.noTypeHelpers %} |
14 class {{tag.interface}}; | 14 class {{tag.interface}}; |
15 void is{{tag.interface}}(const {{tag.interface}}&); // Catch unnecessary runtime
check of type known at compile time. | 15 void is{{tag.interface}}(const {{tag.interface}}&); // Catch unnecessary runtime
check of type known at compile time. |
16 void is{{tag.interface}}(const {{tag.interface}}*); // Catch unnecessary runtime
check of type known at compile time. | 16 void is{{tag.interface}}(const {{tag.interface}}*); // Catch unnecessary runtime
check of type known at compile time. |
17 | 17 |
18 inline bool is{{tag.interface}}(const {{namespace}}Element& element) { | 18 inline bool is{{tag.interface}}(const {{namespace}}Element& element) { |
19 {% if tag.runtimeEnabled %} | 19 {% if tag.runtimeEnabled %} |
20 if (!RuntimeEnabledFeatures::{{tag.runtimeEnabled}}Enabled()) | 20 if (!RuntimeEnabledFeatures::{{tag.runtimeEnabled}}Enabled()) |
21 return false; | 21 return false; |
22 {% endif %} | 22 {% endif %} |
23 return element.hasTagName({{namespace}}Names::{{tag|symbol}}Tag); | 23 return element.hasTagName({{namespace}}Names::{{tag|symbol}}Tag); |
24 } | 24 } |
25 inline bool is{{tag.interface}}(const {{namespace}}Element* element) { return el
ement && is{{tag.interface}}(*element); } | 25 inline bool is{{tag.interface}}(const {{namespace}}Element* element) { return el
ement && is{{tag.interface}}(*element); } |
26 template<typename T> inline bool is{{tag.interface}}(const PassRefPtr<T>& node)
{ return is{{tag.interface}}(node.get()); } | |
27 template<typename T> inline bool is{{tag.interface}}(const RefPtr<T>& node) { re
turn is{{tag.interface}}(node.get()); } | |
28 inline bool is{{tag.interface}}(const Node& node) { return node.is{{namespace}}E
lement() && is{{tag.interface}}(to{{namespace}}Element(node)); } | 26 inline bool is{{tag.interface}}(const Node& node) { return node.is{{namespace}}E
lement() && is{{tag.interface}}(to{{namespace}}Element(node)); } |
29 inline bool is{{tag.interface}}(const Node* node) { return node && is{{tag.inter
face}}(*node); } | 27 inline bool is{{tag.interface}}(const Node* node) { return node && is{{tag.inter
face}}(*node); } |
30 template <> inline bool isElementOfType<const {{tag.interface}}>(const Node& nod
e) { return is{{tag.interface}}(node); } | 28 template <> inline bool isElementOfType<const {{tag.interface}}>(const Node& nod
e) { return is{{tag.interface}}(node); } |
31 template <> inline bool isElementOfType<const {{tag.interface}}>(const {{namespa
ce}}Element& element) { return is{{tag.interface}}(element); } | 29 template <> inline bool isElementOfType<const {{tag.interface}}>(const {{namespa
ce}}Element& element) { return is{{tag.interface}}(element); } |
32 | 30 |
33 {% endfor %} | 31 {% endfor %} |
34 // Using macros because the types are forward-declared and we don't want to use
reinterpret_cast in the | 32 // Using macros because the types are forward-declared and we don't want to use
reinterpret_cast in the |
35 // casting functions above. reinterpret_cast would be unsafe due to multiple inh
eritence. | 33 // casting functions above. reinterpret_cast would be unsafe due to multiple inh
eritence. |
36 | 34 |
37 {% for tag in tags|sort if not tag.multipleTagNames and not tag.noTypeHelpers %} | 35 {% for tag in tags|sort if not tag.multipleTagNames and not tag.noTypeHelpers %} |
38 #define to{{tag.interface}}(x) blink::toElement<blink::{{tag.interface}}>(x) | 36 #define to{{tag.interface}}(x) blink::toElement<blink::{{tag.interface}}>(x) |
39 {% endfor %} | 37 {% endfor %} |
40 } // namespace blink | 38 } // namespace blink |
41 | 39 |
42 #endif | 40 #endif |
OLD | NEW |