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 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 {'name': 'HasExplicitlyInheritedProperties', 'field_template': 'monotonic_fl
ag', | 51 {'name': 'HasExplicitlyInheritedProperties', 'field_template': 'monotonic_fl
ag', |
52 'inherited': False, 'independent': False, 'default_value': False}, | 52 'inherited': False, 'independent': False, 'default_value': False}, |
53 # These are set if we used viewport or rem units when resolving a length. | 53 # These are set if we used viewport or rem units when resolving a length. |
54 # TODO(shend): HasViewportUnits should be a monotonic_flag. | 54 # TODO(shend): HasViewportUnits should be a monotonic_flag. |
55 {'name': 'HasViewportUnits', 'field_template': 'primitive', 'default_value':
'false', | 55 {'name': 'HasViewportUnits', 'field_template': 'primitive', 'default_value':
'false', |
56 'type_name': 'bool', 'inherited': False, 'independent': False}, | 56 'type_name': 'bool', 'inherited': False, 'independent': False}, |
57 {'name': 'HasRemUnits', 'field_template': 'monotonic_flag', 'default_value':
'false', | 57 {'name': 'HasRemUnits', 'field_template': 'monotonic_flag', 'default_value':
'false', |
58 'inherited': False, 'independent': False}, | 58 'inherited': False, 'independent': False}, |
59 # These properties only have generated storage, and their methods are handwr
itten in ComputedStyle. | 59 # These properties only have generated storage, and their methods are handwr
itten in ComputedStyle. |
60 # TODO(shend): Remove these fields and delete the 'storage_only' template. | 60 # TODO(shend): Remove these fields and delete the 'storage_only' template. |
61 {'name': 'EmptyState', 'field_template': 'storage_only', 'size': 1, 'default
_value': 'false', | 61 {'name': 'EmptyState', 'field_template': 'storage_only', 'field_size': 1, 'd
efault_value': 'false', |
62 'type_name': 'bool', 'inherited': False, 'independent': False}, | 62 'type_name': 'bool', 'inherited': False, 'independent': False}, |
63 {'name': 'StyleType', 'field_template': 'storage_only', 'size': 6, 'default_
value': '0', | 63 {'name': 'StyleType', 'field_template': 'storage_only', 'field_size': 6, 'de
fault_value': '0', |
64 'type_name': 'PseudoId', 'inherited': False, 'independent': False}, | 64 'type_name': 'PseudoId', 'inherited': False, 'independent': False}, |
65 {'name': 'PseudoBits', 'field_template': 'storage_only', 'size': 8, 'default
_value': 'kPseudoIdNone', | 65 {'name': 'PseudoBits', 'field_template': 'storage_only', 'field_size': 8, 'd
efault_value': 'kPseudoIdNone', |
66 'type_name': 'PseudoId', 'inherited': False, 'independent': False}, | 66 'type_name': 'PseudoId', 'inherited': False, 'independent': False}, |
67 # True if 'underline solid' is the only text decoration on this element. | 67 # True if 'underline solid' is the only text decoration on this element. |
68 {'name': 'HasSimpleUnderline', 'field_template': 'storage_only', 'size': 1,
'default_value': 'false', | 68 {'name': 'HasSimpleUnderline', 'field_template': 'storage_only', 'field_size
': 1, 'default_value': 'false', |
69 'type_name': 'bool', 'inherited': True, 'independent': False}, | 69 'type_name': 'bool', 'inherited': True, 'independent': False}, |
70 # TODO(shend): vertical align is actually a CSS property, but since we don't
support union fields | 70 # TODO(shend): vertical align is actually a CSS property, but since we don't
support union fields |
71 # which can be either a keyword or Length, this is generated as a nonpropert
y for now. Remove this | 71 # which can be either a keyword or Length, this is generated as a nonpropert
y for now. Remove this |
72 # once we can support union fields and groups. | 72 # once we can support union fields and groups. |
73 {'name': 'VerticalAlign', 'field_template': 'storage_only', 'size': 4, 'defa
ult_value': 'EVerticalAlign::kBaseline', | 73 {'name': 'VerticalAlign', 'field_template': 'storage_only', 'field_size': 4,
'default_value': 'EVerticalAlign::kBaseline', |
74 'type_name': 'EVerticalAlign', 'inherited': False, 'independent': False}, | 74 'type_name': 'EVerticalAlign', 'inherited': False, 'independent': False}, |
75 ] | 75 ] |
76 | 76 |
77 | 77 |
78 class Field(object): | 78 class Field(object): |
79 """ | 79 """ |
80 The generated ComputedStyle object is made up of a series of Fields. | 80 The generated ComputedStyle object is made up of a series of Fields. |
81 Each Field has a name, size, type, etc, and a bunch of attributes to | 81 Each Field has a name, size, type, etc, and a bunch of attributes to |
82 determine which methods it will be used in. | 82 determine which methods it will be used in. |
83 | 83 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 'for property ' + property_['name']) | 192 'for property ' + property_['name']) |
193 | 193 |
194 if property_['field_template'] == 'keyword': | 194 if property_['field_template'] == 'keyword': |
195 type_name = property_['type_name'] | 195 type_name = property_['type_name'] |
196 default_value = type_name + '::' + enum_value_name(property_['default_va
lue']) | 196 default_value = type_name + '::' + enum_value_name(property_['default_va
lue']) |
197 size = int(math.ceil(math.log(len(property_['keywords']), 2))) | 197 size = int(math.ceil(math.log(len(property_['keywords']), 2))) |
198 elif property_['field_template'] == 'storage_only': | 198 elif property_['field_template'] == 'storage_only': |
199 # 'storage_only' fields need to specify a size, type_name and default_va
lue | 199 # 'storage_only' fields need to specify a size, type_name and default_va
lue |
200 type_name = property_['type_name'] | 200 type_name = property_['type_name'] |
201 default_value = property_['default_value'] | 201 default_value = property_['default_value'] |
202 size = property_['size'] | 202 size = property_['field_size'] |
203 elif property_['field_template'] == 'external': | 203 elif property_['field_template'] == 'external': |
204 type_name = property_['type_name'] | 204 type_name = property_['type_name'] |
205 default_value = property_['default_value'] | 205 default_value = property_['default_value'] |
206 size = None | 206 size = None |
207 elif property_['field_template'] == 'primitive': | 207 elif property_['field_template'] == 'primitive': |
208 type_name = property_['type_name'] | 208 type_name = property_['type_name'] |
209 default_value = property_['default_value'] | 209 default_value = property_['default_value'] |
210 size = 1 if type_name == 'bool' else None # pack bools with 1 bit. | 210 size = 1 if type_name == 'bool' else None # pack bools with 1 bit. |
211 else: | 211 else: |
212 assert property_['field_template'] in ('monotonic_flag',) | 212 assert property_['field_template'] in ('monotonic_flag',) |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 # since the JSON5 reader will handle missing fields and defaults. | 310 # since the JSON5 reader will handle missing fields and defaults. |
311 for property_ in NONPROPERTIES: | 311 for property_ in NONPROPERTIES: |
312 property_['name_for_methods'] = property_['name'] | 312 property_['name_for_methods'] = property_['name'] |
313 if 'field_type_path' not in property_: | 313 if 'field_type_path' not in property_: |
314 property_['field_type_path'] = None | 314 property_['field_type_path'] = None |
315 if 'type_name' not in property_: | 315 if 'type_name' not in property_: |
316 property_['type_name'] = 'E' + enum_type_name(property_['name_fo
r_methods']) | 316 property_['type_name'] = 'E' + enum_type_name(property_['name_fo
r_methods']) |
317 | 317 |
318 property_values = self._properties.values() | 318 property_values = self._properties.values() |
319 | 319 |
320 # Override the type name when field_type_path is specified | |
321 for property_ in property_values: | 320 for property_ in property_values: |
| 321 # Override the type name when field_type_path is specified |
322 if property_['field_type_path']: | 322 if property_['field_type_path']: |
323 property_['type_name'] = property_['field_type_path'].split('/')
[-1] | 323 property_['type_name'] = property_['field_type_path'].split('/')
[-1] |
| 324 # CSS properties are not allowed to explicitly specify their field_s
ize. |
| 325 property_['field_size'] = None |
324 | 326 |
325 self._generated_enums = _create_enums(property_values + NONPROPERTIES) | 327 self._generated_enums = _create_enums(property_values + NONPROPERTIES) |
326 | 328 |
327 all_fields = (_create_fields('property', property_values) + | 329 all_fields = (_create_fields('property', property_values) + |
328 _create_fields('nonproperty', NONPROPERTIES)) | 330 _create_fields('nonproperty', NONPROPERTIES)) |
329 | 331 |
330 # Separate the normal fields from the bit fields | 332 # Separate the normal fields from the bit fields |
331 bit_fields = [field for field in all_fields if field.is_bit_field] | 333 bit_fields = [field for field in all_fields if field.is_bit_field] |
332 normal_fields = [field for field in all_fields if not field.is_bit_field
] | 334 normal_fields = [field for field in all_fields if not field.is_bit_field
] |
333 | 335 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 'mapping': [(enum_value_name(k), enum_for_css_keyword(k)) fo
r k in property_['keywords']], | 404 'mapping': [(enum_value_name(k), enum_for_css_keyword(k)) fo
r k in property_['keywords']], |
403 } | 405 } |
404 | 406 |
405 return { | 407 return { |
406 'include_paths': self._include_paths, | 408 'include_paths': self._include_paths, |
407 'mappings': mappings, | 409 'mappings': mappings, |
408 } | 410 } |
409 | 411 |
410 if __name__ == '__main__': | 412 if __name__ == '__main__': |
411 json5_generator.Maker(ComputedStyleBaseWriter).main() | 413 json5_generator.Maker(ComputedStyleBaseWriter).main() |
OLD | NEW |