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

Side by Side Diff: third_party/WebKit/Source/build/scripts/templates/ComputedStyleBase.h.tmpl

Issue 2693933003: Move field-dependent code in ComputedStyleBase to Jinja macros. (Closed)
Patch Set: Rebase Created 3 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
OLDNEW
1 {% from 'macros.tmpl' import license, print_if %} 1 {% from 'macros.tmpl' import license, print_if %}
2 {{license()}} 2 {{license()}}
3 3
4 #ifndef ComputedStyleBase_h 4 #ifndef ComputedStyleBase_h
5 #define ComputedStyleBase_h 5 #define ComputedStyleBase_h
6 6
7 #include "core/ComputedStyleBaseConstants.h" 7 #include "core/ComputedStyleBaseConstants.h"
8 #include "core/CoreExport.h" 8 #include "core/CoreExport.h"
9 {% for path in include_paths %} 9 {% for path in include_paths %}
10 #include "{{path}}" 10 #include "{{path}}"
11 {% endfor %} 11 {% endfor %}
12 12
13 {# Returns the default value for the field, converted to fit in the storage cont ainer. #} 13 {# Each field template has macros that we can call to generate specific
14 {% macro default_value(field) -%} 14 aspects of the field (e.g. getters, setters).
15 {# We only support enum fields for now. #} 15 #}
16 static_cast<unsigned>({{field.default_value}}) 16 {% import 'fields/keyword.tmpl' as keyword %}
17 {%- endmacro %} 17 {% import 'fields/flag.tmpl' as flag %}
18 {% import 'fields/monotonic_flag.tmpl' as monotonic_flag %}
19 {% set field_templates = { 'keyword': keyword, 'flag': flag, 'monotonic_flag': m onotonic_flag } %}
18 20
19 namespace blink { 21 namespace blink {
20 22
21 // The generated portion of ComputedStyle. For more info, see the header comment 23 // The generated portion of ComputedStyle. For more info, see the header comment
22 // in ComputedStyle.h. 24 // in ComputedStyle.h.
23 class CORE_EXPORT ComputedStyleBase { 25 class CORE_EXPORT ComputedStyleBase {
24 public: 26 public:
25 ALWAYS_INLINE ComputedStyleBase() : 27 ALWAYS_INLINE ComputedStyleBase() :
26 {% for field in fields %} 28 {% for field in fields %}
27 {{field.name}}({{default_value(field)}}){{print_if(not loop.last, ',')}} 29 {{field.name}}(static_cast<unsigned>({{field.default_value}})){{print_if(n ot loop.last, ',')}}
28 {% endfor %} 30 {% endfor %}
29 {} 31 {}
30 ~ComputedStyleBase() {} 32 ~ComputedStyleBase() {}
31 33
32 ALWAYS_INLINE ComputedStyleBase(const ComputedStyleBase& o) : 34 ALWAYS_INLINE ComputedStyleBase(const ComputedStyleBase& o) :
33 {% for field in fields %} 35 {% for field in fields %}
34 {{field.name}}(o.{{field.name}}){{print_if(not loop.last, ',')}} 36 {{field.name}}(o.{{field.name}}){{print_if(not loop.last, ',')}}
35 {% endfor %} 37 {% endfor %}
36 {} 38 {}
37 39
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 // style that are marked as inherited by this style. 82 // style that are marked as inherited by this style.
81 void propagateIndependentInheritedProperties( 83 void propagateIndependentInheritedProperties(
82 const ComputedStyleBase& parentStyle); 84 const ComputedStyleBase& parentStyle);
83 85
84 // Fields. 86 // Fields.
85 // TODO(sashab): Remove initialFoo() static methods and update callers to 87 // TODO(sashab): Remove initialFoo() static methods and update callers to
86 // use resetFoo(), which can be more efficient. 88 // use resetFoo(), which can be more efficient.
87 89
88 {% for field in fields %} 90 {% for field in fields %}
89 // {{field.property_name}} 91 // {{field.property_name}}
90 inline static {{field.type_name}} {{field.initial_method_name}}() { 92 {{field_templates[field.field_template].decl_methods(field)|indent(2)}}
91 return {{field.default_value}};
92 }
93 {{field.type_name}} {{field.getter_method_name}}() const {
94 return static_cast<{{field.type_name}}>({{field.name}});
95 }
96 {% if field.is_nonproperty %}
97 void {{field.setter_method_name}}() {
98 {{field.name}} = static_cast<unsigned>(true);
99 }
100 {% else %}
101 void {{field.setter_method_name}}({{field.type_name}} v) {
102 {{field.name}} = static_cast<unsigned>(v);
103 }
104 {% endif %}
105 inline void {{field.resetter_method_name}}() {
106 {{field.name}} = {{default_value(field)}};
107 }
108 93
109 {% endfor %} 94 {% endfor %}
110 protected: 95 protected:
111 // Storage. 96 // Storage.
112 {% for field in fields %} 97 {% for field in fields %}
113 unsigned {{field.name}} : {{field.size}}; // {{field.type_name}} 98 unsigned {{field.name}} : {{field.size}}; // {{field.type_name}}
114 {% endfor %} 99 {% endfor %}
115 }; 100 };
116 101
117 } // namespace blink 102 } // namespace blink
118 103
119 #endif // ComputedStyleBase_h 104 #endif // ComputedStyleBase_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698