Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 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 in_generator | 6 import in_generator |
| 7 from name_utilities import lower_first | 7 from name_utilities import lower_first |
| 8 | 8 |
| 9 | 9 |
| 10 class CSSProperties(in_generator.Writer): | 10 class CSSProperties(in_generator.Writer): |
| 11 defaults = { | 11 defaults = { |
| 12 'alias_for': None, | |
| 12 'longhands': '', | 13 'longhands': '', |
| 13 'font': False, | 14 'font': False, |
| 14 'svg': False, | 15 'svg': False, |
| 15 'name_for_methods': None, | 16 'name_for_methods': None, |
| 16 'use_handlers_for': None, | 17 'use_handlers_for': None, |
| 17 'getter': None, | 18 'getter': None, |
| 18 'setter': None, | 19 'setter': None, |
| 19 'initial': None, | 20 'initial': None, |
| 20 'type_name': None, | 21 'type_name': None, |
| 21 'converter': None, | 22 'converter': None, |
| 22 'custom_all': False, | 23 'custom_all': False, |
| 23 'custom_initial': False, | 24 'custom_initial': False, |
| 24 'custom_inherit': False, | 25 'custom_inherit': False, |
| 25 'custom_value': False, | 26 'custom_value': False, |
| 26 'builder_skip': False, | 27 'builder_skip': False, |
| 28 'builder_unreachable': False, | |
|
alancutter (OOO until 2018)
2014/08/11 05:02:22
Unused flag.
Timothy Loh
2014/08/12 01:49:42
Done.
| |
| 27 'direction_aware': False, | 29 'direction_aware': False, |
| 28 } | 30 } |
| 29 | 31 |
| 30 valid_values = { | 32 valid_values = { |
| 31 'font': (True, False), | 33 'font': (True, False), |
| 32 'svg': (True, False), | 34 'svg': (True, False), |
| 33 'custom_all': (True, False), | 35 'custom_all': (True, False), |
| 34 'custom_initial': (True, False), | 36 'custom_initial': (True, False), |
| 35 'custom_inherit': (True, False), | 37 'custom_inherit': (True, False), |
| 36 'custom_value': (True, False), | 38 'custom_value': (True, False), |
| 37 'builder_skip': (True, False), | 39 'builder_skip': (True, False), |
| 40 'builder_unreachable': (True, False), | |
| 38 'direction_aware': (True, False), | 41 'direction_aware': (True, False), |
| 39 } | 42 } |
| 40 | 43 |
| 41 def __init__(self, file_paths): | 44 def __init__(self, file_paths): |
| 42 in_generator.Writer.__init__(self, file_paths) | 45 in_generator.Writer.__init__(self, file_paths) |
| 43 | 46 |
| 44 properties = self.in_file.name_dictionaries | 47 properties = self.in_file.name_dictionaries |
| 45 | 48 |
| 46 for property in properties: | 49 self._aliases = {property['name']: property['alias_for'] for property in properties if property['alias_for']} |
| 50 properties = [property for property in properties if not property['alias _for']] | |
| 51 | |
| 52 assert len(properties) <= 1024, 'There are more than 1024 CSS Properties , you need to update CSSProperty.h/StylePropertyMetadata m_propertyID accordingl y.' | |
| 53 # We currently assign 0 to CSSPropertyInvalid | |
| 54 self._first_enum_value = 1 | |
| 55 for offset, property in enumerate(properties): | |
| 47 property['property_id'] = css_name_to_enum(property['name']) | 56 property['property_id'] = css_name_to_enum(property['name']) |
| 48 property['upper_camel_name'] = camelcase_css_name(property['name']) | 57 property['upper_camel_name'] = camelcase_css_name(property['name']) |
| 49 property['lower_camel_name'] = lower_first(property['upper_camel_nam e']) | 58 property['lower_camel_name'] = lower_first(property['upper_camel_nam e']) |
| 59 property['enum_value'] = self._first_enum_value + offset | |
| 60 property['is_internal'] = property['name'].startswith('-internal-') | |
| 50 | 61 |
| 51 self._properties_list = properties | 62 self._properties_list = properties |
| 52 self._properties = {property['property_id']: property for property in pr operties} | 63 self._properties = {property['property_id']: property for property in pr operties} |
| 53 | 64 |
| 54 | 65 |
| 55 def camelcase_css_name(css_name): | 66 def camelcase_css_name(css_name): |
| 56 """Convert hyphen-separated-name to UpperCamelCase. | 67 """Convert hyphen-separated-name to UpperCamelCase. |
| 57 | 68 |
| 58 E.g., '-foo-bar' becomes 'FooBar'. | 69 E.g., '-foo-bar' becomes 'FooBar'. |
| 59 """ | 70 """ |
| 60 return ''.join(word.capitalize() for word in css_name.split('-')) | 71 return ''.join(word.capitalize() for word in css_name.split('-')) |
| 61 | 72 |
| 62 | 73 |
| 63 def css_name_to_enum(css_name): | 74 def css_name_to_enum(css_name): |
| 64 return 'CSSProperty' + camelcase_css_name(css_name) | 75 return 'CSSProperty' + camelcase_css_name(css_name) |
| OLD | NEW |