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

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

Issue 2919343002: Remove template parameter on ComputedStyleBase. (Closed)
Patch Set: Address comments Created 3 years, 6 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 {% from 'fields/field.tmpl' import encode, getter_expression, setter_expression, declare_storage, fieldwise_compare, fieldwise_copy, fieldwise_diff, fieldwise_p ointer_compare_inherited %} 2 {% from 'fields/field.tmpl' import encode, getter_expression, setter_expression, declare_storage, fieldwise_compare, fieldwise_copy, fieldwise_diff, fieldwise_p ointer_compare_inherited %}
3 {% from 'fields/group.tmpl' import define_field_group_class %} 3 {% from 'fields/group.tmpl' import declare_field_group_class %}
4 {{license()}} 4 {{license()}}
5 5
6 #ifndef ComputedStyleBase_h 6 #ifndef ComputedStyleBase_h
7 #define ComputedStyleBase_h 7 #define ComputedStyleBase_h
8 8
9 #include "core/style/ComputedStyleConstants.h" 9 #include "core/style/ComputedStyleConstants.h"
10 #include "core/CoreExport.h" 10 #include "core/CoreExport.h"
11 #include "core/style/DataRef.h" 11 #include "core/style/DataRef.h"
12 #include "core/style/MemberCopy.h" 12 #include "core/style/MemberCopy.h"
13 #include "core/style/StyleDifference.h" 13 #include "core/style/StyleDifference.h"
(...skipping 15 matching lines...) Expand all
29 {% set field_templates = { 29 {% set field_templates = {
30 'keyword': keyword, 30 'keyword': keyword,
31 'primitive': primitive, 31 'primitive': primitive,
32 'monotonic_flag': monotonic_flag, 32 'monotonic_flag': monotonic_flag,
33 'storage_only': storage_only, 33 'storage_only': storage_only,
34 'external': external 34 'external': external
35 } %} 35 } %}
36 36
37 namespace blink { 37 namespace blink {
38 38
39 struct SameSizeAsComputedStyleBase { 39 // Forward declaration for diff functions.
40 {% if computed_style.subgroups is defined %} 40 class ComputedStyle;
41 void* dataRefs[{{computed_style.subgroups|length}}];
42 {% endif %}
43 {% for field in computed_style.fields|rejectattr("is_bit_field") %}
44 {{field.type_name}} {{field.name}};
45 {% endfor %}
46 unsigned m_bit_fields[{{computed_style.num_32_bit_words_for_bit_fields}}];
47 };
48 41
49 // The generated portion of ComputedStyle. For more info, see the header comment 42 // The generated portion of ComputedStyle. For more info, see the header comment
50 // in ComputedStyle.h. 43 // in ComputedStyle.h.
51 // 44 //
52 // ComputedStyleBase is a generated class that stores data members or 'fields' 45 // ComputedStyleBase is a generated class that stores data members or 'fields'
53 // used in ComputedStyle. These fields can represent CSS properties or internal 46 // used in ComputedStyle. These fields can represent CSS properties or internal
54 // style information. 47 // style information.
55 // 48 //
56 // STORAGE: 49 // STORAGE:
57 // 50 //
(...skipping 17 matching lines...) Expand all
75 // of all the flex box fields for every ComputedStyleBase. Similarly, when an 68 // of all the flex box fields for every ComputedStyleBase. Similarly, when an
76 // element inherits from its parent, its ComputedStyleBase can simply share all 69 // element inherits from its parent, its ComputedStyleBase can simply share all
77 // of its subgroups with the parent's. 70 // of its subgroups with the parent's.
78 // 71 //
79 // INTERFACE: 72 // INTERFACE:
80 // 73 //
81 // The functions generated for a field is determined by its 'template'. For 74 // The functions generated for a field is determined by its 'template'. For
82 // example, a field with the 'keyword' template has only one setter, whereas an 75 // example, a field with the 'keyword' template has only one setter, whereas an
83 // 'external' field has an extra setter that takes an rvalue reference. A list 76 // 'external' field has an extra setter that takes an rvalue reference. A list
84 // of the available templates can be found in CSSProperties.json5. 77 // of the available templates can be found in CSSProperties.json5.
85 //
86 // ComputedStyleBase is a template class to allow it to use functions on
87 // ComputedStyle. This allows ComputedStyleBase to use hand written functions it
88 // would otherwise not know about. It should only be templated with the
89 // ComputedStyle class and no other class is allowed.
90 template <class ComputedStyleFinal>
91 class CORE_EXPORT ComputedStyleBase { 78 class CORE_EXPORT ComputedStyleBase {
92 public: 79 public:
93 inline bool IndependentInheritedEqual(const ComputedStyleBase& o) const { 80 inline bool IndependentInheritedEqual(const ComputedStyleBase& o) const {
94 return ( 81 return (
95 {{fieldwise_compare(computed_style, computed_style.all_fields 82 {{fieldwise_compare(computed_style, computed_style.all_fields
96 |selectattr("is_property") 83 |selectattr("is_property")
97 |selectattr("is_inherited") 84 |selectattr("is_inherited")
98 |selectattr("is_independent") 85 |selectattr("is_independent")
99 |list 86 |list
100 )|indent(8)}} 87 )|indent(8)}}
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 true 122 true
136 ); 123 );
137 } 124 }
138 125
139 enum IsAtShadowBoundary { 126 enum IsAtShadowBoundary {
140 kAtShadowBoundary, 127 kAtShadowBoundary,
141 kNotAtShadowBoundary, 128 kNotAtShadowBoundary,
142 }; 129 };
143 130
144 void InheritFrom(const ComputedStyleBase& other, 131 void InheritFrom(const ComputedStyleBase& other,
145 IsAtShadowBoundary isAtShadowBoundary) { 132 IsAtShadowBoundary isAtShadowBoundary);
146 {{fieldwise_copy(computed_style, computed_style.all_fields
147 |selectattr("is_property")
148 |selectattr("is_inherited")
149 |list
150 )|indent(4)}}
151 }
152 133
153 void CopyNonInheritedFromCached( 134 void CopyNonInheritedFromCached(
154 const ComputedStyleBase& other) { 135 const ComputedStyleBase& other);
155 {{fieldwise_copy(computed_style, computed_style.all_fields
156 |rejectattr("has_custom_compare_and_copy")
157 |rejectattr("is_inherited")
158 |list
159 )|indent(4)}}
160 }
161 136
162 // Copies the values of any independent inherited properties from the parent 137 // Copies the values of any independent inherited properties from the parent
163 // style that are marked as inherited by this style. 138 // style that are marked as inherited by this style.
164 void PropagateIndependentInheritedProperties( 139 void PropagateIndependentInheritedProperties(
165 const ComputedStyleBase& parentStyle) { 140 const ComputedStyleBase& parentStyle);
166 {% for field in computed_style.all_fields if field.is_property and field.is_ independent %}
167 if ({{field.is_inherited_method_name}}())
168 {{setter_expression(field)}} = parentStyle.{{getter_expression(field)}};
169 {% endfor %}
170 }
171 141
172 {% for name, groups_to_diff in diff_functions_map.items() %} 142 {% for name, groups_to_diff in diff_functions_map.items() %}
173 bool {{name}}(const ComputedStyleFinal& other) const { 143 static bool {{name}}(const ComputedStyle& a, const ComputedStyle& b);
174 const ComputedStyleFinal& self = static_cast<const ComputedStyleFinal&>(*thi s);
175 {{fieldwise_diff(groups_to_diff)|indent(4)}}
176 return false;
177 }
178 {% endfor %} 144 {% endfor %}
179 145
180 // Fields. 146 // Fields.
181 // TODO(sashab): Remove initialFoo() static methods and update callers to 147 // TODO(sashab): Remove initialFoo() static methods and update callers to
182 // use resetFoo(), which can be more efficient. 148 // use resetFoo(), which can be more efficient.
183 149
184 {% for field in computed_style.all_fields|sort(attribute='name') %} 150 {% for field in computed_style.all_fields|sort(attribute='name') %}
185 // {{field.property_name}} 151 // {{field.property_name}}
186 {{field_templates[field.field_template].decl_public_methods(field)|indent(2)}} 152 {{field_templates[field.field_template].decl_public_methods(field)|indent(2)}}
187 153
188 {% endfor %} 154 {% endfor %}
189 private: 155 private:
190 {% for subgroup in computed_style.subgroups %} 156 {% for subgroup in computed_style.subgroups %}
191 {{define_field_group_class(subgroup)|indent(2)}} 157 {{declare_field_group_class(subgroup)|indent(2)}}
192 158
193 {% endfor %} 159 {% endfor %}
194 160
195 protected: 161 protected:
196 // Constructor and destructor are protected so that only the parent class Comp utedStyle 162 // Constructor and destructor are protected so that only the parent class Comp utedStyle
197 // can instantiate this class. 163 // can instantiate this class.
198 ALWAYS_INLINE ComputedStyleBase() : 164 ComputedStyleBase();
199 {% for field in computed_style.fields %}
200 {{field.name}}({{encode(field, field.default_value)}}){{print_if(not loop. last, ',')}}
201 {% endfor %}
202 {
203 static_assert(std::is_same<ComputedStyle, ComputedStyleFinal>::value, "Compu tedStyleBase can only be templated with ComputedStyle");
204 {% for subgroup in computed_style.subgroups %}
205 {{subgroup.member_name}}.Init();
206 {% endfor %}
207 }
208 165
209 {% for field in computed_style.all_fields|sort(attribute='name') %} 166 {% for field in computed_style.all_fields|sort(attribute='name') %}
210 {% if field.field_template in ('storage_only', 'monotonic_flag', 'external') % } 167 {% if field.field_template in ('storage_only', 'monotonic_flag', 'external') % }
211 // {{field.property_name}} 168 // {{field.property_name}}
212 {{field_templates[field.field_template].decl_protected_methods(field)|indent(2 )}} 169 {{field_templates[field.field_template].decl_protected_methods(field)|indent(2 )}}
213 170
214 {% endif %} 171 {% endif %}
215 {% endfor %} 172 {% endfor %}
216 173
217 ~ComputedStyleBase() = default; 174 ~ComputedStyleBase() = default;
218 175
219 // Storage. 176 // Storage.
220 {% for subgroup in computed_style.subgroups %} 177 {% for subgroup in computed_style.subgroups %}
221 DataRef<{{subgroup.type_name}}> {{subgroup.member_name}}; 178 DataRef<{{subgroup.type_name}}> {{subgroup.member_name}};
222 {% endfor %} 179 {% endfor %}
223 180
224 private: 181 private:
225 {% for field in computed_style.fields %} 182 {% for field in computed_style.fields %}
226 {{declare_storage(field)}} 183 {{declare_storage(field)}}
227 {% endfor %} 184 {% endfor %}
228 }; 185 };
229 186
230 } // namespace blink 187 } // namespace blink
231 188
232 #endif // ComputedStyleBase_h 189 #endif // ComputedStyleBase_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698