コード例 #1
0
    def __init__(self, json5_file_paths):
        super(CSSOMTypesWriter, self).__init__([])

        self._input_files = json5_file_paths
        self._properties = (
            css_properties.CSSProperties(json5_file_paths)).longhands

        for property_ in self._properties:
            types = []
            # Expand types
            for single_type in property_['typedom_types']:
                if single_type == 'Image':
                    types.append('URLImage')
                else:
                    types.append(single_type)
            property_['typedom_types'] = types

            # Generate Keyword ID values from keywords.
            property_['keywordIDs'] = map(enum_for_css_keyword,
                                          property_['keywords'])

        self._outputs = {
            'CSSOMTypes.cpp': self.generate_types,
            'CSSOMKeywords.cpp': self.generate_keywords,
        }
コード例 #2
0
    def __init__(self, json5_file_paths, output_dir):
        super(CSSPropertyInstancesWriter, self).__init__([], output_dir)
        self._input_files = json5_file_paths
        self._outputs = {
            'css_property_instances.h':
            self.generate_property_instances_header,
            'css_property_instances.cc':
            self.generate_property_instances_implementation
        }
        # These files are no longer generated. If the files are present from
        # a previous build, we remove them. This avoids accidentally #including
        # a stale generated header.
        self._cleanup = set([
            'css_property.cc', 'css_property.h', 'css_unresolved_property.cc',
            'css_unresolved_property.h'
        ])

        self._css_properties = css_properties.CSSProperties(json5_file_paths)

        properties = self._css_properties.longhands + self._css_properties.shorthands
        aliases = self._css_properties.aliases

        # Lists of PropertyClassData.
        self._property_classes_by_id = list(map(self.get_class, properties))
        self._alias_classes_by_id = list(map(self.get_class, aliases))

        # Sort by enum value.
        self._property_classes_by_id.sort(key=lambda t: t.enum_value)
        self._alias_classes_by_id.sort(key=lambda t: t.enum_value)
コード例 #3
0
    def __init__(self, json5_file_paths, output_dir):
        super(ComputedStyleBaseWriter, self).__init__([], output_dir)

        self._input_files = json5_file_paths

        # Reads css_properties.json5, computed_style_field_aliases.json5,
        # runtime_enabled_features.json5 and computed_style_extra_fields.json5
        self._css_properties = css_properties.CSSProperties(
            json5_file_paths[0:4])

        # We sort the enum values based on each value's position in
        # the keywords as listed in css_properties.json5. This will ensure that
        # if there is a continuous
        # segment in css_properties.json5 matching the segment in this enum then
        # the generated enum will have the same order and continuity as
        # css_properties.json5 and we can get the longest continuous segment.
        # Thereby reduce the switch case statement to the minimum.
        properties = keyword_utils.sort_keyword_properties_by_canonical_order(
            self._css_properties.longhands, json5_file_paths[5],
            self.default_parameters)
        self._properties = properties + self._css_properties.extra_fields

        self._generated_enums = _create_enums(self._properties)

        # Organise fields into a tree structure where the root group
        # is ComputedStyleBase.
        group_parameters = dict([
            (conf["name"], conf["cumulative_distribution"])
            for conf in json5_generator.Json5File.load_from_files(
                [json5_file_paths[7]]).name_dictionaries
        ])

        properties_ranking = [
            x["name"].original
            for x in json5_generator.Json5File.load_from_files(
                [json5_file_paths[6]]).name_dictionaries
        ]
        _evaluate_rare_non_inherited_group(
            self._properties, properties_ranking,
            len(group_parameters["rare_non_inherited_properties_rule"]),
            group_parameters["rare_non_inherited_properties_rule"])
        _evaluate_rare_inherit_group(
            self._properties, properties_ranking,
            len(group_parameters["rare_inherited_properties_rule"]),
            group_parameters["rare_inherited_properties_rule"])
        self._root_group = _create_groups(self._properties)
        self._diff_functions_map = _create_diff_groups_map(
            json5_generator.Json5File.load_from_files([json5_file_paths[4]
                                                       ]).name_dictionaries,
            self._root_group)

        self._include_paths = _get_include_paths(self._properties)
        self._outputs = {
            'computed_style_base.h':
            self.generate_base_computed_style_h,
            'computed_style_base.cc':
            self.generate_base_computed_style_cpp,
            'computed_style_base_constants.h':
            self.generate_base_computed_style_constants,
        }
コード例 #4
0
    def __init__(self, json5_file_paths, output_dir):
        super(StylePropertyShorthandWriter, self).__init__([], output_dir)
        self._input_files = json5_file_paths
        self._outputs = {
            'style_property_shorthand.cc':
            self.generate_style_property_shorthand_cpp,
            'style_property_shorthand.h':
            self.generate_style_property_shorthand_h
        }

        json5_properties = css_properties.CSSProperties(json5_file_paths)
        self._shorthands = json5_properties.shorthands

        self._longhand_dictionary = defaultdict(list)
        for property_ in json5_properties.shorthands:
            property_['longhand_property_ids'] = map(enum_for_css_property,
                                                     property_['longhands'])
            for longhand in property_['longhand_property_ids']:
                self._longhand_dictionary[longhand].append(property_)

        for longhands in self._longhand_dictionary.values():
            # Sort first by number of longhands in decreasing order, then
            # alphabetically
            longhands.sort(key=lambda property_: (-len(property_[
                'longhand_property_ids']), property_['name'].original))
コード例 #5
0
 def __init__(self, json5_file_path):
     super(CSSPropertyNamesWriter, self).__init__(json5_file_path)
     self._outputs = {
         (self.file_basename + ".h"): self.generate_header,
         (self.file_basename + ".cc"): self.generate_implementation,
     }
     self._css_properties = css_properties.CSSProperties(json5_file_path)
コード例 #6
0
    def __init__(self, json5_file_paths):
        super(CSSPropertyWriter, self).__init__([])
        self._input_files = json5_file_paths
        self._outputs = {
            'CSSProperty.h': self.generate_property_header,
            'CSSProperty.cpp': self.generate_property_implementation,
        }

        self._css_properties = css_properties.CSSProperties(json5_file_paths)

        # A list of (enum_value, property_id, property_classname) tuples.
        self._property_classes_by_id = []
        # Just a set of class names.
        self._shorthand_property_classes = set()
        self._longhand_property_classes = set()
        for property_ in self._css_properties.longhands:
            property_class = self.get_class(property_)
            self._property_classes_by_id.append(property_class)
            self._longhand_property_classes.add(property_class.classname)
        for property_ in self._css_properties.shorthands:
            property_class = self.get_class(property_)
            self._property_classes_by_id.append(property_class)
            self._shorthand_property_classes.add(property_class.classname)

        # Sort by enum value.
        self._property_classes_by_id.sort(key=lambda t: t.enum_value)
コード例 #7
0
    def __init__(self, json5_file_paths, output_dir):
        super(ComputedStyleInitialValuesWriter, self).__init__([], output_dir)

        json_properties = css_properties.CSSProperties(json5_file_paths)

        self._properties = json_properties.longhands + \
            json_properties.extra_fields
        self._includes = set()
        self._forward_declarations = set()

        for property_ in self._properties:
            # TODO(meade): CursorList and AppliedTextDecorationList are
            # typedefs, not classes, so they can't be forward declared. Find a
            # better way to specify this.
            if property_['default_value'] == 'nullptr' \
                    and not property_['unwrapped_type_name'] == 'CursorList' \
                    and not property_['unwrapped_type_name'] == \
                    'AppliedTextDecorationList':
                self._forward_declarations.add(
                    property_['unwrapped_type_name'])
            else:
                self._includes.update(property_['include_paths'])

        self._outputs = {
            'computed_style_initial_values.h': self.generate_header,
        }
コード例 #8
0
    def __init__(self, json5_file_paths, output_dir):
        super(StylePropertyShorthandWriter, self).__init__([], output_dir)
        self._input_files = json5_file_paths
        self._outputs = {
            (self._FILE_BASENAME + '.cc'):
            self.generate_style_property_shorthand_cpp,
            (self._FILE_BASENAME + '.h'):
            self.generate_style_property_shorthand_h
        }

        json5_properties = css_properties.CSSProperties(json5_file_paths)
        self._shorthands = json5_properties.shorthands

        self._longhand_dictionary = defaultdict(list)
        for property_ in json5_properties.shorthands:
            property_['longhand_enum_keys'] = map(enum_key_for_css_property,
                                                  property_['longhands'])
            property_['longhand_property_ids'] = map(id_for_css_property,
                                                     property_['longhands'])

            longhands = map(
                lambda name: json5_properties.properties_by_name[name],
                property_['longhands'])
            property_['expansions'] = create_expansions(longhands)
            for longhand_enum_key in property_['longhand_enum_keys']:
                self._longhand_dictionary[longhand_enum_key].append(property_)

        for longhands in self._longhand_dictionary.values():
            # Sort first by number of longhands in decreasing order, then
            # alphabetically
            longhands.sort(key=lambda property_: (-len(property_[
                'longhand_property_ids']), property_['name'].original))
コード例 #9
0
    def __init__(self, json5_file_paths, output_dir):
        super(StyleBuilderWriter, self).__init__([], output_dir)

        self._json5_properties = css_properties.CSSProperties(json5_file_paths)
        self._input_files = json5_file_paths
        self._properties = self._json5_properties.longhands + \
            self._json5_properties.shorthands
        for property_ in self._properties:
            calculate_apply_functions_to_declare(property_)
コード例 #10
0
    def __init__(self, json5_file_paths, output_dir):
        super(StyleCascadeSlotsWriter, self).__init__([], output_dir)

        json_properties = css_properties.CSSProperties(json5_file_paths)

        self._properties = json_properties.longhands
        self._outputs = {
            'style_cascade_slots.h': self.generate_header,
            'style_cascade_slots.cc': self.generate_impl,
        }
コード例 #11
0
    def __init__(self, json5_file_paths, output_dir):
        super(CSSStyleDeclarationAttributeIDLWriter, self).__init__([],
                                                                    output_dir)
        assert len(json5_file_paths) == 3,\
            ('CSSStyleDeclarationAttributeIDLWriter requires 3 input json5 ' +
             'files, got {}.'.format(len(json5_file_paths)))

        properties = css_properties.CSSProperties(json5_file_paths)
        self._attributes = get_attributes(properties.supported_properties)
        self._outputs = {}
        self._outputs[OUT_IDL] = self.generate_attributes_idl
コード例 #12
0
    def __init__(self, json5_file_paths, output_dir):
        super(CSSStyleDeclarationAttributeWriter, self).__init__([],
                                                                 output_dir)
        assert len(json5_file_paths) == 3,\
            ('CSSStyleDeclarationAttributeWriter requires 3 input json5 ' +
             'files, got {}.'.format(len(json5_file_paths)))

        properties = css_properties.CSSProperties(
            json5_file_paths).supported_properties
        self._properties = list(filter(lambda p: p['runtime_flag'],
                                       properties))
        self._outputs = {}
        self._outputs[OUT_H] = self.generate_attributes_h
        self._outputs[OUT_CC] = self.generate_attributes_cc
コード例 #13
0
    def __init__(self, json5_file_paths):
        super(StyleBuilderWriter, self).__init__([])
        self._outputs = {
            'StyleBuilderFunctions.h': self.generate_style_builder_functions_h,
            'StyleBuilderFunctions.cpp':
            self.generate_style_builder_functions_cpp,
            'StyleBuilder.cpp': self.generate_style_builder,
        }

        self._json5_properties = css_properties.CSSProperties(json5_file_paths)
        self._input_files = json5_file_paths
        self._properties = self._json5_properties.longhands + \
            self._json5_properties.shorthands
        for property_ in self._properties:
            calculate_functions_to_declare(property_)
コード例 #14
0
    def __init__(self, json5_file_paths, output_dir):
        super(CSSPropertyBaseWriter, self).__init__([], output_dir)
        self._input_files = json5_file_paths
        self._outputs = {
            'css_property_instances.h': self.generate_property_instances_header,
            'css_property_instances.cc':
                self.generate_property_instances_implementation
        }
        # These files are no longer generated. If the files are present from
        # a previous build, we remove them. This avoids accidentally #including
        # a stale generated header.
        self._cleanup = set([
            'css_property.cc',
            'css_property.h',
            'css_unresolved_property.cc',
            'css_unresolved_property.h'
        ])

        self._css_properties = css_properties.CSSProperties(json5_file_paths)

        # A list of (enum_value, property_id, property_classname) tuples.
        self._property_classes_by_id = []
        self._alias_classes_by_id = []
        # Just a set of class names.
        self._shorthand_property_filenames = set()
        self._longhand_property_filenames = set()
        for property_ in self._css_properties.longhands:
            property_class = self.get_class(property_)
            self._property_classes_by_id.append(property_class)
            if property_class.classname != 'Longhand':
                self._longhand_property_filenames.add(property_class.filename)
        for property_ in self._css_properties.shorthands:
            property_class = self.get_class(property_)
            self._property_classes_by_id.append(property_class)
            self._shorthand_property_filenames.add(property_class.filename)
        for property_ in self._css_properties.aliases:
            property_class = self.get_class(property_)
            self._alias_classes_by_id.append(property_class)
            if property_['longhands']:
                self._shorthand_property_filenames.add(property_class.filename)
            elif property_class.classname != 'Longhand':
                self._longhand_property_filenames.add(property_class.filename)

        # Sort by enum value.
        self._property_classes_by_id.sort(key=lambda t: t.enum_value)
        self._alias_classes_by_id.sort(key=lambda t: t.enum_value)
コード例 #15
0
    def __init__(self, json5_file_paths, output_dir):
        super(CSSPropertyBaseWriter, self).__init__([], output_dir)
        self._input_files = json5_file_paths
        self._outputs = {
            'css_unresolved_property.h':
            self.generate_unresolved_property_header,
            'css_unresolved_property.cc':
            self.generate_unresolved_property_implementation,
            'css_property.h': self.generate_resolved_property_header,
            'css_property.cc': self.generate_resolved_property_implementation,
        }

        self._css_properties = css_properties.CSSProperties(json5_file_paths)

        # A list of (enum_value, property_id, property_classname) tuples.
        self._property_classes_by_id = []
        self._alias_classes_by_id = []
        # Just a set of class names.
        self._shorthand_property_filenames = set()
        self._longhand_property_filenames = set()
        for property_ in self._css_properties.longhands:
            property_class = self.get_class(property_)
            self._property_classes_by_id.append(property_class)
            if property_class.classname != 'Longhand':
                self._longhand_property_filenames.add(property_class.filename)
        for property_ in self._css_properties.shorthands:
            property_class = self.get_class(property_)
            self._property_classes_by_id.append(property_class)
            self._shorthand_property_filenames.add(property_class.filename)
        for property_ in self._css_properties.aliases:
            property_class = self.get_class(property_)
            self._alias_classes_by_id.append(property_class)
            if property_['longhands']:
                self._shorthand_property_filenames.add(property_class.filename)
            elif property_class.classname != 'Longhand':
                self._longhand_property_filenames.add(property_class.filename)

        # Sort by enum value.
        self._property_classes_by_id.sort(key=lambda t: t.enum_value)
        self._alias_classes_by_id.sort(key=lambda t: t.enum_value)
コード例 #16
0
    def __init__(self, json5_file_paths, output_dir):
        super(CSSPropertiesWriter, self).__init__([], output_dir)
        assert len(json5_file_paths) == 4,\
            ('CSSPropertiesWriter requires 4 input json5 files, ' +
             'got {}.'.format(len(json5_file_paths)))

        self._css_properties = css_properties.CSSProperties(json5_file_paths)

        # Map of property method name -> (return_type, parameters)
        self._property_methods = {}
        property_methods = json5_generator.Json5File.load_from_files(
            [json5_file_paths[3]])
        for property_method in property_methods.name_dictionaries:
            self._property_methods[
                property_method['name'].original] = property_method

        all_properties = self._css_properties.properties_including_aliases

        for property_ in all_properties:
            property_['property_methods'] = [
                self._property_methods[method_name]
                for method_name in property_['property_methods']
            ]

        # Clean up all the files that were previously generated. This prevents
        # accidentally including a stale header in the future.
        old_file = lambda prop: prop['namespace_group'].lower() + '/' \
            + prop['name'].to_snake_case()
        old_h = lambda prop: old_file(prop) + '.h'
        old_cc = lambda prop: old_file(prop) + '.cc'
        self._cleanup |= set(map(old_h, all_properties))
        self._cleanup |= set(map(old_cc, all_properties))

        self._input_files = json5_file_paths
        self._outputs = {}
        self._outputs['longhands.h'] = self.generate_longhands_h
        self._outputs['longhands.cc'] = self.generate_longhands_cc
        self._outputs['shorthands.h'] = self.generate_shorthands_h
        self._outputs['shorthands.cc'] = self.generate_shorthands_cc
コード例 #17
0
    def __init__(self, json5_file_paths, output_dir):
        super(CSSOMTypesWriter, self).__init__([], output_dir)

        self._input_files = json5_file_paths
        self._properties = (
            css_properties.CSSProperties(json5_file_paths)).longhands

        for property_ in self._properties:
            types = []
            # Expand types
            for single_type in property_['typedom_types']:
                types.append(single_type)
            property_['typedom_types'] = types

            # Generate CSSValueID values from keywords.
            property_['keywordIDs'] = map(enum_key_for_css_keyword,
                                          property_['keywords'])

        self._outputs = {
            'cssom_types.cc': self.generate_types,
            'cssom_keywords.cc': self.generate_keywords,
        }
コード例 #18
0
    def __init__(self, json5_file_paths):
        super(CSSPropertyAPIWriter, self).__init__([])
        self._input_files = json5_file_paths
        self._outputs = {
            'CSSPropertyAPI.h': self.generate_property_api_header,
            'CSSPropertyAPI.cpp': self.generate_property_api_implementation,
        }

        self._css_properties = css_properties.CSSProperties(json5_file_paths)

        # A list of (enum_value, property_id, api_classname) tuples.
        self._api_classes_by_property_id = []
        # Just a set of class names.
        self._shorthand_api_classes = set()
        self._longhand_api_classes = set()
        for property_ in self._css_properties.longhands:
            api_class = self.get_class(property_, 'CSSPropertyAPI')
            self._api_classes_by_property_id.append(api_class)
            self._longhand_api_classes.add(api_class.classname)
        for property_ in self._css_properties.shorthands:
            api_class = self.get_class(property_, 'CSSShorthandPropertyAPI')
            self._api_classes_by_property_id.append(api_class)
            self._shorthand_api_classes.add(api_class.classname)

        # Manually add CSSPropertyVariable and CSSPropertyAtApply.
        self._api_classes_by_property_id.append(
            ApiClassData(enum_value=1,
                         property_id="CSSPropertyApplyAtRule",
                         classname="CSSPropertyAPIApplyAtRule"))
        self._longhand_api_classes.add("CSSPropertyAPIApplyAtRule")
        self._api_classes_by_property_id.append(
            ApiClassData(enum_value=2,
                         property_id="CSSPropertyVariable",
                         classname="CSSPropertyAPIVariable"))
        self._longhand_api_classes.add("CSSPropertyAPIVariable")

        # Sort by enum value.
        self._api_classes_by_property_id.sort(key=lambda t: t.enum_value)