Chromium Code Reviews| Index: third_party/WebKit/Source/build/scripts/make_css_property_apis.py |
| diff --git a/third_party/WebKit/Source/build/scripts/make_css_property_apis.py b/third_party/WebKit/Source/build/scripts/make_css_property_apis.py |
| index de909b5502d8a8c0b06286e505433709f89cd045..2b1dd5e8fd895fd66439f0befa181ccd3784cc02 100755 |
| --- a/third_party/WebKit/Source/build/scripts/make_css_property_apis.py |
| +++ b/third_party/WebKit/Source/build/scripts/make_css_property_apis.py |
| @@ -10,6 +10,8 @@ import template_expander |
| import make_style_builder |
| from collections import namedtuple, defaultdict |
| +from json5_generator import Json5File |
| +from css_properties import CSSProperties |
| # Gets the classname for a given property. |
| def get_classname(property): |
| @@ -22,42 +24,57 @@ def get_classname(property): |
| return property['api_class'] |
| -class CSSPropertyAPIWriter(make_style_builder.StyleBuilderWriter): |
| - def __init__(self, json5_file_path): |
| - super(CSSPropertyAPIWriter, self).__init__(json5_file_path) |
| +class CSSPropertyAPIWriter(json5_generator.Writer): |
| + def __init__(self, json5_file_paths): |
| + super(CSSPropertyAPIWriter, self).__init__(None) |
| + assert len(json5_file_paths) == 2, 'CSSPropertyAPIWriter requires 2 input json5 files files, got %d.' % len(json5_file_paths) |
| + |
| + self.css_properties = CSSProperties([json5_file_paths.pop(0)]) |
|
sashab
2017/02/08 04:00:03
CSSProperties -> StyleBuilderWriter
|
| + self.css_property_api_methods = Json5File.load_from_files([json5_file_paths.pop()], {}, {}) |
|
sashab
2017/02/08 04:00:03
Replace .pop() with actual indices, eg [0] and [1]
|
| + |
| self._outputs = { |
| 'CSSPropertyDescriptor.cpp': self.generate_property_descriptor_cpp, |
| } |
| + ApiMethod = namedtuple('ApiMethod', ('definition', 'name', 'classnames')) |
|
sashab
2017/02/08 04:00:03
This is a tuple defining each api method and its d
|
| + self.api_methods_implemented_in = [] |
|
sashab
2017/02/08 04:00:03
A list of all the API methods
self.all_api_method
|
| + for api_method in self.css_property_api_methods.name_dictionaries: |
| + # Temporary set of classnames |
| + properties_method_is_implemented_in = [] |
|
sashab
2017/02/08 04:00:03
classnames_method_is_implemented_in = []
|
| + for property in self.css_properties.properties().values(): |
| + if api_method['name'] in property['api_methods']: |
| + properties_method_is_implemented_in.append(get_classname(property)) |
| + self.api_methods_implemented_in.append(ApiMethod( |
| + definition=api_method['definition'], |
| + name=api_method['name'], |
| + classnames=properties_method_is_implemented_in, |
| + )) |
| + |
|
sashab
2017/02/08 04:00:03
# Build ordered, complete list of api methods for
|
| # Temporary map of API classname to list of propertyIDs that the API class is for. |
| properties_for_class = defaultdict(list) |
| - # Temporary map of API classname to set of method names this API class implements |
| - api_methods_for_class = defaultdict(set) |
| - for property in self._properties.values(): |
| + for property in self.css_properties.properties().values(): |
| if property['api_class'] is None: |
| continue |
| classname = get_classname(property) |
| - api_methods_for_class[classname] = property['api_methods'] |
| properties_for_class[classname].append(property['property_id']) |
| - self._outputs[classname + '.h'] = self.generate_property_api_h_builder(classname, property['api_methods']) |
| + self._outputs[classname + '.h'] = self.generate_property_api_h_builder(classname, self.api_methods_implemented_in) |
| # Stores a list of classes with elements (index, classname, [propertyIDs, ..], [api_methods, ...]). |
| self._api_classes = [] |
| - ApiClass = namedtuple('ApiClass', ('index', 'classname', 'property_ids', 'api_methods')) |
| + ApiClass = namedtuple('ApiClass', ('index', 'classname', 'property_ids')) |
| for i, classname in enumerate(properties_for_class.keys()): |
| self._api_classes.append(ApiClass( |
| index=i + 1, |
| classname=classname, |
| property_ids=properties_for_class[classname], |
| - api_methods=api_methods_for_class[classname], |
| )) |
| @template_expander.use_jinja('CSSPropertyDescriptor.cpp.tmpl') |
| def generate_property_descriptor_cpp(self): |
| return { |
| 'api_classes': self._api_classes, |
| - 'api_methods': self.json5_file.parameters['api_methods']['valid_values'], |
| + 'api_methods': self.api_methods_implemented_in, |
| } |
| # Provides a function object given the classname of the property. |