Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Unified Diff: third_party/WebKit/Source/build/scripts/make_computed_style_base.py

Issue 2914613002: Add keyword_subset field template and generate text-decoration-line. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 50dc4e572cf04b5179ad2ca2304fefc2cd0478f0..bab729020bd426ba306fdff530384d96fa935a1d 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
@@ -14,7 +14,7 @@ from name_utilities import (
enum_for_css_keyword, enum_type_name, enum_value_name, class_member_name, method_name,
class_name, join_name
)
-from collections import defaultdict, OrderedDict
+from collections import defaultdict
from itertools import chain
# Heuristic ordering of types from largest to smallest, used to sort fields by their alignment sizes.
@@ -74,6 +74,14 @@ class Group(object):
self.all_fields = _flatten_list(subgroup.all_fields for subgroup in subgroups) + fields
+class Enum(object):
+ """Represents a generated enum in ComputedStyleConstants."""
nainar 2017/05/30 04:13:45 ComputedStyleBaseConstants
+ def __init__(self, type_name, keywords, is_set):
+ self.type_name = type_name
+ self.values = [enum_value_name(keyword) for keyword in keywords]
+ self.is_set = is_set
nainar 2017/05/30 04:13:45 is_set -> is_subset
shend 2017/05/31 07:52:07 I decided not to change this one, since the enum i
+
+
class DiffGroup(object):
"""Represents a group of expressions and subgroups that need to be diffed
for a function in ComputedStyle.
@@ -227,27 +235,29 @@ def _create_diff_groups(fields_to_diff, methods_to_diff, predicates_to_test, roo
def _create_enums(properties):
- """
- Returns an OrderedDict of enums to be generated, enum name -> [list of enum values]
- """
+ """Returns a list of Enums to be generated"""
enums = {}
for property_ in properties:
# Only generate enums for keyword properties that do not require includes.
- if property_['field_template'] == 'keyword' and len(property_['include_paths']) == 0:
- enum_name = property_['type_name']
- enum_values = [enum_value_name(k) for k in property_['keywords']]
+ if property_['field_template'] in ('keyword', 'keyword_set') and len(property_['include_paths']) == 0:
nainar 2017/05/30 04:13:45 keyword_set -> keyword_subset
shend 2017/05/31 07:52:07 done.
+ enum = Enum(property_['type_name'], property_['keywords'],
+ is_set=(property_['field_template'] == 'keyword_set'))
+
+ if property_['field_template'] == 'keyword_set':
+ assert property_['keywords'][0] == 'none', \
+ "First keyword in a 'keyword_set' field must be 'none' in '{}'.".format(property_['name'])
- if enum_name in enums:
+ if enum.type_name in enums:
# There's an enum with the same name, check if the enum values are the same
- assert set(enums[enum_name]) == set(enum_values), \
- ("'" + property_['name'] + "' can't have type_name '" + enum_name + "' "
+ assert set(enums[enum.type_name].values) == set(enum.values), \
+ ("'" + property_['name'] + "' can't have type_name '" + enum.type_name + "' "
"because it was used by a previous property, but with a different set of keywords. "
"Either give it a different name or ensure the keywords are the same.")
- enums[enum_name] = enum_values
+ enums[enum.type_name] = enum
- # Return the enums sorted by key (enum name)
- return OrderedDict(sorted(enums.items(), key=lambda t: t[0]))
+ # Return the enums sorted by type name
+ return list(sorted(enums.values(), key=lambda e: e.type_name))
def _create_property_field(property_):
@@ -264,6 +274,10 @@ def _create_property_field(property_):
type_name = property_['type_name']
default_value = type_name + '::' + enum_value_name(property_['default_value'])
size = int(math.ceil(math.log(len(property_['keywords']), 2)))
+ elif property_['field_template'] == 'keyword_set':
+ type_name = property_['type_name']
+ default_value = type_name + '::' + enum_value_name(property_['default_value'])
+ size = len(property_['keywords']) - 1 # Subtract 1 for 'none' keyword
elif property_['field_template'] == 'storage_only':
# 'storage_only' fields need to specify a size, type_name and default_value
type_name = property_['type_name']

Powered by Google App Engine
This is Rietveld 408576698