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 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 """ | 81 """ |
| 82 Returns a dictionary of enums to be generated, enum name -> [list of enum va lues] | 82 Returns a dictionary of enums to be generated, enum name -> [list of enum va lues] |
| 83 """ | 83 """ |
| 84 enums = {} | 84 enums = {} |
| 85 for property_ in properties: | 85 for property_ in properties: |
| 86 # Only generate enums for keyword properties that use the default field_ storage_type. | 86 # Only generate enums for keyword properties that use the default field_ storage_type. |
| 87 if property_['keyword_only'] and property_['field_storage_type'] is None : | 87 if property_['keyword_only'] and property_['field_storage_type'] is None : |
| 88 enum_name = property_['type_name'] | 88 enum_name = property_['type_name'] |
| 89 # From the Blink style guide: Enum members should use InterCaps with an initial capital letter. [names-enum-members] | 89 # From the Blink style guide: Enum members should use InterCaps with an initial capital letter. [names-enum-members] |
| 90 enum_values = [('k' + camel_case(k)) for k in property_['keywords']] | 90 enum_values = [('k' + camel_case(k)) for k in property_['keywords']] |
| 91 | |
| 92 if enum_name in enums: | |
| 93 # There's an enum with the same name, check if the enum values a re the same | |
| 94 assert set(enums[enum_name]) == set(enum_values), \ | |
| 95 ("'{}' can't have type_name '{}' ".format(property_['name'], enum_name) + | |
|
sashab
2017/02/07 02:59:27
Can you just use + property['name'] and + enum_nam
shend
2017/02/07 21:44:02
done.
| |
| 96 "because it was used by a previous property, but with a dif ferent set of keywords. " | |
| 97 "Either give it a different name or ensure the keywords are the same.") | |
| 98 | |
| 91 enums[enum_name] = enum_values | 99 enums[enum_name] = enum_values |
| 92 | 100 |
| 93 return enums | 101 return enums |
| 94 | 102 |
| 95 | 103 |
| 96 def _create_enum_field(property_): | 104 def _create_enum_field(property_): |
| 97 """ | 105 """ |
| 98 Create an enum field from a CSS property and return the Field object. | 106 Create an enum field from a CSS property and return the Field object. |
| 99 """ | 107 """ |
| 100 property_name = property_['name_for_methods'] | 108 property_name = property_['name_for_methods'] |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 287 def generate_base_computed_style_constants(self): | 295 def generate_base_computed_style_constants(self): |
| 288 return { | 296 return { |
| 289 'properties': self._properties, | 297 'properties': self._properties, |
| 290 'enums': self._generated_enums, | 298 'enums': self._generated_enums, |
| 291 'fields': self._fields, | 299 'fields': self._fields, |
| 292 'expected_total_field_bytes': self._expected_total_field_bytes, | 300 'expected_total_field_bytes': self._expected_total_field_bytes, |
| 293 } | 301 } |
| 294 | 302 |
| 295 if __name__ == '__main__': | 303 if __name__ == '__main__': |
| 296 json5_generator.Maker(ComputedStyleBaseWriter).main() | 304 json5_generator.Maker(ComputedStyleBaseWriter).main() |
| OLD | NEW |