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

Side by Side Diff: third_party/WebKit/Source/build/scripts/make_computed_style_base.py

Issue 2904483003: Replace "field_type_path" with "include_paths" in CSSProperties.json5. (Closed)
Patch Set: Rebase Created 3 years, 7 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/build/scripts/make_css_value_id_mappings.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2016 The Chromium Authors. All rights reserved. 2 # Copyright 2016 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import math 6 import math
7 import sys 7 import sys
8 8
9 import json5_generator 9 import json5_generator
10 import template_expander 10 import template_expander
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 # If the size of the field is not None, it means it is a bit field 161 # If the size of the field is not None, it means it is a bit field
162 self.is_bit_field = self.size is not None 162 self.is_bit_field = self.size is not None
163 163
164 assert len(kwargs) == 0, 'Unexpected arguments provided to Field: ' + st r(kwargs) 164 assert len(kwargs) == 0, 'Unexpected arguments provided to Field: ' + st r(kwargs)
165 165
166 166
167 def _get_include_paths(properties): 167 def _get_include_paths(properties):
168 """ 168 """
169 Get a list of paths that need to be included for ComputedStyleBase. 169 Get a list of paths that need to be included for ComputedStyleBase.
170 """ 170 """
171 include_paths = set() 171 return list(sorted(set(_flatten_list(property_['include_paths'] for property _ in properties))))
meade_UTC10 2017/05/26 01:20:18 uh, is there a way that the data can be structured
172 for property_ in properties:
173 if property_['field_type_path'] is not None:
174 include_paths.add(property_['field_type_path'] + '.h')
175 return list(sorted(include_paths))
176 172
177 173
178 def _group_fields(fields): 174 def _group_fields(fields):
179 """Groups a list of fields by their group_name and returns the root group."" " 175 """Groups a list of fields by their group_name and returns the root group."" "
180 groups = defaultdict(list) 176 groups = defaultdict(list)
181 for field in fields: 177 for field in fields:
182 groups[field.group_name].append(field) 178 groups[field.group_name].append(field)
183 179
184 no_group = groups.pop(None) 180 no_group = groups.pop(None)
185 subgroups = [Group(group_name, [], _reorder_fields(fields)) for group_name, fields in groups.items()] 181 subgroups = [Group(group_name, [], _reorder_fields(fields)) for group_name, fields in groups.items()]
(...skipping 29 matching lines...) Expand all
215 diff_group.expressions.append(entry['method']) 211 diff_group.expressions.append(entry['method'])
216 return diff_group 212 return diff_group
217 213
218 214
219 def _create_enums(properties): 215 def _create_enums(properties):
220 """ 216 """
221 Returns an OrderedDict of enums to be generated, enum name -> [list of enum values] 217 Returns an OrderedDict of enums to be generated, enum name -> [list of enum values]
222 """ 218 """
223 enums = {} 219 enums = {}
224 for property_ in properties: 220 for property_ in properties:
225 # Only generate enums for keyword properties that use the default field_ type_path. 221 # Only generate enums for keyword properties that do not require include s.
226 if property_['field_template'] == 'keyword' and property_['field_type_pa th'] is None: 222 if property_['field_template'] == 'keyword' and len(property_['include_p aths']) == 0:
227 enum_name = property_['type_name'] 223 enum_name = property_['type_name']
228 enum_values = [enum_value_name(k) for k in property_['keywords']] 224 enum_values = [enum_value_name(k) for k in property_['keywords']]
229 225
230 if enum_name in enums: 226 if enum_name in enums:
231 # There's an enum with the same name, check if the enum values a re the same 227 # There's an enum with the same name, check if the enum values a re the same
232 assert set(enums[enum_name]) == set(enum_values), \ 228 assert set(enums[enum_name]) == set(enum_values), \
233 ("'" + property_['name'] + "' can't have type_name '" + enum _name + "' " 229 ("'" + property_['name'] + "' can't have type_name '" + enum _name + "' "
234 "because it was used by a previous property, but with a dif ferent set of keywords. " 230 "because it was used by a previous property, but with a dif ferent set of keywords. "
235 "Either give it a different name or ensure the keywords are the same.") 231 "Either give it a different name or ensure the keywords are the same.")
236 232
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 extra_fields = json5_generator.Json5File.load_from_files( 398 extra_fields = json5_generator.Json5File.load_from_files(
403 [json5_file_paths[1]], 399 [json5_file_paths[1]],
404 default_parameters=self.json5_file.parameters 400 default_parameters=self.json5_file.parameters
405 ).name_dictionaries 401 ).name_dictionaries
406 402
407 for property_ in extra_fields: 403 for property_ in extra_fields:
408 make_style_builder.apply_property_naming_defaults(property_) 404 make_style_builder.apply_property_naming_defaults(property_)
409 405
410 all_properties = css_properties + extra_fields 406 all_properties = css_properties + extra_fields
411 407
412 # Override the type name when field_type_path is specified
413 for property_ in all_properties:
414 if property_['field_type_path']:
415 property_['type_name'] = property_['field_type_path'].split('/') [-1]
416
417 self._generated_enums = _create_enums(all_properties) 408 self._generated_enums = _create_enums(all_properties)
418 409
419 all_fields = _create_fields(all_properties) 410 all_fields = _create_fields(all_properties)
420 411
421 # Organise fields into a tree structure where the root group 412 # Organise fields into a tree structure where the root group
422 # is ComputedStyleBase. 413 # is ComputedStyleBase.
423 self._root_group = _group_fields(all_fields) 414 self._root_group = _group_fields(all_fields)
424 self._diff_functions_map = _create_diff_groups_map(json5_generator.Json5 File.load_from_files( 415 self._diff_functions_map = _create_diff_groups_map(json5_generator.Json5 File.load_from_files(
425 [json5_file_paths[2]] 416 [json5_file_paths[2]]
426 ).name_dictionaries, self._root_group) 417 ).name_dictionaries, self._root_group)
(...skipping 16 matching lines...) Expand all
443 434
444 @template_expander.use_jinja('ComputedStyleBaseConstants.h.tmpl') 435 @template_expander.use_jinja('ComputedStyleBaseConstants.h.tmpl')
445 def generate_base_computed_style_constants(self): 436 def generate_base_computed_style_constants(self):
446 return { 437 return {
447 'properties': self._properties, 438 'properties': self._properties,
448 'enums': self._generated_enums, 439 'enums': self._generated_enums,
449 } 440 }
450 441
451 if __name__ == '__main__': 442 if __name__ == '__main__':
452 json5_generator.Maker(ComputedStyleBaseWriter).main() 443 json5_generator.Maker(ComputedStyleBaseWriter).main()
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/build/scripts/make_css_value_id_mappings.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698