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

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

Issue 2756113002: Move naming related code in make_computed_style_base to name_utilities. (Closed)
Patch Set: Rebase Created 3 years, 9 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/make_computed_style_base.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 json5_generator 6 import json5_generator
7 import name_utilities 7 from name_utilities import (
8 upper_camel_case, lower_camel_case, enum_for_css_property, enum_for_css_prop erty_alias
9 )
8 10
9 11
10 class CSSProperties(json5_generator.Writer): 12 class CSSProperties(json5_generator.Writer):
11 def __init__(self, file_paths): 13 def __init__(self, file_paths):
12 json5_generator.Writer.__init__(self, file_paths) 14 json5_generator.Writer.__init__(self, file_paths)
13 15
14 properties = self.json5_file.name_dictionaries 16 properties = self.json5_file.name_dictionaries
15 17
16 # Sort properties by priority, then alphabetically. 18 # Sort properties by priority, then alphabetically.
17 for property in properties: 19 for property in properties:
(...skipping 22 matching lines...) Expand all
40 42
41 # StylePropertyMetadata additionally assumes there are under 1024 proper ties. 43 # StylePropertyMetadata additionally assumes there are under 1024 proper ties.
42 assert self._first_enum_value + len(properties) < 512, 'Property aliasin g expects there are under 512 properties.' 44 assert self._first_enum_value + len(properties) < 512, 'Property aliasin g expects there are under 512 properties.'
43 45
44 for property in properties: 46 for property in properties:
45 assert property['is_descriptor'] or property['is_property'], \ 47 assert property['is_descriptor'] or property['is_property'], \
46 property['name'] + ' must be either a property, a descriptor' +\ 48 property['name'] + ' must be either a property, a descriptor' +\
47 ' or both' 49 ' or both'
48 50
49 for offset, property in enumerate(properties): 51 for offset, property in enumerate(properties):
50 property['property_id'] = name_utilities.enum_for_css_property(prope rty['name']) 52 property['property_id'] = enum_for_css_property(property['name'])
51 property['upper_camel_name'] = name_utilities.camel_case(property['n ame']) 53 property['upper_camel_name'] = upper_camel_case(property['name'])
52 property['lower_camel_name'] = name_utilities.lower_first(property[' upper_camel_name']) 54 property['lower_camel_name'] = lower_camel_case(property['name'])
53 property['enum_value'] = self._first_enum_value + offset 55 property['enum_value'] = self._first_enum_value + offset
54 property['is_internal'] = property['name'].startswith('-internal-') 56 property['is_internal'] = property['name'].startswith('-internal-')
55 57
56 self._properties_including_aliases = properties 58 self._properties_including_aliases = properties
57 self._properties = {property['property_id']: property for property in pr operties} 59 self._properties = {property['property_id']: property for property in pr operties}
58 60
59 # The generated code will only work with at most one alias per property. 61 # The generated code will only work with at most one alias per property.
60 assert len({property['alias_for'] for property in self._aliases}) == len (self._aliases) 62 assert len({property['alias_for'] for property in self._aliases}) == len (self._aliases)
61 63
62 # Update property aliases to include the fields of the property being al iased. 64 # Update property aliases to include the fields of the property being al iased.
63 for i, alias in enumerate(self._aliases): 65 for i, alias in enumerate(self._aliases):
64 aliased_property = self._properties[ 66 aliased_property = self._properties[
65 name_utilities.enum_for_css_property(alias['alias_for'])] 67 enum_for_css_property(alias['alias_for'])]
66 updated_alias = aliased_property.copy() 68 updated_alias = aliased_property.copy()
67 updated_alias['name'] = alias['name'] 69 updated_alias['name'] = alias['name']
68 updated_alias['alias_for'] = alias['alias_for'] 70 updated_alias['alias_for'] = alias['alias_for']
69 updated_alias['property_id'] = \ 71 updated_alias['property_id'] = enum_for_css_property_alias(alias['na me'])
70 name_utilities.enum_for_css_property_alias(alias['name'])
71 updated_alias['enum_value'] = aliased_property['enum_value'] + 512 72 updated_alias['enum_value'] = aliased_property['enum_value'] + 512
72 updated_alias['upper_camel_name'] = \ 73 updated_alias['upper_camel_name'] = upper_camel_case(alias['name'])
73 name_utilities.camel_case(alias['name']) 74 updated_alias['lower_camel_name'] = lower_camel_case(alias['name'])
74 updated_alias['lower_camel_name'] = \
75 name_utilities.lower_first(updated_alias['upper_camel_name'])
76 self._aliases[i] = updated_alias 75 self._aliases[i] = updated_alias
77 self._properties_including_aliases += self._aliases 76 self._properties_including_aliases += self._aliases
78 77
79 self.last_unresolved_property_id = max(property["enum_value"] for proper ty in self._properties_including_aliases) 78 self.last_unresolved_property_id = max(property["enum_value"] for proper ty in self._properties_including_aliases)
80 79
81 def properties(self): 80 def properties(self):
82 return self._properties 81 return self._properties
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/build/scripts/make_computed_style_base.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698