Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(442)

Side by Side Diff: third_party/WebKit/Source/build/scripts/css_properties.py

Issue 2620233002: Add 'priority' key to CSSProperties.in (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/build/scripts/name_utilities.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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': 2,
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,
(...skipping 11 matching lines...) Expand all
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),
58 'keyword_only': (True, False), 59 'keyword_only': (True, False),
59 } 60 }
60 61
61 def __init__(self, file_paths): 62 def __init__(self, file_paths):
62 in_generator.Writer.__init__(self, file_paths) 63 in_generator.Writer.__init__(self, file_paths)
63 64
64 properties = self.in_file.name_dictionaries 65 properties = self.in_file.name_dictionaries
66
67 # Group properties by priority.
68 prioritised_properties = {0: [], 1: [], 2: []}
ktyliu 2017/01/11 02:45:43 Note you can do this all in one statement by using
sashab 2017/01/11 02:50:46 "Let me do your entire patch in one line kthxbai"
69 for property in properties:
70 priority = int(property['priority'])
71 assert priority in [0, 1, 2], 'Priority must be a number between 0 a nd 2'
72 prioritised_properties[priority].append(property)
73
74 # Sort each priority alphabetically and concatenate them.
75 property_name_key = lambda p: name_utilities.strip_webkit_prefix(p['name '])
76 properties = (sorted(prioritised_properties[0], key=property_name_key) +
77 sorted(prioritised_properties[1], key=property_name_key) +
78 sorted(prioritised_properties[2], key=property_name_key))
79
65 self._aliases = [property for property in properties if property['alias_ for']] 80 self._aliases = [property for property in properties if property['alias_ for']]
66 properties = [property for property in properties if not property['alias _for']] 81 properties = [property for property in properties if not property['alias _for']]
67 82
68 # 0: CSSPropertyInvalid 83 # 0: CSSPropertyInvalid
69 # 1: CSSPropertyApplyAtRule 84 # 1: CSSPropertyApplyAtRule
70 # 2: CSSPropertyVariable 85 # 2: CSSPropertyVariable
71 self._first_enum_value = 3 86 self._first_enum_value = 3
72 87
73 # StylePropertyMetadata additionally assumes there are under 1024 proper ties. 88 # 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.' 89 assert self._first_enum_value + len(properties) < 512, 'Property aliasin g expects there are under 512 properties.'
75 90
76 for offset, property in enumerate(properties): 91 for offset, property in enumerate(properties):
77 property['property_id'] = name_utilities.enum_for_css_property(prope rty['name']) 92 property['property_id'] = name_utilities.enum_for_css_property(prope rty['name'])
78 property['upper_camel_name'] = name_utilities.camel_case(property['n ame']) 93 property['upper_camel_name'] = name_utilities.camel_case(property['n ame'])
79 property['lower_camel_name'] = name_utilities.lower_first(property[' upper_camel_name']) 94 property['lower_camel_name'] = name_utilities.lower_first(property[' upper_camel_name'])
80 property['enum_value'] = self._first_enum_value + offset 95 property['enum_value'] = self._first_enum_value + offset
81 property['is_internal'] = property['name'].startswith('-internal-') 96 property['is_internal'] = property['name'].startswith('-internal-')
82 97
83 self._properties_including_aliases = properties 98 self._properties_including_aliases = properties
84 self._properties = {property['property_id']: property for property in pr operties} 99 self._properties = {property['property_id']: property for property in pr operties}
85 100
86 # The generated code will only work with at most one alias per property 101 # 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) 102 assert len({property['alias_for'] for property in self._aliases}) == len (self._aliases)
88 103
89 for property in self._aliases: 104 for property in self._aliases:
90 property['property_id'] = name_utilities.enum_for_css_property_alias (property['name']) 105 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'])] 106 aliased_property = self._properties[name_utilities.enum_for_css_prop erty(property['alias_for'])]
92 property['enum_value'] = aliased_property['enum_value'] + 512 107 property['enum_value'] = aliased_property['enum_value'] + 512
93 self._properties_including_aliases += self._aliases 108 self._properties_including_aliases += self._aliases
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/build/scripts/name_utilities.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698