Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(339)

Unified Diff: Source/build/scripts/templates/ElementTypeHelpers.h.tmpl

Issue 182583002: Revert of Add template parameter to ElementTraversal to iterate over Elements of a specific type (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Source/core/core.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/build/scripts/templates/ElementTypeHelpers.h.tmpl
diff --git a/Source/build/scripts/templates/ElementTypeHelpers.h.tmpl b/Source/build/scripts/templates/ElementTypeHelpers.h.tmpl
index 91758aa6e889d33a584bb2efb6a3ad4de8dc5967..dd9ad85645640c9e8be60b113676fff220ea6b6b 100644
--- a/Source/build/scripts/templates/ElementTypeHelpers.h.tmpl
+++ b/Source/build/scripts/templates/ElementTypeHelpers.h.tmpl
@@ -31,6 +31,28 @@
inline bool is{{tag.interface}}(const Node* node) { ASSERT(node); return node->isElementNode() ? is{{tag.interface}}(*toElement(node)) : false; }
template <> inline bool isElementOfType<const {{tag.interface}}>(const Element& element) { return is{{tag.interface}}(element); }
{% endfor %}
+// Type casting.
+template<typename T> inline T& toElement(Node& node)
+{
+ ASSERT_WITH_SECURITY_IMPLICATION(isElementOfType<const T>(node));
+ return static_cast<T&>(node);
+}
+template<typename T> inline T* toElement(Node* node)
+{
+ ASSERT_WITH_SECURITY_IMPLICATION(!node || isElementOfType<const T>(*node));
+ return static_cast<T*>(node);
+}
+template<typename T> inline const T& toElement(const Node& node)
+{
+ ASSERT_WITH_SECURITY_IMPLICATION(isElementOfType<const T>(node));
+ return static_cast<const T&>(node);
+}
+template<typename T> inline const T* toElement(const Node* node)
+{
+ ASSERT_WITH_SECURITY_IMPLICATION(!node || isElementOfType<const T>(*node));
+ return static_cast<const T*>(node);
+}
+template<typename T, typename U> inline T* toElement(const RefPtr<U>& node) { return toElement<T>(node.get()); }
// Using macros because the types are forward-declared and we don't want to use reinterpret_cast in the
// casting functions above. reinterpret_cast would be unsafe due to multiple inheritence.
« no previous file with comments | « no previous file | Source/core/core.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698