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

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

Issue 2669973002: Support generating enums shared by multiple ComputedStyle fields. (Closed)
Patch Set: Address comments Created 3 years, 10 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 | no next file » | 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 2016 The Chromium Authors. All rights reserved. 2 # Copyright 2016 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 math 6 import math
7 import sys 7 import sys
8 8
9 import json5_generator 9 import json5_generator
10 import template_expander 10 import template_expander
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 """ 80 """
81 Returns a dictionary of enums to be generated, enum name -> [list of enum va lues] 81 Returns a dictionary of enums to be generated, enum name -> [list of enum va lues]
82 """ 82 """
83 enums = {} 83 enums = {}
84 for property_ in properties: 84 for property_ in properties:
85 # Only generate enums for keyword properties that use the default field_ storage_type. 85 # Only generate enums for keyword properties that use the default field_ storage_type.
86 if property_['keyword_only'] and property_['field_storage_type'] is None : 86 if property_['keyword_only'] and property_['field_storage_type'] is None :
87 enum_name = property_['type_name'] 87 enum_name = property_['type_name']
88 # From the Blink style guide: Enum members should use InterCaps with an initial capital letter. [names-enum-members] 88 # From the Blink style guide: Enum members should use InterCaps with an initial capital letter. [names-enum-members]
89 enum_values = [('k' + camel_case(k)) for k in property_['keywords']] 89 enum_values = [('k' + camel_case(k)) for k in property_['keywords']]
90
91 if enum_name in enums:
92 # There's an enum with the same name, check if the enum values a re the same
93 assert set(enums[enum_name]) == set(enum_values), \
94 ("'" + property_['name'] + "' can't have type_name '" + enum _name + "' "
95 "because it was used by a previous property, but with a dif ferent set of keywords. "
96 "Either give it a different name or ensure the keywords are the same.")
97
90 enums[enum_name] = enum_values 98 enums[enum_name] = enum_values
91 99
92 return enums 100 return enums
93 101
94 102
95 def _create_property_field(property_): 103 def _create_property_field(property_):
96 """ 104 """
97 Create a property field from a CSS property and return the Field object. 105 Create a property field from a CSS property and return the Field object.
98 """ 106 """
99 property_name = property_['name_for_methods'] 107 property_name = property_['name_for_methods']
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 def generate_base_computed_style_constants(self): 294 def generate_base_computed_style_constants(self):
287 return { 295 return {
288 'properties': self._properties, 296 'properties': self._properties,
289 'enums': self._generated_enums, 297 'enums': self._generated_enums,
290 'fields': self._fields, 298 'fields': self._fields,
291 'expected_total_field_bytes': self._expected_total_field_bytes, 299 'expected_total_field_bytes': self._expected_total_field_bytes,
292 } 300 }
293 301
294 if __name__ == '__main__': 302 if __name__ == '__main__':
295 json5_generator.Maker(ComputedStyleBaseWriter).main() 303 json5_generator.Maker(ComputedStyleBaseWriter).main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698