OLD | NEW |
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, upper_first_letter, enum_for
_css_keyword | 13 from name_utilities import camel_case, lower_first, upper_first_letter, enum_for
_css_keyword |
14 | 14 |
15 | 15 |
16 # Temporary hard-coded list of fields that are not CSS properties. | 16 # Temporary hard-coded list of fields that are not CSS properties. |
17 # Ideally these would be specified in a .json5 file. | 17 # Ideally these would be specified in a .json5 file. |
18 NONPROPERTY_FIELDS = [ | 18 NONPROPERTY_FIELDS = [ |
19 {'name': 'isLink', 'field_template': 'monotonic_flag'}, | 19 {'name': 'isLink', 'field_template': 'monotonic_flag'}, |
20 # Style can not be shared. | 20 # Style can not be shared. |
21 {'name': 'unique', 'field_template': 'monotonic_flag'}, | 21 {'name': 'unique', 'field_template': 'monotonic_flag'}, |
22 # Whether this style is affected by these pseudo-classes. | 22 # Whether this style is affected by these pseudo-classes. |
23 {'name': 'affectedByFocus', 'field_template': 'monotonic_flag'}, | 23 {'name': 'affectedByFocus', 'field_template': 'monotonic_flag'}, |
24 {'name': 'affectedByHover', 'field_template': 'monotonic_flag'}, | 24 {'name': 'affectedByHover', 'field_template': 'monotonic_flag'}, |
25 {'name': 'affectedByActive', 'field_template': 'monotonic_flag'}, | 25 {'name': 'affectedByActive', 'field_template': 'monotonic_flag'}, |
26 {'name': 'affectedByDrag', 'field_template': 'monotonic_flag'}, | 26 {'name': 'affectedByDrag', 'field_template': 'monotonic_flag'}, |
27 # A non-inherited property references a variable or @apply is used | 27 # A non-inherited property references a variable or @apply is used |
28 {'name': 'hasVariableReferenceFromNonInheritedProperty', 'field_template': '
monotonic_flag'}, | 28 {'name': 'hasVariableReferenceFromNonInheritedProperty', 'field_template': '
monotonic_flag'}, |
29 # Explicitly inherits a non-inherited property | 29 # Explicitly inherits a non-inherited property |
30 {'name': 'hasExplicitlyInheritedProperties', 'field_template': 'monotonic_fl
ag'} | 30 {'name': 'hasExplicitlyInheritedProperties', 'field_template': 'monotonic_fl
ag'}, |
| 31 # These properties only have generated storage, and their methods are handwr
itten in ComputedStyle. |
| 32 # TODO(shend): Remove these fields and delete the 'storage_only' template. |
| 33 {'name': 'emptyState', 'field_template': 'storage_only', 'size': 1} |
31 ] | 34 ] |
32 | 35 |
33 | 36 |
34 class Field(object): | 37 class Field(object): |
35 """ | 38 """ |
36 The generated ComputedStyle object is made up of a series of Fields. | 39 The generated ComputedStyle object is made up of a series of Fields. |
37 Each Field has a name, size, type, etc, and a bunch of attributes to | 40 Each Field has a name, size, type, etc, and a bunch of attributes to |
38 determine which methods it will be used in. | 41 determine which methods it will be used in. |
39 | 42 |
40 A Field also has enough information to use any storage type in C++, such as | 43 A Field also has enough information to use any storage type in C++, such as |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 initial_method_name='initial' + field_name_suffix_upper, | 202 initial_method_name='initial' + field_name_suffix_upper, |
200 resetter_method_name='reset' + field_name_suffix_upper, | 203 resetter_method_name='reset' + field_name_suffix_upper, |
201 ) | 204 ) |
202 | 205 |
203 | 206 |
204 def _create_nonproperty_field(property_): | 207 def _create_nonproperty_field(property_): |
205 """ | 208 """ |
206 Create a nonproperty field from an entry in NONPROPERTY_FIELDS and return th
e Field object. | 209 Create a nonproperty field from an entry in NONPROPERTY_FIELDS and return th
e Field object. |
207 """ | 210 """ |
208 # TODO(shend): Make this work for nonflags | 211 # TODO(shend): Make this work for nonflags |
209 assert property_['field_template'] in ('flag', 'monotonic_flag'), \ | 212 assert property_['field_template'] in ('flag', 'monotonic_flag', 'storage_on
ly'), \ |
210 "Nonproperties with arbitrary templates are not yet supported" | 213 "Nonproperties with arbitrary templates are not yet supported" |
211 member_name = 'm_' + property_['name'] | 214 member_name = 'm_' + property_['name'] |
212 field_name_upper = upper_first_letter(property_['name']) | 215 field_name_upper = upper_first_letter(property_['name']) |
213 | 216 |
| 217 if property_['field_template'] == 'storage_only': |
| 218 assert 'size' in property_, 'storage_only fields need to specify a size' |
| 219 size = property_['size'] |
| 220 else: |
| 221 # Otherwise the field must be some type of flag. |
| 222 size = 1 |
| 223 |
214 return Field( | 224 return Field( |
215 'nonproperty', | 225 'nonproperty', |
216 name=member_name, | 226 name=member_name, |
217 property_name=property_['name'], | 227 property_name=property_['name'], |
218 type_name='bool', | 228 type_name='bool', |
219 field_template=property_['field_template'], | 229 field_template=property_['field_template'], |
220 size=1, | 230 size=size, |
221 default_value='false', | 231 default_value='false', |
222 getter_method_name=property_['name'], | 232 getter_method_name=property_['name'], |
223 setter_method_name='set' + field_name_upper, | 233 setter_method_name='set' + field_name_upper, |
224 initial_method_name='initial' + field_name_upper, | 234 initial_method_name='initial' + field_name_upper, |
225 resetter_method_name='reset' + field_name_upper, | 235 resetter_method_name='reset' + field_name_upper, |
226 ) | 236 ) |
227 | 237 |
228 | 238 |
229 def _create_fields(properties): | 239 def _create_fields(properties): |
230 """ | 240 """ |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 'mapping': [('k' + camel_case(k), enum_for_css_keyword(k)) f
or k in property_['keywords']], | 386 'mapping': [('k' + camel_case(k), enum_for_css_keyword(k)) f
or k in property_['keywords']], |
377 } | 387 } |
378 | 388 |
379 return { | 389 return { |
380 'include_paths': self._include_paths, | 390 'include_paths': self._include_paths, |
381 'mappings': mappings, | 391 'mappings': mappings, |
382 } | 392 } |
383 | 393 |
384 if __name__ == '__main__': | 394 if __name__ == '__main__': |
385 json5_generator.Maker(ComputedStyleBaseWriter).main() | 395 json5_generator.Maker(ComputedStyleBaseWriter).main() |
OLD | NEW |