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

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

Issue 2667543002: Moved nonproperty 'unique' to be generated in ComputedStyleBase. (Closed)
Patch Set: Rebase 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 | third_party/WebKit/Source/build/scripts/templates/ComputedStyleBase.h.tmpl » ('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 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
11 import make_style_builder 11 import make_style_builder
12 12
13 from name_utilities import camel_case, lower_first 13 from name_utilities import camel_case, lower_first, upper_first_letter
14
15
16 # Temporary hard-coded list of fields that are not CSS properties.
17 # Ideally these would be specified in a .in or .json5 file.
18 NONPROPERTY_FIELDS = set([
19 # Style can not be shared.
20 'unique',
21 ])
14 22
15 23
16 class Field(object): 24 class Field(object):
17 """ 25 """
18 The generated ComputedStyle object is made up of a series of Fields. 26 The generated ComputedStyle object is made up of a series of Fields.
19 Each Field has a name, size, type, etc, and a bunch of attributes to 27 Each Field has a name, size, type, etc, and a bunch of attributes to
20 determine which methods it will be used in. 28 determine which methods it will be used in.
21 29
22 A Field also has enough information to use any storage type in C++, such as 30 A Field also has enough information to use any storage type in C++, such as
23 regular member variables, or more complex storage like vectors or hashmaps. 31 regular member variables, or more complex storage like vectors or hashmaps.
(...skipping 29 matching lines...) Expand all
53 61
54 def __init__(self, field_family, **kwargs): 62 def __init__(self, field_family, **kwargs):
55 # Values common to all fields 63 # Values common to all fields
56 # Set attributes from the keyword arguments 64 # Set attributes from the keyword arguments
57 for attrib in Field.REQUIRED_ATTRIBUTES: 65 for attrib in Field.REQUIRED_ATTRIBUTES:
58 setattr(self, attrib, kwargs.pop(attrib)) 66 setattr(self, attrib, kwargs.pop(attrib))
59 67
60 # Field family: one of these must be true 68 # Field family: one of these must be true
61 self.is_property = field_family == 'property' 69 self.is_property = field_family == 'property'
62 self.is_inherited_flag = field_family == 'inherited_flag' 70 self.is_inherited_flag = field_family == 'inherited_flag'
63 assert (self.is_property, self.is_inherited_flag).count(True) == 1, \ 71 self.is_nonproperty = field_family == 'nonproperty'
64 'Field family has to be exactly one of: property, inherited_flag' 72 assert (self.is_property, self.is_inherited_flag, self.is_nonproperty).c ount(True) == 1, \
73 'Field family has to be exactly one of: property, inherited_flag, no nproperty'
65 74
66 if self.is_property: 75 if self.is_property:
67 self.is_inherited = kwargs.pop('inherited') 76 self.is_inherited = kwargs.pop('inherited')
68 self.is_independent = kwargs.pop('independent') 77 self.is_independent = kwargs.pop('independent')
69 assert self.is_inherited or not self.is_independent, 'Only inherited fields can be independent' 78 assert self.is_inherited or not self.is_independent, 'Only inherited fields can be independent'
70 79
71 self.is_inherited_method_name = kwargs.pop('is_inherited_method_name ') 80 self.is_inherited_method_name = kwargs.pop('is_inherited_method_name ')
72 elif self.is_inherited_flag: 81 elif self.is_inherited_flag:
73 # Inherited flag-only fields 82 # Inherited flag-only fields
74 pass 83 pass
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 storage_type_path=None, 178 storage_type_path=None,
170 size=1, 179 size=1,
171 default_value='true', 180 default_value='true',
172 getter_method_name=field_name_suffix_lower, 181 getter_method_name=field_name_suffix_lower,
173 setter_method_name='set' + field_name_suffix_upper, 182 setter_method_name='set' + field_name_suffix_upper,
174 initial_method_name='initial' + field_name_suffix_upper, 183 initial_method_name='initial' + field_name_suffix_upper,
175 resetter_method_name='reset' + field_name_suffix_upper, 184 resetter_method_name='reset' + field_name_suffix_upper,
176 ) 185 )
177 186
178 187
188 def _create_nonproperty_field(field_name):
189 """
190 Create a nonproperty field from its name and return the Field object.
191 """
192 member_name = 'm_' + field_name
193 field_name_upper = upper_first_letter(field_name)
194
195 return Field(
196 'nonproperty',
197 name=member_name,
198 property_name=field_name,
199 storage_type='bool',
200 storage_type_path=None,
201 size=1,
202 default_value='false',
203 getter_method_name=field_name,
204 setter_method_name='set' + field_name_upper,
205 initial_method_name='initial' + field_name_upper,
206 resetter_method_name='reset' + field_name_upper,
207 )
208
209
179 def _create_fields(properties): 210 def _create_fields(properties):
180 """ 211 """
181 Create ComputedStyle fields from CSS properties and return a list of Field o bjects. 212 Create ComputedStyle fields from CSS properties and return a list of Field o bjects.
182 """ 213 """
183 fields = [] 214 fields = []
184 for property_ in properties: 215 for property_ in properties:
185 # Keywords only means we generate an enum field. 216 # Keywords only means we generate an enum field.
186 if property_['keyword_only']: 217 if property_['keyword_only']:
187 # If the property is independent, add the single-bit sized isInherit ed flag 218 # If the property is independent, add the single-bit sized isInherit ed flag
188 # to the list of Fields as well. 219 # to the list of Fields as well.
189 if property_['independent']: 220 if property_['independent']:
190 fields.append(_create_inherited_flag_field(property_)) 221 fields.append(_create_inherited_flag_field(property_))
191 222
192 fields.append(_create_property_field(property_)) 223 fields.append(_create_property_field(property_))
193 224
225 for field_name in NONPROPERTY_FIELDS:
226 fields.append(_create_nonproperty_field(field_name))
227
194 return fields 228 return fields
195 229
196 230
197 def _pack_fields(fields): 231 def _pack_fields(fields):
198 """ 232 """
199 Group a list of fields into buckets to minimise padding. 233 Group a list of fields into buckets to minimise padding.
200 Returns a list of buckets, where each bucket is a list of Field objects. 234 Returns a list of buckets, where each bucket is a list of Field objects.
201 """ 235 """
202 # Since fields cannot cross word boundaries, in order to minimize 236 # Since fields cannot cross word boundaries, in order to minimize
203 # padding, group fields into buckets so that as many buckets as possible 237 # padding, group fields into buckets so that as many buckets as possible
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 def generate_base_computed_style_constants(self): 328 def generate_base_computed_style_constants(self):
295 return { 329 return {
296 'properties': self._properties, 330 'properties': self._properties,
297 'enums': self._generated_enums, 331 'enums': self._generated_enums,
298 'fields': self._fields, 332 'fields': self._fields,
299 'expected_total_field_bytes': self._expected_total_field_bytes, 333 'expected_total_field_bytes': self._expected_total_field_bytes,
300 } 334 }
301 335
302 if __name__ == '__main__': 336 if __name__ == '__main__':
303 json5_generator.Maker(ComputedStyleBaseWriter).main() 337 json5_generator.Maker(ComputedStyleBaseWriter).main()
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/build/scripts/templates/ComputedStyleBase.h.tmpl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698