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 import name_utilities | 7 import name_utilities |
8 | 8 |
9 | 9 |
10 class CSSProperties(in_generator.Writer): | 10 class CSSProperties(in_generator.Writer): |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 'custom_value': (True, False), | 55 'custom_value': (True, False), |
56 'builder_skip': (True, False), | 56 'builder_skip': (True, False), |
57 'direction_aware': (True, False), | 57 'direction_aware': (True, False), |
58 'keyword_only': (True, False), | 58 'keyword_only': (True, False), |
59 } | 59 } |
60 | 60 |
61 def __init__(self, file_paths): | 61 def __init__(self, file_paths): |
62 in_generator.Writer.__init__(self, file_paths) | 62 in_generator.Writer.__init__(self, file_paths) |
63 | 63 |
64 properties = self.in_file.name_dictionaries | 64 properties = self.in_file.name_dictionaries |
65 self._descriptors = [property for property in properties if property['de
scriptor_only']] | |
66 | |
67 self._aliases = [property for property in properties if property['alias_
for']] | 65 self._aliases = [property for property in properties if property['alias_
for']] |
68 properties = [property for property in properties if not property['alias
_for']] | 66 properties = [property for property in properties if not property['alias
_for']] |
69 | 67 |
70 # 0: CSSPropertyInvalid | 68 # 0: CSSPropertyInvalid |
71 # 1: CSSPropertyApplyAtRule | 69 # 1: CSSPropertyApplyAtRule |
72 # 2: CSSPropertyVariable | 70 # 2: CSSPropertyVariable |
73 self._first_enum_value = 3 | 71 self._first_enum_value = 3 |
74 | 72 |
75 # StylePropertyMetadata additionally assumes there are under 1024 proper
ties. | 73 # StylePropertyMetadata additionally assumes there are under 1024 proper
ties. |
76 assert self._first_enum_value + len(properties) < 512, 'Property aliasin
g expects there are under 512 properties.' | 74 assert self._first_enum_value + len(properties) < 512, 'Property aliasin
g expects there are under 512 properties.' |
77 | 75 |
78 for offset, property in enumerate(properties): | 76 for offset, property in enumerate(properties): |
79 property['property_id'] = name_utilities.enum_for_css_property(prope
rty['name']) | 77 property['property_id'] = name_utilities.enum_for_css_property(prope
rty['name']) |
80 property['upper_camel_name'] = name_utilities.camel_case(property['n
ame']) | 78 property['upper_camel_name'] = name_utilities.camel_case(property['n
ame']) |
81 property['lower_camel_name'] = name_utilities.lower_first(property['
upper_camel_name']) | 79 property['lower_camel_name'] = name_utilities.lower_first(property['
upper_camel_name']) |
82 property['enum_value'] = self._first_enum_value + offset | 80 property['enum_value'] = self._first_enum_value + offset |
83 property['is_internal'] = property['name'].startswith('-internal-') | 81 property['is_internal'] = property['name'].startswith('-internal-') |
84 | 82 |
85 self._properties_including_aliases = properties | 83 self._properties_including_aliases = properties |
86 self._properties = {property['property_id']: property for property in pr
operties} | 84 self._properties = {property['property_id']: property for property in pr
operties} |
87 | 85 |
88 # The generated code will only work with at most one alias per property | 86 # The generated code will only work with at most one alias per property |
89 assert len({property['alias_for'] for property in self._aliases}) == len
(self._aliases) | 87 assert len({property['alias_for'] for property in self._aliases}) == len
(self._aliases) |
90 | 88 |
91 for property in self._aliases: | 89 for property in self._aliases: |
92 property['property_id'] = name_utilities.enum_for_css_property_alias
(property['name']) | 90 property['property_id'] = name_utilities.enum_for_css_property_alias
(property['name']) |
93 aliased_property = self._properties[name_utilities.enum_for_css_prop
erty(property['alias_for'])] | 91 aliased_property = self._properties[name_utilities.enum_for_css_prop
erty(property['alias_for'])] |
94 property['enum_value'] = aliased_property['enum_value'] + 512 | 92 property['enum_value'] = aliased_property['enum_value'] + 512 |
95 self._properties_including_aliases += self._aliases | 93 self._properties_including_aliases += self._aliases |
OLD | NEW |