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/ContextFeatures.h" | 7 #include "core/dom/ContextFeatures.h" |
8 #include "core/dom/Element.h" | 8 #include "core/dom/Element.h" |
9 #include "{{namespace}}Names.h" | 9 #include "{{namespace}}Names.h" |
10 #include "RuntimeEnabledFeatures.h" | 10 #include "RuntimeEnabledFeatures.h" |
11 | 11 |
12 namespace WebCore { | 12 namespace WebCore { |
13 // Type checking. | 13 // Type checking. |
14 {% for tag in tags|sort if not tag.multipleTagNames and not tag.noTypeHelpers %} | 14 {% for tag in tags|sort if not tag.multipleTagNames and not tag.noTypeHelpers %} |
15 class {{tag.interface}}; | 15 class {{tag.interface}}; |
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 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 inline bool is{{tag.interface}}(const Element& element) { | 18 inline bool is{{tag.interface}}(const Element& element) { |
19 {%- if tag.contextConditional %} | 19 {%- if tag.contextConditional %} |
20 if (!ContextFeatures::{{tag.contextConditional}}Enabled(&element.document()) ) | 20 if (!ContextFeatures::{{tag.contextConditional}}Enabled(&element.document()) ) |
21 return false; | 21 return false; |
22 {%- endif %} | 22 {%- endif %} |
23 {%- if tag.runtimeEnabled %} | 23 {%- if tag.runtimeEnabled %} |
24 if (!RuntimeEnabledFeatures::{{tag.runtimeEnabled}}Enabled()) | 24 if (!RuntimeEnabledFeatures::{{tag.runtimeEnabled}}Enabled()) |
25 return false; | 25 return false; |
26 {%- endif %} | 26 {%- endif %} |
27 return element.hasTagName({{namespace}}Names::{{tag|symbol}}Tag); | 27 return element.hasTagName({{namespace}}Names::{{tag|symbol}}Tag); |
28 } | 28 } |
29 inline bool is{{tag.interface}}(const Element* element) { return element && is{{ tag.interface}}(*element); } | 29 inline bool is{{tag.interface}}(const Element* element) { return element && is{{ tag.interface}}(*element); } |
30 template<typename T> inline bool is{{tag.interface}}(const RefPtr<T>& node) { re turn is{{tag.interface}}(node.get()); } | |
adamk
2014/03/10 18:23:24
This seems possibly-dangerous, as passing a PassRe
Inactive
2014/03/10 18:28:29
You are right, I believe we had the exact same dis
| |
30 inline bool is{{tag.interface}}(const Node& node) { return node.isElementNode() ? is{{tag.interface}}(toElement(node)) : false; } | 31 inline bool is{{tag.interface}}(const Node& node) { return node.isElementNode() ? is{{tag.interface}}(toElement(node)) : false; } |
31 inline bool is{{tag.interface}}(const Node* node) { return node && node->isEleme ntNode() ? is{{tag.interface}}(*toElement(node)) : false; } | 32 inline bool is{{tag.interface}}(const Node* node) { return node && node->isEleme ntNode() ? is{{tag.interface}}(*toElement(node)) : false; } |
32 template <> inline bool isElementOfType<const {{tag.interface}}>(const Element& element) { return is{{tag.interface}}(element); } | 33 template <> inline bool isElementOfType<const {{tag.interface}}>(const Element& element) { return is{{tag.interface}}(element); } |
33 {% endfor %} | 34 {% endfor %} |
34 | 35 |
35 // Using macros because the types are forward-declared and we don't want to use reinterpret_cast in the | 36 // Using macros because the types are forward-declared and we don't want to use reinterpret_cast in the |
36 // casting functions above. reinterpret_cast would be unsafe due to multiple inh eritence. | 37 // casting functions above. reinterpret_cast would be unsafe due to multiple inh eritence. |
37 {% for tag in tags|sort if not tag.multipleTagNames and not tag.noTypeHelpers %} | 38 {% for tag in tags|sort if not tag.multipleTagNames and not tag.noTypeHelpers %} |
38 #define to{{tag.interface}}(x) WebCore::toElement<WebCore::{{tag.interface}}>(x) | 39 #define to{{tag.interface}}(x) WebCore::toElement<WebCore::{{tag.interface}}>(x) |
39 {% endfor %} | 40 {% endfor %} |
40 } // WebCore | 41 } // WebCore |
41 | 42 |
42 #endif | 43 #endif |
OLD | NEW |