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): |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 'custom_value': (True, False), | 42 'custom_value': (True, False), |
43 'builder_skip': (True, False), | 43 'builder_skip': (True, False), |
44 'direction_aware': (True, False), | 44 'direction_aware': (True, False), |
45 } | 45 } |
46 | 46 |
47 def __init__(self, file_paths): | 47 def __init__(self, file_paths): |
48 in_generator.Writer.__init__(self, file_paths) | 48 in_generator.Writer.__init__(self, file_paths) |
49 | 49 |
50 properties = self.in_file.name_dictionaries | 50 properties = self.in_file.name_dictionaries |
51 | 51 |
52 self._aliases = {property['name']: property['alias_for'] for property in
properties if property['alias_for']} | 52 self._aliases = [property for property in properties if property['alias_
for']] |
53 properties = [property for property in properties if not property['alias
_for']] | 53 properties = [property for property in properties if not property['alias
_for']] |
54 | 54 |
55 assert len(properties) <= 1024, 'There are more than 1024 CSS Properties
, you need to update CSSProperty.h/StylePropertyMetadata m_propertyID accordingl
y.' | 55 # StylePropertyMetadata additionally assumes there are under 1024 proper
ties. |
| 56 assert len(properties) < 512, 'Property aliasing expects there are under
512 properties.' |
| 57 |
56 # We currently assign 0 to CSSPropertyInvalid | 58 # We currently assign 0 to CSSPropertyInvalid |
57 self._first_enum_value = 1 | 59 self._first_enum_value = 1 |
58 for offset, property in enumerate(properties): | 60 for offset, property in enumerate(properties): |
59 property['property_id'] = css_name_to_enum(property['name']) | 61 property['property_id'] = css_name_to_enum(property['name']) |
60 property['upper_camel_name'] = camelcase_css_name(property['name']) | 62 property['upper_camel_name'] = camelcase_css_name(property['name']) |
61 property['lower_camel_name'] = lower_first(property['upper_camel_nam
e']) | 63 property['lower_camel_name'] = lower_first(property['upper_camel_nam
e']) |
62 property['enum_value'] = self._first_enum_value + offset | 64 property['enum_value'] = self._first_enum_value + offset |
63 property['is_internal'] = property['name'].startswith('-internal-') | 65 property['is_internal'] = property['name'].startswith('-internal-') |
64 | 66 |
65 self._properties_list = properties | 67 self._properties_including_aliases = properties |
66 self._properties = {property['property_id']: property for property in pr
operties} | 68 self._properties = {property['property_id']: property for property in pr
operties} |
67 | 69 |
| 70 # The generated code will only work with at most one alias per property |
| 71 assert len({property['alias_for'] for property in self._aliases}) == len
(self._aliases) |
| 72 |
| 73 for property in self._aliases: |
| 74 property['property_id'] = css_alias_name_to_enum(property['name']) |
| 75 aliased_property = self._properties[css_name_to_enum(property['alias
_for'])] |
| 76 property['enum_value'] = aliased_property['enum_value'] + 512 |
| 77 self._properties_including_aliases += self._aliases |
| 78 |
68 | 79 |
69 def camelcase_css_name(css_name): | 80 def camelcase_css_name(css_name): |
70 """Convert hyphen-separated-name to UpperCamelCase. | 81 """Convert hyphen-separated-name to UpperCamelCase. |
71 | 82 |
72 E.g., '-foo-bar' becomes 'FooBar'. | 83 E.g., '-foo-bar' becomes 'FooBar'. |
73 """ | 84 """ |
74 return ''.join(word.capitalize() for word in css_name.split('-')) | 85 return ''.join(word.capitalize() for word in css_name.split('-')) |
75 | 86 |
76 | 87 |
77 def css_name_to_enum(css_name): | 88 def css_name_to_enum(css_name): |
78 return 'CSSProperty' + camelcase_css_name(css_name) | 89 return 'CSSProperty' + camelcase_css_name(css_name) |
| 90 |
| 91 |
| 92 def css_alias_name_to_enum(css_name): |
| 93 return 'CSSPropertyAlias' + camelcase_css_name(css_name) |
OLD | NEW |