| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 for a function in ComputedStyle. | 79 for a function in ComputedStyle. |
| 80 | 80 |
| 81 Attributes: | 81 Attributes: |
| 82 subgroups: List of DiffGroup instances that are stored as subgroups unde
r this group. | 82 subgroups: List of DiffGroup instances that are stored as subgroups unde
r this group. |
| 83 expressions: List of expression that are on this group that need to be d
iffed. | 83 expressions: List of expression that are on this group that need to be d
iffed. |
| 84 """ | 84 """ |
| 85 def __init__(self, group_name): | 85 def __init__(self, group_name): |
| 86 self.group_name = group_name | 86 self.group_name = group_name |
| 87 self.subgroups = [] | 87 self.subgroups = [] |
| 88 self.expressions = [] | 88 self.expressions = [] |
| 89 self.predicates = [] |
| 89 | 90 |
| 90 | 91 |
| 91 class Field(object): | 92 class Field(object): |
| 92 """ | 93 """ |
| 93 The generated ComputedStyle object is made up of a series of Fields. | 94 The generated ComputedStyle object is made up of a series of Fields. |
| 94 Each Field has a name, size, type, etc, and a bunch of attributes to | 95 Each Field has a name, size, type, etc, and a bunch of attributes to |
| 95 determine which methods it will be used in. | 96 determine which methods it will be used in. |
| 96 | 97 |
| 97 A Field also has enough information to use any storage type in C++, such as | 98 A Field also has enough information to use any storage type in C++, such as |
| 98 regular member variables, or more complex storage like vectors or hashmaps. | 99 regular member variables, or more complex storage like vectors or hashmaps. |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 groups[field.group_name].append(field) | 186 groups[field.group_name].append(field) |
| 186 | 187 |
| 187 no_group = groups.pop(None) | 188 no_group = groups.pop(None) |
| 188 subgroups = [Group(group_name, [], _reorder_fields(fields)) for group_name,
fields in groups.items()] | 189 subgroups = [Group(group_name, [], _reorder_fields(fields)) for group_name,
fields in groups.items()] |
| 189 return Group('', subgroups=subgroups, fields=_reorder_fields(no_group)) | 190 return Group('', subgroups=subgroups, fields=_reorder_fields(no_group)) |
| 190 | 191 |
| 191 | 192 |
| 192 def _create_diff_groups_map(diff_function_inputs, root_group): | 193 def _create_diff_groups_map(diff_function_inputs, root_group): |
| 193 diff_functions_map = {} | 194 diff_functions_map = {} |
| 194 for entry in diff_function_inputs: | 195 for entry in diff_function_inputs: |
| 195 diff_functions_map[entry['name']] = _create_diff_groups(entry['fields_to
_diff'], entry['methods_to_diff'], root_group) | 196 diff_functions_map[entry['name']] = _create_diff_groups(entry['fields_to
_diff'], |
| 197 entry['methods_t
o_diff'], entry['predicates_to_test'], root_group) |
| 196 return diff_functions_map | 198 return diff_functions_map |
| 197 | 199 |
| 198 | 200 |
| 199 def _list_field_dependencies(methods_to_diff): | 201 def _list_field_dependencies(entries_with_field_dependencies): |
| 200 field_dependencies = [] | 202 field_dependencies = [] |
| 201 for entry in methods_to_diff: | 203 for entry in entries_with_field_dependencies: |
| 202 field_dependencies += entry['field_dependencies'] | 204 field_dependencies += entry['field_dependencies'] |
| 203 return field_dependencies | 205 return field_dependencies |
| 204 | 206 |
| 205 | 207 |
| 206 def _create_diff_groups(fields_to_diff, methods_to_diff, root_group): | 208 def _create_diff_groups(fields_to_diff, methods_to_diff, predicates_to_test, roo
t_group): |
| 207 diff_group = DiffGroup(root_group.member_name) | 209 diff_group = DiffGroup(root_group.member_name) |
| 208 field_dependencies = _list_field_dependencies(methods_to_diff) | 210 field_dependencies = _list_field_dependencies(methods_to_diff + predicates_t
o_test) |
| 209 for subgroup in root_group.subgroups: | 211 for subgroup in root_group.subgroups: |
| 210 if any(field.property_name in (fields_to_diff + field_dependencies) for
field in subgroup.all_fields): | 212 if any(field.property_name in (fields_to_diff + field_dependencies) for
field in subgroup.all_fields): |
| 211 diff_group.subgroups.append(_create_diff_groups(fields_to_diff, meth
ods_to_diff, subgroup)) | 213 diff_group.subgroups.append(_create_diff_groups(fields_to_diff, meth
ods_to_diff, predicates_to_test, subgroup)) |
| 212 for field in root_group.fields: | 214 for field in root_group.fields: |
| 213 if not field.is_inherited_flag: | 215 if not field.is_inherited_flag: |
| 214 if field.property_name in fields_to_diff: | 216 if field.property_name in fields_to_diff: |
| 215 diff_group.expressions.append(field.getter_expression) | 217 diff_group.expressions.append(field.getter_expression) |
| 216 for entry in methods_to_diff: | 218 for entry in methods_to_diff: |
| 217 if field.property_name in entry['field_dependencies']: | 219 if field.property_name in entry['field_dependencies']: |
| 218 diff_group.expressions.append(entry['method']) | 220 diff_group.expressions.append(entry['method']) |
| 221 for entry in predicates_to_test: |
| 222 if field.property_name in entry['field_dependencies']: |
| 223 diff_group.predicates.append(entry['predicate']) |
| 219 return diff_group | 224 return diff_group |
| 220 | 225 |
| 221 | 226 |
| 222 def _create_enums(properties): | 227 def _create_enums(properties): |
| 223 """ | 228 """ |
| 224 Returns an OrderedDict of enums to be generated, enum name -> [list of enum
values] | 229 Returns an OrderedDict of enums to be generated, enum name -> [list of enum
values] |
| 225 """ | 230 """ |
| 226 enums = {} | 231 enums = {} |
| 227 for property_ in properties: | 232 for property_ in properties: |
| 228 # Only generate enums for keyword properties that use the default field_
type_path. | 233 # Only generate enums for keyword properties that use the default field_
type_path. |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 | 457 |
| 453 @template_expander.use_jinja('ComputedStyleBaseConstants.h.tmpl') | 458 @template_expander.use_jinja('ComputedStyleBaseConstants.h.tmpl') |
| 454 def generate_base_computed_style_constants(self): | 459 def generate_base_computed_style_constants(self): |
| 455 return { | 460 return { |
| 456 'properties': self._properties, | 461 'properties': self._properties, |
| 457 'enums': self._generated_enums, | 462 'enums': self._generated_enums, |
| 458 } | 463 } |
| 459 | 464 |
| 460 if __name__ == '__main__': | 465 if __name__ == '__main__': |
| 461 json5_generator.Maker(ComputedStyleBaseWriter).main() | 466 json5_generator.Maker(ComputedStyleBaseWriter).main() |
| OLD | NEW |