Commit e076f009 authored by shend's avatar shend Committed by Commit bot

Replace "field_type_path" with "include_paths" in CSSProperties.json5.

In CSSProperties.json5, to deal with type_names that are defined in
other files, we use the "field_type_path" parameter. For example, if we
wanted to use "Length" as the type_name, we can specify
"field_type_path" as "platform/Length" and the generator will
automatically include "platform/Length.h". We would also deduce that
the type_name is Length. However, this does not cater for type_names
like "Vector<String>", where multiple files need to be included.

This patch generalises "field_type_path" to "include_paths", which is
simply a list of files containing definitions for the types in
type_name. Since "include_paths" can contain multiple files, we can no
longer deduce the type_name, so we have to explicitly specify the
type_name.

BUG=628043

Review-Url: https://codereview.chromium.org/2904483003
Cr-Commit-Position: refs/heads/master@{#474928}
parent 6952c722
...@@ -174,8 +174,7 @@ def _get_include_paths(properties): ...@@ -174,8 +174,7 @@ def _get_include_paths(properties):
""" """
include_paths = set() include_paths = set()
for property_ in properties: for property_ in properties:
if property_['field_type_path'] is not None: include_paths.update(property_['include_paths'])
include_paths.add(property_['field_type_path'] + '.h')
return list(sorted(include_paths)) return list(sorted(include_paths))
...@@ -230,8 +229,8 @@ def _create_enums(properties): ...@@ -230,8 +229,8 @@ def _create_enums(properties):
""" """
enums = {} enums = {}
for property_ in properties: for property_ in properties:
# Only generate enums for keyword properties that use the default field_type_path. # Only generate enums for keyword properties that do not require includes.
if property_['field_template'] == 'keyword' and property_['field_type_path'] is None: if property_['field_template'] == 'keyword' and len(property_['include_paths']) == 0:
enum_name = property_['type_name'] enum_name = property_['type_name']
enum_values = [enum_value_name(k) for k in property_['keywords']] enum_values = [enum_value_name(k) for k in property_['keywords']]
...@@ -423,11 +422,6 @@ class ComputedStyleBaseWriter(make_style_builder.StyleBuilderWriter): ...@@ -423,11 +422,6 @@ class ComputedStyleBaseWriter(make_style_builder.StyleBuilderWriter):
all_properties = css_properties + extra_fields all_properties = css_properties + extra_fields
# Override the type name when field_type_path is specified
for property_ in all_properties:
if property_['field_type_path']:
property_['type_name'] = property_['field_type_path'].split('/')[-1]
self._generated_enums = _create_enums(all_properties) self._generated_enums = _create_enums(all_properties)
all_fields = _create_fields(all_properties) all_fields = _create_fields(all_properties)
......
...@@ -20,16 +20,12 @@ class CSSValueIDMappingsWriter(make_style_builder.StyleBuilderWriter): ...@@ -20,16 +20,12 @@ class CSSValueIDMappingsWriter(make_style_builder.StyleBuilderWriter):
@template_expander.use_jinja('CSSValueIDMappingsGenerated.h.tmpl') @template_expander.use_jinja('CSSValueIDMappingsGenerated.h.tmpl')
def generate_css_value_mappings(self): def generate_css_value_mappings(self):
mappings = {} mappings = {}
include_paths = [] include_paths = set()
for property_ in self._properties.values(): for property_ in self._properties.values():
if property_['field_template'] == 'keyword': if property_['field_template'] == 'keyword':
if property_['field_type_path']: include_paths.update(property_['include_paths'])
type_name = property_['field_type_path'].split('/')[-1]
include_paths.append(property_['field_type_path'] + '.h')
else:
type_name = property_['type_name']
mappings[type_name] = { mappings[property_['type_name']] = {
'default_value': enum_value_name(property_['default_value']), 'default_value': enum_value_name(property_['default_value']),
'mapping': [(enum_value_name(k), enum_for_css_keyword(k)) for k in property_['keywords']], 'mapping': [(enum_value_name(k), enum_for_css_keyword(k)) for k in property_['keywords']],
} }
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
// The rest is the same as CSSProperties.json5, but the only relevant ones in // The rest is the same as CSSProperties.json5, but the only relevant ones in
// this file are: // this file are:
// name, field_template, field_type_path, default_value, type_name, keyword, // name, field_template, include_paths, default_value, type_name, keyword,
// inherited // inherited
}, },
...@@ -186,27 +186,31 @@ ...@@ -186,27 +186,31 @@
name: "VerticalAlignLength", name: "VerticalAlignLength",
field_template: "storage_only", field_template: "storage_only",
default_value: "Length()", default_value: "Length()",
field_type_path: "platform/Length", include_paths: ["platform/Length.h"],
type_name: "Length",
field_group: "box", field_group: "box",
}, },
{ {
name: "border-image", name: "border-image",
field_template: "external", field_template: "external",
field_type_path: "core/style/NinePieceImage", include_paths: ["core/style/NinePieceImage.h"],
type_name: "NinePieceImage",
field_group: "surround", field_group: "surround",
default_value: "NinePieceImage()", default_value: "NinePieceImage()",
}, },
{ {
name: "Background", name: "Background",
field_template: "storage_only", field_template: "storage_only",
field_type_path: "core/style/FillLayer", include_paths: ["core/style/FillLayer.h"],
type_name: "FillLayer",
default_value: "FillLayer(kBackgroundFillLayer, true)", default_value: "FillLayer(kBackgroundFillLayer, true)",
field_group: "background", field_group: "background",
}, },
{ {
name: "BackgroundColor", name: "BackgroundColor",
field_template: "storage_only", field_template: "storage_only",
field_type_path: "core/css/StyleColor", include_paths: ["core/css/StyleColor.h"],
type_name: "StyleColor",
default_value: "Color::kTransparent", default_value: "Color::kTransparent",
field_group: "background", field_group: "background",
}, },
...@@ -237,7 +241,8 @@ ...@@ -237,7 +241,8 @@
{ {
name: "font", name: "font",
field_template: "storage_only", field_template: "storage_only",
field_type_path: "platform/fonts/Font", include_paths: ["platform/fonts/Font.h"],
type_name: "Font",
field_group: "inherited", field_group: "inherited",
inherited: true, inherited: true,
default_value: "Font()", default_value: "Font()",
...@@ -246,7 +251,8 @@ ...@@ -246,7 +251,8 @@
name: "color", name: "color",
inherited: true, inherited: true,
field_template: "storage_only", field_template: "storage_only",
field_type_path: "platform/graphics/Color", include_paths: ["platform/graphics/Color.h"],
type_name: "Color",
field_group: "inherited", field_group: "inherited",
default_value: "Color::kBlack", default_value: "Color::kBlack",
}, },
...@@ -254,7 +260,8 @@ ...@@ -254,7 +260,8 @@
name: "VisitedLinkColor", name: "VisitedLinkColor",
inherited: true, inherited: true,
field_template: "external", field_template: "external",
field_type_path: "platform/graphics/Color", include_paths: ["platform/graphics/Color.h"],
type_name: "Color",
field_group: "inherited", field_group: "inherited",
default_value: "Color::kBlack", default_value: "Color::kBlack",
}, },
...@@ -270,7 +277,8 @@ ...@@ -270,7 +277,8 @@
name: "VisitedLinkTextStrokeColor", name: "VisitedLinkTextStrokeColor",
inherited: true, inherited: true,
field_template: "storage_only", field_template: "storage_only",
field_type_path: "platform/graphics/Color", type_name: "Color",
include_paths: ["platform/graphics/Color.h"],
default_value: "Color()", default_value: "Color()",
field_group: "rare-inherited", field_group: "rare-inherited",
}, },
...@@ -278,7 +286,8 @@ ...@@ -278,7 +286,8 @@
name: "VisitedLinkTextFillColor", name: "VisitedLinkTextFillColor",
inherited: true, inherited: true,
field_template: "storage_only", field_template: "storage_only",
field_type_path: "platform/graphics/Color", type_name: "Color",
include_paths: ["platform/graphics/Color.h"],
default_value: "Color()", default_value: "Color()",
field_group: "rare-inherited", field_group: "rare-inherited",
}, },
...@@ -286,7 +295,8 @@ ...@@ -286,7 +295,8 @@
name: "VisitedLinkTextEmphasisColor", name: "VisitedLinkTextEmphasisColor",
inherited: true, inherited: true,
field_template: "storage_only", field_template: "storage_only",
field_type_path: "platform/graphics/Color", type_name: "Color",
include_paths: ["platform/graphics/Color.h"],
default_value: "Color()", default_value: "Color()",
field_group: "rare-inherited", field_group: "rare-inherited",
}, },
...@@ -294,7 +304,8 @@ ...@@ -294,7 +304,8 @@
name: "VisitedLinkCaretColor", name: "VisitedLinkCaretColor",
inherited: true, inherited: true,
field_template: "storage_only", field_template: "storage_only",
field_type_path: "platform/graphics/Color", type_name: "Color",
include_paths: ["platform/graphics/Color.h"],
default_value: "Color()", default_value: "Color()",
field_group: "rare-inherited", field_group: "rare-inherited",
}, },
...@@ -302,7 +313,8 @@ ...@@ -302,7 +313,8 @@
name: "CursorData", name: "CursorData",
inherited: true, inherited: true,
field_template: "storage_only", field_template: "storage_only",
field_type_path: "core/style/CursorList", type_name: "CursorList",
include_paths: ["core/style/CursorList.h"],
default_value: "nullptr", default_value: "nullptr",
wrapper_pointer_name: "Persistent", wrapper_pointer_name: "Persistent",
field_group: "rare-inherited", field_group: "rare-inherited",
...@@ -518,7 +530,8 @@ ...@@ -518,7 +530,8 @@
name: "TextEmphasisCustomMark", name: "TextEmphasisCustomMark",
inherited: true, inherited: true,
field_template: "storage_only", field_template: "storage_only",
field_type_path: "platform/wtf/text/AtomicString", type_name: "AtomicString",
include_paths: ["platform/wtf/text/AtomicString.h"],
default_value: "AtomicString()", default_value: "AtomicString()",
field_group: "rare-inherited", field_group: "rare-inherited",
}, },
...@@ -526,7 +539,8 @@ ...@@ -526,7 +539,8 @@
name: "AppliedTextDecorations", name: "AppliedTextDecorations",
inherited: true, inherited: true,
field_template: "storage_only", field_template: "storage_only",
field_type_path: "core/style/AppliedTextDecorationList", type_name: "AppliedTextDecorationList",
include_paths: ["core/style/AppliedTextDecorationList.h"],
default_value: "nullptr", default_value: "nullptr",
wrapper_pointer_name: "RefPtr", wrapper_pointer_name: "RefPtr",
field_group: "rare-inherited", field_group: "rare-inherited",
...@@ -535,7 +549,8 @@ ...@@ -535,7 +549,8 @@
name: "Variables", name: "Variables",
inherited: true, inherited: true,
field_template: "storage_only", field_template: "storage_only",
field_type_path: "core/style/StyleInheritedVariables", type_name: "StyleInheritedVariables",
include_paths: ["core/style/StyleInheritedVariables.h"],
default_value: "nullptr", default_value: "nullptr",
wrapper_pointer_name: "RefPtr", wrapper_pointer_name: "RefPtr",
field_group: "rare-inherited", field_group: "rare-inherited",
......
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