Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| 11 import make_style_builder | 11 import make_style_builder |
| 12 | 12 |
| 13 from name_utilities import ( | 13 from name_utilities import ( |
| 14 enum_for_css_keyword, enum_type_name, enum_value_name, class_member_name, me thod_name, | 14 enum_for_css_keyword, enum_type_name, enum_value_name, class_member_name, me thod_name, |
| 15 join_name | 15 join_name |
| 16 ) | 16 ) |
| 17 from collections import OrderedDict | 17 from collections import OrderedDict, defaultdict |
| 18 | 18 |
| 19 | 19 |
| 20 # Temporary hard-coded list of fields that are not CSS properties. | 20 # Temporary hard-coded list of fields that are not CSS properties. |
| 21 # TODO(shend): Put this into its own JSON5 file. | 21 # TODO(shend): Put this into its own JSON5 file. |
| 22 NONPROPERTIES = [ | 22 NONPROPERTIES = [ |
| 23 {'name': 'IsLink', 'field_template': 'monotonic_flag', | 23 {'name': 'IsLink', 'field_template': 'monotonic_flag', |
| 24 'inherited': False, 'independent': False, 'default_value': False}, | 24 'inherited': False, 'independent': False, 'default_value': False}, |
| 25 {'name': 'OriginalDisplay', 'field_template': 'keyword', 'default_value': 'i nline', | 25 {'name': 'OriginalDisplay', 'field_template': 'keyword', 'default_value': 'i nline', |
| 26 'type_name': 'EDisplay', 'inherited': False, 'independent': False, | 26 'type_name': 'EDisplay', 'inherited': False, 'independent': False, |
| 27 'keywords': [ | 27 'keywords': [ |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 300 def __init__(self, json5_file_path): | 300 def __init__(self, json5_file_path): |
| 301 super(ComputedStyleBaseWriter, self).__init__(json5_file_path) | 301 super(ComputedStyleBaseWriter, self).__init__(json5_file_path) |
| 302 self._outputs = { | 302 self._outputs = { |
| 303 'ComputedStyleBase.h': self.generate_base_computed_style_h, | 303 'ComputedStyleBase.h': self.generate_base_computed_style_h, |
| 304 'ComputedStyleBase.cpp': self.generate_base_computed_style_cpp, | 304 'ComputedStyleBase.cpp': self.generate_base_computed_style_cpp, |
| 305 'ComputedStyleBaseConstants.h': self.generate_base_computed_style_co nstants, | 305 'ComputedStyleBaseConstants.h': self.generate_base_computed_style_co nstants, |
| 306 } | 306 } |
| 307 | 307 |
| 308 # TODO(shend): Remove this once we move NONPROPERTIES to its own JSON fi le, | 308 # TODO(shend): Remove this once we move NONPROPERTIES to its own JSON fi le, |
| 309 # since the JSON5 reader will handle missing fields and defaults. | 309 # since the JSON5 reader will handle missing fields and defaults. |
| 310 for property_ in NONPROPERTIES: | 310 nonproperties = [defaultdict(lambda: None, item) for item in NONPROPERTI ES] |
| 311 property_['name_for_methods'] = property_['name'] | 311 |
| 312 if 'field_type_path' not in property_: | 312 for property_ in nonproperties: |
|
Bugs Nash
2017/04/12 23:31:45
this field_type_path logic does not seem to be in
shend
2017/04/12 23:41:03
This line should be fine because all it's doing is
Bugs Nash
2017/04/12 23:52:37
The default dict doesn't add field_type_path at al
shend
2017/04/12 23:57:28
Yeah, it doesn't add field_type_path. So if proper
| |
| 313 property_['field_type_path'] = None | 313 self._apply_property_naming_defaults(property_) |
| 314 if 'type_name' not in property_: | |
| 315 property_['type_name'] = 'E' + enum_type_name(property_['name_fo r_methods']) | |
| 316 | 314 |
| 317 property_values = self._properties.values() | 315 property_values = self._properties.values() |
| 318 | 316 |
| 319 for property_ in property_values: | 317 for property_ in property_values: |
| 320 # Override the type name when field_type_path is specified | 318 # Override the type name when field_type_path is specified |
| 321 if property_['field_type_path']: | 319 if property_['field_type_path']: |
| 322 property_['type_name'] = property_['field_type_path'].split('/') [-1] | 320 property_['type_name'] = property_['field_type_path'].split('/') [-1] |
| 323 # CSS properties are not allowed to explicitly specify their field_s ize. | 321 # CSS properties are not allowed to explicitly specify their field_s ize. |
| 324 property_['field_size'] = None | 322 property_['field_size'] = None |
| 325 | 323 |
| 326 self._generated_enums = _create_enums(property_values + NONPROPERTIES) | 324 self._generated_enums = _create_enums(property_values + nonproperties) |
| 327 | 325 |
| 328 all_fields = (_create_fields('property', property_values) + | 326 all_fields = (_create_fields('property', property_values) + |
| 329 _create_fields('nonproperty', NONPROPERTIES)) | 327 _create_fields('nonproperty', nonproperties)) |
| 330 | 328 |
| 331 # Separate the normal fields from the bit fields | 329 # Separate the normal fields from the bit fields |
| 332 bit_fields = [field for field in all_fields if field.is_bit_field] | 330 bit_fields = [field for field in all_fields if field.is_bit_field] |
| 333 normal_fields = [field for field in all_fields if not field.is_bit_field ] | 331 normal_fields = [field for field in all_fields if not field.is_bit_field ] |
| 334 | 332 |
| 335 # Pack bit fields into buckets | 333 # Pack bit fields into buckets |
| 336 field_buckets = _pack_fields(bit_fields) | 334 field_buckets = _pack_fields(bit_fields) |
| 337 | 335 |
| 338 # The expected size of ComputedStyleBase is equivalent to as many words | 336 # The expected size of ComputedStyleBase is equivalent to as many words |
| 339 # as the total number of buckets. | 337 # as the total number of buckets. |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 356 (self._expected_bit_field_bytes, real_bit_field_bytes)) | 354 (self._expected_bit_field_bytes, real_bit_field_bytes)) |
| 357 | 355 |
| 358 # Normal fields go first, then the bit fields. | 356 # Normal fields go first, then the bit fields. |
| 359 self._fields = list(normal_fields) | 357 self._fields = list(normal_fields) |
| 360 | 358 |
| 361 # Order the fields so fields in each bucket are adjacent. | 359 # Order the fields so fields in each bucket are adjacent. |
| 362 for bucket in field_buckets: | 360 for bucket in field_buckets: |
| 363 for field in bucket: | 361 for field in bucket: |
| 364 self._fields.append(field) | 362 self._fields.append(field) |
| 365 | 363 |
| 366 self._include_paths = _get_include_paths(property_values + NONPROPERTIES ) | 364 self._include_paths = _get_include_paths(property_values + nonproperties ) |
| 367 | 365 |
| 368 | 366 |
| 369 @template_expander.use_jinja('ComputedStyleBase.h.tmpl') | 367 @template_expander.use_jinja('ComputedStyleBase.h.tmpl') |
| 370 def generate_base_computed_style_h(self): | 368 def generate_base_computed_style_h(self): |
| 371 return { | 369 return { |
| 372 'properties': self._properties, | 370 'properties': self._properties, |
| 373 'enums': self._generated_enums, | 371 'enums': self._generated_enums, |
| 374 'include_paths': self._include_paths, | 372 'include_paths': self._include_paths, |
| 375 'fields': self._fields, | 373 'fields': self._fields, |
| 376 } | 374 } |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 387 @template_expander.use_jinja('ComputedStyleBaseConstants.h.tmpl') | 385 @template_expander.use_jinja('ComputedStyleBaseConstants.h.tmpl') |
| 388 def generate_base_computed_style_constants(self): | 386 def generate_base_computed_style_constants(self): |
| 389 return { | 387 return { |
| 390 'properties': self._properties, | 388 'properties': self._properties, |
| 391 'enums': self._generated_enums, | 389 'enums': self._generated_enums, |
| 392 'fields': self._fields, | 390 'fields': self._fields, |
| 393 } | 391 } |
| 394 | 392 |
| 395 if __name__ == '__main__': | 393 if __name__ == '__main__': |
| 396 json5_generator.Maker(ComputedStyleBaseWriter).main() | 394 json5_generator.Maker(ComputedStyleBaseWriter).main() |
| OLD | NEW |