OLD | NEW |
(Empty) | |
| 1 {% from "macros.tmpl" import license -%} |
| 2 {{ license() }} |
| 3 |
| 4 #ifndef {{namespace}}ElementTypeHelpers_h |
| 5 #define {{namespace}}ElementTypeHelpers_h |
| 6 |
| 7 #include "core/dom/ContextFeatures.h" |
| 8 #include "core/dom/Element.h" |
| 9 #include "{{namespace}}Names.h" |
| 10 #include "RuntimeEnabledFeatures.h" |
| 11 |
| 12 namespace WebCore { |
| 13 // Type checking. |
| 14 {% for tag in tags|sort if not tag.multipleTagNames %} |
| 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 inline bool is{{tag.interface}}(const Element& element) { |
| 19 {%- if tag.contextConditional %} |
| 20 if (!ContextFeatures::{{tag.contextConditional}}Enabled(&element.document())
) |
| 21 return false; |
| 22 {%- endif %} |
| 23 {%- if tag.runtimeEnabled %} |
| 24 if (!RuntimeEnabledFeatures::{{tag.runtimeEnabled}}Enabled()) |
| 25 return false; |
| 26 {%- endif %} |
| 27 return element.hasTagName({{namespace}}Names::{{tag.name}}Tag); |
| 28 } |
| 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; } |
| 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); } |
| 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 |
| 57 // 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. |
| 59 {% for tag in tags|sort if not tag.multipleTagNames %} |
| 60 #define to{{tag.interface}}(x) WebCore::toElement<WebCore::{{tag.interface}}>(x) |
| 61 {% endfor %} |
| 62 } // WebCore |
| 63 |
| 64 #endif |
OLD | NEW |