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" |
(...skipping 13 matching lines...) Expand all Loading... |
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.name}}Tag); | 27 return element.hasTagName({{namespace}}Names::{{tag.name}}Tag); |
28 } | 28 } |
29 inline bool is{{tag.interface}}(const Element* element) { ASSERT(element); retur
n is{{tag.interface}}(*element); } | 29 inline bool is{{tag.interface}}(const Element* element) { ASSERT(element); retur
n is{{tag.interface}}(*element); } |
30 inline bool is{{tag.interface}}(const Node& node) { return node.isElementNode()
? is{{tag.interface}}(toElement(node)) : false; } | 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) { ASSERT(node); return node->i
sElementNode() ? is{{tag.interface}}(*toElement(node)) : false; } | 31 inline bool is{{tag.interface}}(const Node* node) { ASSERT(node); return node->i
sElementNode() ? is{{tag.interface}}(*toElement(node)) : false; } |
32 template <> inline bool isElementOfType<const {{tag.interface}}>(const Element&
element) { return is{{tag.interface}}(element); } | 32 template <> inline bool isElementOfType<const {{tag.interface}}>(const Element&
element) { return is{{tag.interface}}(element); } |
33 {% endfor %} | 33 {% endfor %} |
34 // Type casting. | |
35 template<typename T> inline T& toElement(Node& node) | |
36 { | |
37 ASSERT_WITH_SECURITY_IMPLICATION(isElementOfType<const T>(node)); | |
38 return static_cast<T&>(node); | |
39 } | |
40 template<typename T> inline T* toElement(Node* node) | |
41 { | |
42 ASSERT_WITH_SECURITY_IMPLICATION(!node || isElementOfType<const T>(*node)); | |
43 return static_cast<T*>(node); | |
44 } | |
45 template<typename T> inline const T& toElement(const Node& node) | |
46 { | |
47 ASSERT_WITH_SECURITY_IMPLICATION(isElementOfType<const T>(node)); | |
48 return static_cast<const T&>(node); | |
49 } | |
50 template<typename T> inline const T* toElement(const Node* node) | |
51 { | |
52 ASSERT_WITH_SECURITY_IMPLICATION(!node || isElementOfType<const T>(*node)); | |
53 return static_cast<const T*>(node); | |
54 } | |
55 template<typename T, typename U> inline T* toElement(const RefPtr<U>& node) { re
turn toElement<T>(node.get()); } | |
56 | 34 |
57 // Using macros because the types are forward-declared and we don't want to use
reinterpret_cast in the | 35 // Using macros because the types are forward-declared and we don't want to use
reinterpret_cast in the |
58 // casting functions above. reinterpret_cast would be unsafe due to multiple inh
eritence. | 36 // casting functions above. reinterpret_cast would be unsafe due to multiple inh
eritence. |
59 {% for tag in tags|sort if not tag.multipleTagNames %} | 37 {% for tag in tags|sort if not tag.multipleTagNames %} |
60 #define to{{tag.interface}}(x) WebCore::toElement<WebCore::{{tag.interface}}>(x) | 38 #define to{{tag.interface}}(x) WebCore::toElement<WebCore::{{tag.interface}}>(x) |
61 {% endfor %} | 39 {% endfor %} |
62 } // WebCore | 40 } // WebCore |
63 | 41 |
64 #endif | 42 #endif |
OLD | NEW |