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

Side by Side Diff: Source/build/scripts/templates/ElementTypeHelpers.h.tmpl

Issue 192293002: Use new is*Element() helper functions in DOM code (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/core/dom/ContainerNode.cpp » ('j') | Source/core/dom/ContainerNode.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
OLDNEW
« no previous file with comments | « no previous file | Source/core/dom/ContainerNode.cpp » ('j') | Source/core/dom/ContainerNode.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698