Commit 43a287c7 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

ComputedStyle: Take into account of aliases in ranking data

Property aliases in css_properties_ranking.json5 were ignored while
ComputedStyle generation.  So, if an alias rank is higher than the
rank of the corresponding real one, the generated field could be added
to a deeper layer though the field is used frequently.

This CL changes make_computed_style_base.py so that it takes into
account of alias rankings.

 - Introduce _best_rank() to determine the best ranking value including
   aliases.
 - _evaluate_rare_non_inherited_group() and
   _evaluate_rare_inherit_group() use _best_rank() instead of
   properties_ranking[property_['name'].original]

This change moves |backface_visibility_| to a shallower layer.
This CL is a preparation to add 'appearance' property and make
'-webkit-appearance' its alias.

Bug: 963551
Change-Id: I120ee0aa250671ef8f86806ca653eb2cec63ba85
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2086468
Commit-Queue: Kent Tamura <tkent@chromium.org>
Reviewed-by: default avatarAnders Hartvoll Ruud <andruud@chromium.org>
Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#747503}
parent 19f8abc5
......@@ -234,6 +234,8 @@ class CSSProperties(object):
alias['name'])
aliased_property = self._properties_by_id[
id_for_css_property(alias['alias_for'])]
aliased_property.setdefault('aliases', [])
aliased_property['aliases'].append(alias['name'].original)
updated_alias = aliased_property.copy()
updated_alias['name'] = alias['name']
updated_alias['alias_for'] = alias['alias_for']
......
......@@ -403,6 +403,21 @@ def _get_properties_ranking_using_partition_rule(
for i in range(len(properties_ranking))]))
def _best_rank(prop, ranking_map):
"""Return the best ranking value for the specified property.
This function collects ranking values for not only the property's real name
but also its aliases, and returns the best (lower is better) value.
If no ranking values for the property is available, this returns -1.
"""
worst_rank = max(ranking_map.values()) + 1
best_rank = ranking_map.get(prop["name"].original, worst_rank)
for alias_name in prop.get("aliases", []):
best_rank = min(best_rank, ranking_map.get(alias_name, worst_rank))
return best_rank if best_rank != worst_rank else -1
def _evaluate_rare_non_inherited_group(properties, properties_ranking,
num_layers, partition_rule=None):
"""Re-evaluate the grouping of RareNonInherited groups based on each
......@@ -431,21 +446,19 @@ def _evaluate_rare_non_inherited_group(properties, properties_ranking,
properties_ranking, partition_rule)
for property_ in properties:
if (property_["field_group"] is not None and
"*" in property_["field_group"]
and not property_["inherited"] and
property_["name"].original in properties_ranking):
rank = _best_rank(property_, properties_ranking)
if (property_["field_group"] is not None
and "*" in property_["field_group"]
and not property_["inherited"] and rank >= 0):
assert property_["field_group"] == "*", \
"The property {} will be automatically assigned a group, " \
"please put '*' as the field_group".format(property_['name'])
property_["field_group"] = "->".join(
layers_name[0:properties_ranking[property_["name"].original]])
elif property_["field_group"] is not None and \
"*" in property_["field_group"] and \
not property_["inherited"] and \
property_["name"].original not in properties_ranking:
property_["field_group"] = "->".join(layers_name[0:rank])
elif (property_["field_group"] is not None
and "*" in property_["field_group"]
and not property_["inherited"] and rank < 0):
group_tree = property_["field_group"].split("->")[1:]
group_tree = [layers_name[0], layers_name[0] + "-sub"] + group_tree
property_["field_group"] = "->".join(group_tree)
......@@ -481,16 +494,14 @@ def _evaluate_rare_inherit_group(properties, properties_ranking,
properties_ranking, partition_rule)
for property_ in properties:
if property_["field_group"] is not None and \
"*" in property_["field_group"] \
and property_["inherited"] and \
property_["name"].original in properties_ranking:
property_["field_group"] = "->".join(
layers_name[0:properties_ranking[property_["name"].original]])
elif property_["field_group"] is not None and \
"*" in property_["field_group"] \
and property_["inherited"] and \
property_["name"].original not in properties_ranking:
rank = _best_rank(property_, properties_ranking)
if (property_["field_group"] is not None
and "*" in property_["field_group"] and property_["inherited"]
and rank >= 0):
property_["field_group"] = "->".join(layers_name[0:rank])
elif (property_["field_group"] is not None
and "*" in property_["field_group"] and property_["inherited"]
and rank < 0):
group_tree = property_["field_group"].split("->")[1:]
group_tree = [layers_name[0], layers_name[0] + "-sub"] + group_tree
property_["field_group"] = "->".join(group_tree)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment