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 import name_utilities | 7 import name_utilities |
| 8 | 8 |
| 9 | 9 |
| 10 class CSSProperties(in_generator.Writer): | 10 class CSSProperties(in_generator.Writer): |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 'setter': None, | 24 'setter': None, |
| 25 'initial': None, | 25 'initial': None, |
| 26 'type_name': None, | 26 'type_name': None, |
| 27 'converter': None, | 27 'converter': None, |
| 28 'custom_all': False, | 28 'custom_all': False, |
| 29 'custom_initial': False, | 29 'custom_initial': False, |
| 30 'custom_inherit': False, | 30 'custom_inherit': False, |
| 31 'custom_value': False, | 31 'custom_value': False, |
| 32 'builder_skip': False, | 32 'builder_skip': False, |
| 33 'direction_aware': False, | 33 'direction_aware': False, |
| 34 'priority': 'Low', | |
| 34 'api_class': None, | 35 'api_class': None, |
| 35 # Generated ComputedStyle annotations. | 36 # Generated ComputedStyle annotations. |
| 36 'field_storage_type': None, | 37 'field_storage_type': None, |
| 37 # Typed OM annotations. | 38 # Typed OM annotations. |
| 38 'typedom_types': [], | 39 'typedom_types': [], |
| 39 'keywords': [], | 40 'keywords': [], |
| 40 'initial_keyword': None, | 41 'initial_keyword': None, |
| 41 'keyword_only': False, | 42 'keyword_only': False, |
| 42 'supports_percentage': False, | 43 'supports_percentage': False, |
| 43 'repeated': False, | 44 'repeated': False, |
| 44 } | 45 } |
| 45 | 46 |
| 46 valid_values = { | 47 valid_values = { |
| 47 'interpolable': (True, False), | 48 'interpolable': (True, False), |
| 48 'inherited': (True, False), | 49 'inherited': (True, False), |
| 49 'independent': (True, False), | 50 'independent': (True, False), |
| 50 'font': (True, False), | 51 'font': (True, False), |
| 51 'svg': (True, False), | 52 'svg': (True, False), |
| 52 'custom_all': (True, False), | 53 'custom_all': (True, False), |
| 53 'custom_initial': (True, False), | 54 'custom_initial': (True, False), |
| 54 'custom_inherit': (True, False), | 55 'custom_inherit': (True, False), |
| 55 'custom_value': (True, False), | 56 'custom_value': (True, False), |
| 56 'builder_skip': (True, False), | 57 'builder_skip': (True, False), |
| 57 'direction_aware': (True, False), | 58 'direction_aware': (True, False), |
| 59 'priority': ('Animation', 'High', 'Low'), | |
| 58 'keyword_only': (True, False), | 60 'keyword_only': (True, False), |
| 59 } | 61 } |
| 60 | 62 |
| 61 def __init__(self, file_paths): | 63 def __init__(self, file_paths): |
| 62 in_generator.Writer.__init__(self, file_paths) | 64 in_generator.Writer.__init__(self, file_paths) |
| 63 | 65 |
| 64 properties = self.in_file.name_dictionaries | 66 properties = self.in_file.name_dictionaries |
| 67 | |
| 68 # Sort properties by priority, then alphabetically. | |
| 69 for property in properties: | |
| 70 priority_numbers = {'Animation': 0, 'High': 1, 'Low': 2} | |
|
alancutter (OOO until 2018)
2017/01/11 04:20:56
Add comment stating that this must match the order
sashab
2017/01/11 23:28:51
Added comment, didn't add TODO to generate CSSProp
| |
| 71 priority = priority_numbers[property['priority']] | |
| 72 name_without_leading_dash = property['name'] | |
| 73 if property['name'].startswith('-'): | |
| 74 name_without_leading_dash = property['name'][1:] | |
| 75 property['sorting_key'] = (priority, name_without_leading_dash) | |
| 76 | |
| 77 # Assert there are no key collisions. | |
| 78 sorting_keys = [p['sorting_key'] for p in properties] | |
| 79 assert len(sorting_keys) == len(set(sorting_keys)), \ | |
| 80 ('Collision detected - two properties have the same name and priorit y, ' | |
| 81 'a potentially non-deterministic ordering can occur.') | |
| 82 properties.sort(key=lambda p: p['sorting_key']) | |
| 83 | |
| 65 self._aliases = [property for property in properties if property['alias_ for']] | 84 self._aliases = [property for property in properties if property['alias_ for']] |
| 66 properties = [property for property in properties if not property['alias _for']] | 85 properties = [property for property in properties if not property['alias _for']] |
| 67 | 86 |
| 68 # 0: CSSPropertyInvalid | 87 # 0: CSSPropertyInvalid |
| 69 # 1: CSSPropertyApplyAtRule | 88 # 1: CSSPropertyApplyAtRule |
| 70 # 2: CSSPropertyVariable | 89 # 2: CSSPropertyVariable |
| 71 self._first_enum_value = 3 | 90 self._first_enum_value = 3 |
| 72 | 91 |
| 73 # StylePropertyMetadata additionally assumes there are under 1024 proper ties. | 92 # StylePropertyMetadata additionally assumes there are under 1024 proper ties. |
| 74 assert self._first_enum_value + len(properties) < 512, 'Property aliasin g expects there are under 512 properties.' | 93 assert self._first_enum_value + len(properties) < 512, 'Property aliasin g expects there are under 512 properties.' |
| 75 | 94 |
| 76 for offset, property in enumerate(properties): | 95 for offset, property in enumerate(properties): |
| 77 property['property_id'] = name_utilities.enum_for_css_property(prope rty['name']) | 96 property['property_id'] = name_utilities.enum_for_css_property(prope rty['name']) |
| 78 property['upper_camel_name'] = name_utilities.camel_case(property['n ame']) | 97 property['upper_camel_name'] = name_utilities.camel_case(property['n ame']) |
| 79 property['lower_camel_name'] = name_utilities.lower_first(property[' upper_camel_name']) | 98 property['lower_camel_name'] = name_utilities.lower_first(property[' upper_camel_name']) |
| 80 property['enum_value'] = self._first_enum_value + offset | 99 property['enum_value'] = self._first_enum_value + offset |
| 81 property['is_internal'] = property['name'].startswith('-internal-') | 100 property['is_internal'] = property['name'].startswith('-internal-') |
| 82 | 101 |
| 83 self._properties_including_aliases = properties | 102 self._properties_including_aliases = properties |
| 84 self._properties = {property['property_id']: property for property in pr operties} | 103 self._properties = {property['property_id']: property for property in pr operties} |
| 85 | 104 |
| 86 # The generated code will only work with at most one alias per property | 105 # The generated code will only work with at most one alias per property |
| 87 assert len({property['alias_for'] for property in self._aliases}) == len (self._aliases) | 106 assert len({property['alias_for'] for property in self._aliases}) == len (self._aliases) |
| 88 | 107 |
| 89 for property in self._aliases: | 108 for property in self._aliases: |
| 90 property['property_id'] = name_utilities.enum_for_css_property_alias (property['name']) | 109 property['property_id'] = name_utilities.enum_for_css_property_alias (property['name']) |
| 91 aliased_property = self._properties[name_utilities.enum_for_css_prop erty(property['alias_for'])] | 110 aliased_property = self._properties[name_utilities.enum_for_css_prop erty(property['alias_for'])] |
| 92 property['enum_value'] = aliased_property['enum_value'] + 512 | 111 property['enum_value'] = aliased_property['enum_value'] + 512 |
| 93 self._properties_including_aliases += self._aliases | 112 self._properties_including_aliases += self._aliases |
| OLD | NEW |