Chromium Code Reviews| Index: third_party/WebKit/Source/build/scripts/make_computed_style_base.py |
| diff --git a/third_party/WebKit/Source/build/scripts/make_computed_style_base.py b/third_party/WebKit/Source/build/scripts/make_computed_style_base.py |
| index a181350f4317cdd9e5071746d0333e3497525437..f6c3dd2537c8b0493ab4b189d8447031c939c79a 100755 |
| --- a/third_party/WebKit/Source/build/scripts/make_computed_style_base.py |
| +++ b/third_party/WebKit/Source/build/scripts/make_computed_style_base.py |
| @@ -74,6 +74,19 @@ class Group(object): |
| self.all_fields = _flatten_list(subgroup.all_fields for subgroup in subgroups) + fields |
| +class DiffGroup(object): |
| + """Represents a group of expressions and subgroups that need to be diffed |
| + for a function in ComputedStyle. |
| + |
| + Attributes: |
| + subgroups: List of DiffGroup instances that are stored as subgroups under this group. |
| + expressions: List of expression that are on this group that need to be diffed. |
| + """ |
| + def __init__(self, group_name): |
| + self.group_name = group_name |
| + self.subgroups = [] |
| + self.expressions = [] |
| + |
|
alancutter (OOO until 2018)
2017/05/12 04:04:50
Two newlines between class definitions.
nainar
2017/05/12 05:05:36
Done.
|
| class Field(object): |
| """ |
| The generated ComputedStyle object is made up of a series of Fields. |
| @@ -139,6 +152,10 @@ class Field(object): |
| self.internal_setter_method_name = method_name(join_name(setter_method_name, 'Internal')) |
| self.initial_method_name = initial_method_name |
| self.resetter_method_name = method_name(join_name('Reset', name_for_methods)) |
| + if self.group_name: |
| + self.getter_expression = self.group_member_name + '->' + class_member_name(self.name) |
| + else: |
| + self.getter_expression = class_member_name(self.name) |
| # If the size of the field is not None, it means it is a bit field |
| self.is_bit_field = self.size is not None |
| @@ -168,6 +185,24 @@ def _group_fields(fields): |
| return Group('', subgroups=subgroups, fields=_reorder_fields(no_group)) |
| +def _create_diff_groups_map(diff_function_inputs, root_group): |
| + diff_functions_map = {} |
| + for entry in diff_function_inputs: |
| + diff_functions_map[entry['name']] = _create_diff_groups(entry['fields'], root_group) |
| + return diff_functions_map |
| + |
| + |
| +def _create_diff_groups(fields_to_diff, root_group): |
| + diff_group = DiffGroup(root_group.member_name) |
| + for subgroup in root_group.subgroups: |
| + if any(field.property_name in fields_to_diff for field in subgroup.all_fields): |
| + diff_group.subgroups.append(_create_diff_groups(fields_to_diff, subgroup)) |
| + for field in root_group.fields: |
| + if field.property_name in fields_to_diff: |
| + diff_group.expressions.append(field.getter_expression) |
| + return diff_group |
| + |
| + |
| def _create_enums(properties): |
| """ |
| Returns an OrderedDict of enums to be generated, enum name -> [list of enum values] |
| @@ -373,6 +408,9 @@ class ComputedStyleBaseWriter(make_style_builder.StyleBuilderWriter): |
| # Organise fields into a tree structure where the root group |
| # is ComputedStyleBase. |
| self._root_group = _group_fields(all_fields) |
| + self._diff_functions_map = _create_diff_groups_map(json5_generator.Json5File.load_from_files( |
| + [json5_file_paths[2]] |
| + ).name_dictionaries, self._root_group) |
| self._include_paths = _get_include_paths(all_properties) |
| self._outputs = { |
| @@ -396,6 +434,7 @@ class ComputedStyleBaseWriter(make_style_builder.StyleBuilderWriter): |
| 'properties': self._properties, |
| 'enums': self._generated_enums, |
| 'computed_style': self._root_group, |
| + 'diff_functions_map': self._diff_functions_map, |
| } |
| @template_expander.use_jinja('ComputedStyleBaseConstants.h.tmpl') |