def expand_parameters(self, property_): def set_if_none(property_, key, value): if key not in property_ or property_[key] is None: property_[key] = value # Basic info. name = property_['name'] property_['property_id'] = id_for_css_property(name) property_['enum_key'] = enum_key_for_css_property(name) property_['is_internal'] = name.original.startswith('-internal-') method_name = property_['name_for_methods'] if not method_name: method_name = name.to_upper_camel_case().replace('Webkit', '') set_if_none(property_, 'inherited', False) # Initial function, Getters and Setters for ComputedStyle. set_if_none(property_, 'initial', 'Initial' + method_name) simple_type_name = str(property_['type_name']).split('::')[-1] set_if_none(property_, 'name_for_methods', method_name) set_if_none(property_, 'type_name', 'E' + method_name) set_if_none( property_, 'getter', method_name if simple_type_name != method_name else 'Get' + method_name) set_if_none(property_, 'setter', 'Set' + method_name) if property_['inherited']: property_['is_inherited_setter'] = ('Set' + method_name + 'IsInherited') property_['is_animation_property'] = ( property_['priority'] == 'Animation') # Figure out whether this property should have style builders at all. # E.g. shorthands do not get style builders. property_['style_builder_declare'] = (property_['is_property'] and not property_['longhands']) # Figure out whether we should generate style builder implementations. for x in ['initial', 'inherit', 'value']: suppressed = x in property_['style_builder_custom_functions'] declared = property_['style_builder_declare'] property_['style_builder_generate_%s' % x] = (declared and not suppressed) # Expand StyleBuilderConverter params where necessary. if property_['type_name'] in PRIMITIVE_TYPES: set_if_none(property_, 'converter', 'CSSPrimitiveValue') else: set_if_none(property_, 'converter', 'CSSIdentifierValue') assert not property_['alias_for'], \ 'Use expand_aliases to expand aliases' if not property_['longhands']: property_['superclass'] = 'Longhand' property_['namespace_group'] = 'Longhand' elif property_['longhands']: property_['superclass'] = 'Shorthand' property_['namespace_group'] = 'Shorthand' # Expand out field templates. if property_['field_template']: self._field_alias_expander.expand_field_alias(property_) type_name = property_['type_name'] if (property_['field_template'] == 'keyword' or property_['field_template'] == 'multi_keyword'): default_value = (type_name + '::' + NameStyleConverter( property_['default_value']).to_enum_value()) elif (property_['field_template'] == 'external' or property_['field_template'] == 'primitive' or property_['field_template'] == 'pointer'): default_value = property_['default_value'] else: assert property_['field_template'] == 'monotonic_flag', \ "Please put a valid value for field_template; got " + \ str(property_['field_template']) property_['type_name'] = 'bool' default_value = 'false' property_['default_value'] = default_value property_['unwrapped_type_name'] = property_['type_name'] if property_['wrapper_pointer_name']: assert property_['field_template'] in ['pointer', 'external'] if property_['field_template'] == 'external': property_['type_name'] = '{}<{}>'.format( property_['wrapper_pointer_name'], type_name) # Default values for extra parameters in computed_style_extra_fields.json5. set_if_none(property_, 'custom_copy', False) set_if_none(property_, 'custom_compare', False) set_if_none(property_, 'mutable', False) if property_['logical_property_group']: group = property_['logical_property_group'] assert 'name' in group, 'name option is required' assert 'resolver' in group, 'resolver option is required' logicals = { 'block', 'inline', 'block-start', 'block-end', 'inline-start', 'inline-end', 'start-start', 'start-end', 'end-start', 'end-end' } physicals = { 'vertical', 'horizontal', 'top', 'bottom', 'left', 'right', 'top-left', 'top-right', 'bottom-right', 'bottom-left' } if group['resolver'] in logicals: group['is_logical'] = True elif group['resolver'] in physicals: group['is_logical'] = False else: assert 0, 'invalid resolver option' group['name'] = NameStyleConverter(group['name']) group['resolver_name'] = NameStyleConverter(group['resolver']) if not property_['style_builder_template'] and group['is_logical']: property_['style_builder_template'] = 'direction_aware'
def expand_parameters(self, property_): def set_if_none(property_, key, value): if key not in property_ or property_[key] is None: property_[key] = value # Basic info. name = property_['name'] property_['property_id'] = id_for_css_property(name) property_['enum_key'] = enum_key_for_css_property(name) property_['is_internal'] = name.original.startswith('-internal-') method_name = property_['name_for_methods'] if not method_name: method_name = name.to_upper_camel_case().replace('Webkit', '') set_if_none(property_, 'inherited', False) # Initial function, Getters and Setters for ComputedStyle. property_['initial'] = 'Initial' + method_name simple_type_name = str(property_['type_name']).split('::')[-1] set_if_none(property_, 'name_for_methods', method_name) set_if_none(property_, 'type_name', 'E' + method_name) set_if_none( property_, 'getter', method_name if simple_type_name != method_name else 'Get' + method_name) set_if_none(property_, 'setter', 'Set' + method_name) if property_['inherited']: property_[ 'is_inherited_setter'] = 'Set' + method_name + 'IsInherited' # Figure out whether we should generate style builder implementations. for x in ['initial', 'inherit', 'value']: suppressed = x in property_['style_builder_custom_functions'] property_['style_builder_generate_%s' % x] = not suppressed # Expand StyleBuilderConverter params where necessary. if property_['type_name'] in PRIMITIVE_TYPES: set_if_none(property_, 'converter', 'CSSPrimitiveValue') else: set_if_none(property_, 'converter', 'CSSIdentifierValue') # Expand out field templates. if property_['field_template']: self._field_alias_expander.expand_field_alias(property_) type_name = property_['type_name'] if (property_['field_template'] == 'keyword' or property_['field_template'] == 'multi_keyword'): default_value = (type_name + '::' + NameStyleConverter( property_['default_value']).to_enum_value()) elif (property_['field_template'] == 'external' or property_['field_template'] == 'primitive' or property_['field_template'] == 'pointer'): default_value = property_['default_value'] else: assert property_['field_template'] == 'monotonic_flag', \ "Please put a valid value for field_template; got " + \ str(property_['field_template']) property_['type_name'] = 'bool' default_value = 'false' property_['default_value'] = default_value property_['unwrapped_type_name'] = property_['type_name'] if property_['wrapper_pointer_name']: assert property_['field_template'] in ['pointer', 'external'] if property_['field_template'] == 'external': property_['type_name'] = '{}<{}>'.format( property_['wrapper_pointer_name'], type_name) # Default values for extra parameters in computed_style_extra_fields.json5. set_if_none(property_, 'custom_copy', False) set_if_none(property_, 'custom_compare', False) set_if_none(property_, 'mutable', False) if property_['direction_aware_options'] and not property_[ 'style_builder_template']: property_['style_builder_template'] = 'direction_aware'