| 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, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 36 'custom_value': (True, False), | 37 'custom_value': (True, False), |
| 37 'builder_skip': (True, False), | 38 'builder_skip': (True, False), |
| 38 'direction_aware': (True, False), | 39 'direction_aware': (True, False), |
| 39 } | 40 } |
| 40 | 41 |
| 41 def __init__(self, file_paths): | 42 def __init__(self, file_paths): |
| 42 in_generator.Writer.__init__(self, file_paths) | 43 in_generator.Writer.__init__(self, file_paths) |
| 43 | 44 |
| 44 properties = self.in_file.name_dictionaries | 45 properties = self.in_file.name_dictionaries |
| 45 | 46 |
| 46 for property in properties: | 47 self._aliases = {property['name']: property['alias_for'] for property in
properties if property['alias_for']} |
| 48 properties = [property for property in properties if not property['alias
_for']] |
| 49 |
| 50 assert len(properties) <= 1024, 'There are more than 1024 CSS Properties
, you need to update CSSProperty.h/StylePropertyMetadata m_propertyID accordingl
y.' |
| 51 # We currently assign 0 to CSSPropertyInvalid |
| 52 self._first_enum_value = 1 |
| 53 for offset, property in enumerate(properties): |
| 47 property['property_id'] = css_name_to_enum(property['name']) | 54 property['property_id'] = css_name_to_enum(property['name']) |
| 48 property['upper_camel_name'] = camelcase_css_name(property['name']) | 55 property['upper_camel_name'] = camelcase_css_name(property['name']) |
| 49 property['lower_camel_name'] = lower_first(property['upper_camel_nam
e']) | 56 property['lower_camel_name'] = lower_first(property['upper_camel_nam
e']) |
| 57 property['enum_value'] = self._first_enum_value + offset |
| 58 property['is_internal'] = property['name'].startswith('-internal-') |
| 50 | 59 |
| 51 self._properties_list = properties | 60 self._properties_list = properties |
| 52 self._properties = {property['property_id']: property for property in pr
operties} | 61 self._properties = {property['property_id']: property for property in pr
operties} |
| 53 | 62 |
| 54 | 63 |
| 55 def camelcase_css_name(css_name): | 64 def camelcase_css_name(css_name): |
| 56 """Convert hyphen-separated-name to UpperCamelCase. | 65 """Convert hyphen-separated-name to UpperCamelCase. |
| 57 | 66 |
| 58 E.g., '-foo-bar' becomes 'FooBar'. | 67 E.g., '-foo-bar' becomes 'FooBar'. |
| 59 """ | 68 """ |
| 60 return ''.join(word.capitalize() for word in css_name.split('-')) | 69 return ''.join(word.capitalize() for word in css_name.split('-')) |
| 61 | 70 |
| 62 | 71 |
| 63 def css_name_to_enum(css_name): | 72 def css_name_to_enum(css_name): |
| 64 return 'CSSProperty' + camelcase_css_name(css_name) | 73 return 'CSSProperty' + camelcase_css_name(css_name) |
| OLD | NEW |