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

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

Issue 2692803002: Clean up type handling in make_computed_style_base.py. (Closed)
Patch Set: Update comments Created 3 years, 10 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/build/scripts/templates/ComputedStyleBase.h.tmpl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 af01def834510dff821fc21fe183a8f67123d5d6..a24ebf77efced89cf7d6c5161883e351b035c966 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
@@ -31,23 +31,28 @@ class Field(object):
regular member variables, or more complex storage like vectors or hashmaps.
Almost all properties will have at least one Field, often more than one.
- Fields also fall into various families, which determine the logic that is
- used to generate them. The available field families are:
+ Fields also fall into various roles, which determine the logic that is
+ used to generate them. The available field roles are:
- 'property', for fields that store CSS properties
- 'inherited_flag', for single-bit flags that store whether a property is
inherited by this style or set explicitly
+ - 'nonproperty', for fields that are not CSS properties
"""
# List of required attributes for a field which need to be passed in by
- # keyword arguments
+ # keyword arguments. See CSSProperties.json5 for an explanation of each
+ # attribute.
REQUIRED_ATTRIBUTES = set([
# Name of field
'name',
# Name of property field is for
'property_name',
- # Internal field storage type (storage_type_path can be None)
- 'storage_type',
- 'storage_type_path',
+ # Name of the type (e.g. EClear, int)
+ 'type_name',
+ # Path to predefined class for overriding generated types.
+ 'field_type_path',
+ # Affects how the field is generated (keyword, flag)
+ 'field_template',
# Bits needed for storage
'size',
# Default value for field
@@ -59,18 +64,18 @@ class Field(object):
'resetter_method_name',
])
- def __init__(self, field_family, **kwargs):
+ def __init__(self, field_role, **kwargs):
# Values common to all fields
# Set attributes from the keyword arguments
for attrib in Field.REQUIRED_ATTRIBUTES:
setattr(self, attrib, kwargs.pop(attrib))
- # Field family: one of these must be true
- self.is_property = field_family == 'property'
- self.is_inherited_flag = field_family == 'inherited_flag'
- self.is_nonproperty = field_family == 'nonproperty'
+ # Field role: one of these must be true
+ self.is_property = field_role == 'property'
+ self.is_inherited_flag = field_role == 'inherited_flag'
+ self.is_nonproperty = field_role == 'nonproperty'
assert (self.is_property, self.is_inherited_flag, self.is_nonproperty).count(True) == 1, \
- 'Field family has to be exactly one of: property, inherited_flag, nonproperty'
+ 'Field role has to be exactly one of: property, inherited_flag, nonproperty'
if self.is_property:
self.is_inherited = kwargs.pop('inherited')
@@ -91,8 +96,8 @@ def _create_enums(properties):
"""
enums = {}
for property_ in properties:
- # Only generate enums for keyword properties that use the default field_storage_type.
- if property_['keyword_only'] and property_['field_storage_type'] is None:
+ # Only generate enums for keyword properties that use the default field_type_path.
+ if property_['field_template'] == 'keyword' and property_['field_type_path'] is None:
enum_name = property_['type_name']
# From the Blink style guide: Enum members should use InterCaps with an initial capital letter. [names-enum-members]
enum_values = [('k' + camel_case(k)) for k in property_['keywords']]
@@ -118,15 +123,15 @@ def _create_property_field(property_):
# From the Blink style guide: Other data members should be prefixed by "m_". [names-data-members]
field_name = 'm_' + property_name_lower
- bits_needed = math.log(len(property_['keywords']), 2)
+ bits_needed = math.log(len(property_['keywords']), 2) # TODO: implement for non-enums
# Separate the type path from the type name, if specified.
- if property_['field_storage_type']:
- type_path = property_['field_storage_type']
- type_name = type_path.split('/')[-1]
+ if property_['field_type_path']:
+ field_type_path = property_['field_type_path']
+ type_name = field_type_path.split('/')[-1]
else:
+ field_type_path = None
type_name = property_['type_name']
- type_path = None
# For now, the getter name should match the field name. Later, getter names
# will start with an uppercase letter, so if they conflict with the type name,
@@ -136,19 +141,19 @@ def _create_property_field(property_):
getter_method_name = 'get' + property_name
assert property_['initial_keyword'] is not None, \
- ('MakeComputedStyleBase requires an initial keyword for keyword_only values, none specified '
+ ('MakeComputedStyleBase requires an initial keyword for keyword fields, none specified '
'for property ' + property_['name'])
default_value = type_name + '::k' + camel_case(property_['initial_keyword'])
- # Add the property itself as a member variable.
return Field(
'property',
name=field_name,
property_name=property_['name'],
inherited=property_['inherited'],
independent=property_['independent'],
- storage_type=type_name,
- storage_type_path=type_path,
+ type_name=type_name,
+ field_type_path=field_type_path,
+ field_template=property_['field_template'],
size=int(math.ceil(bits_needed)),
default_value=default_value,
getter_method_name=getter_method_name,
@@ -174,8 +179,9 @@ def _create_inherited_flag_field(property_):
'inherited_flag',
name='m_' + field_name_suffix_lower,
property_name=property_['name'],
- storage_type='bool',
- storage_type_path=None,
+ type_name='bool',
+ field_type_path=None,
+ field_template='flag',
size=1,
default_value='true',
getter_method_name=field_name_suffix_lower,
@@ -196,8 +202,9 @@ def _create_nonproperty_field(field_name):
'nonproperty',
name=member_name,
property_name=field_name,
- storage_type='bool',
- storage_type_path=None,
+ type_name='bool',
+ field_type_path=None,
+ field_template='flag',
size=1,
default_value='false',
getter_method_name=field_name,
@@ -213,8 +220,8 @@ def _create_fields(properties):
"""
fields = []
for property_ in properties:
- # Keywords only means we generate an enum field.
- if property_['keyword_only']:
+ # Only generate properties that have a field template
+ if property_['field_template'] is not None:
# If the property is independent, add the single-bit sized isInherited flag
# to the list of Fields as well.
if property_['independent']:
« no previous file with comments | « no previous file | third_party/WebKit/Source/build/scripts/templates/ComputedStyleBase.h.tmpl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698