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

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

Issue 2620233002: Add 'priority' key to CSSProperties.in (Closed)
Patch Set: Small fix from bad rebsae 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/core/css/CSSProperties.in » ('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': '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 # This order must match the order in CSSPropertyPriority.h.
71 priority_numbers = {'Animation': 0, 'High': 1, 'Low': 2}
72 priority = priority_numbers[property['priority']]
73 name_without_leading_dash = property['name']
74 if property['name'].startswith('-'):
75 name_without_leading_dash = property['name'][1:]
76 property['sorting_key'] = (priority, name_without_leading_dash)
77
78 # Assert there are no key collisions.
79 sorting_keys = [p['sorting_key'] for p in properties]
80 assert len(sorting_keys) == len(set(sorting_keys)), \
81 ('Collision detected - two properties have the same name and priorit y, '
82 'a potentially non-deterministic ordering can occur.')
83 properties.sort(key=lambda p: p['sorting_key'])
84
65 self._aliases = [property for property in properties if property['alias_ for']] 85 self._aliases = [property for property in properties if property['alias_ for']]
66 properties = [property for property in properties if not property['alias _for']] 86 properties = [property for property in properties if not property['alias _for']]
67 87
68 # 0: CSSPropertyInvalid 88 # 0: CSSPropertyInvalid
69 # 1: CSSPropertyApplyAtRule 89 # 1: CSSPropertyApplyAtRule
70 # 2: CSSPropertyVariable 90 # 2: CSSPropertyVariable
71 self._first_enum_value = 3 91 self._first_enum_value = 3
72 92
73 # StylePropertyMetadata additionally assumes there are under 1024 proper ties. 93 # 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.' 94 assert self._first_enum_value + len(properties) < 512, 'Property aliasin g expects there are under 512 properties.'
75 95
76 for offset, property in enumerate(properties): 96 for offset, property in enumerate(properties):
77 property['property_id'] = name_utilities.enum_for_css_property(prope rty['name']) 97 property['property_id'] = name_utilities.enum_for_css_property(prope rty['name'])
78 property['upper_camel_name'] = name_utilities.camel_case(property['n ame']) 98 property['upper_camel_name'] = name_utilities.camel_case(property['n ame'])
79 property['lower_camel_name'] = name_utilities.lower_first(property[' upper_camel_name']) 99 property['lower_camel_name'] = name_utilities.lower_first(property[' upper_camel_name'])
80 property['enum_value'] = self._first_enum_value + offset 100 property['enum_value'] = self._first_enum_value + offset
81 property['is_internal'] = property['name'].startswith('-internal-') 101 property['is_internal'] = property['name'].startswith('-internal-')
82 102
83 self._properties_including_aliases = properties 103 self._properties_including_aliases = properties
84 self._properties = {property['property_id']: property for property in pr operties} 104 self._properties = {property['property_id']: property for property in pr operties}
85 105
86 # The generated code will only work with at most one alias per property 106 # 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) 107 assert len({property['alias_for'] for property in self._aliases}) == len (self._aliases)
88 108
89 for property in self._aliases: 109 for property in self._aliases:
90 property['property_id'] = name_utilities.enum_for_css_property_alias (property['name']) 110 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'])] 111 aliased_property = self._properties[name_utilities.enum_for_css_prop erty(property['alias_for'])]
92 property['enum_value'] = aliased_property['enum_value'] + 512 112 property['enum_value'] = aliased_property['enum_value'] + 512
93 self._properties_including_aliases += self._aliases 113 self._properties_including_aliases += self._aliases
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/css/CSSProperties.in » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698