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..29e9d94177bbd27728bfe711a97f7edf85ca937e 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 make_style_builder import StyleBuilderWriter |
# Gets the classname for a given property. |
def get_classname(property): |
@@ -23,50 +25,72 @@ def get_classname(property): |
class CSSPropertyAPIWriter(make_style_builder.StyleBuilderWriter): |
- def __init__(self, json5_file_path): |
- super(CSSPropertyAPIWriter, self).__init__(json5_file_path) |
+ def __init__(self, json5_file_paths): |
+ super(CSSPropertyAPIWriter, self).__init__(json5_file_paths[0]) |
+ # TODO(aazzam): Move the logic for loading CSSPropertyAPIMethods.json5 into a new class APIMethodsWriter(). |
+ assert len(json5_file_paths) == 2, 'CSSPropertyAPIWriter requires 2 input json5 files files, got %d.' % len(json5_file_paths) |
+ |
+ #self.css_properties = StyleBuilderWriter([json5_file_paths[0]]) |
+ self.css_property_api_methods = Json5File.load_from_files([json5_file_paths[1]], {}, {}) |
+ |
self._outputs = { |
'CSSPropertyDescriptor.cpp': self.generate_property_descriptor_cpp, |
} |
+ # Stores a map of API method name -> (return_type, parameters) |
+ self.all_api_methods = {} |
+ # Stores an ordered list of all API method names. This must match the |
+ # order they appear in the Descriptor object. |
+ self.ordered_api_method_names = [] |
+ ApiMethod = namedtuple('ApiMethod', ('return_type', 'parameters')) |
+ for api_method in self.css_property_api_methods.name_dictionaries: |
+ self.ordered_api_method_names.append(api_method['name']) |
+ self.all_api_methods[api_method['name']] = ApiMethod( |
+ return_type=api_method['return_type'], |
+ parameters=api_method['parameters'], |
+ ) |
+ |
# 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(): |
+ # Map of API classname to list of methods implemented by that class. |
+ self.methods_for_classes = defaultdict(list) |
+ for property in self.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']) |
+ # For api_classes that contain multiple properties, combine all implemented properties. |
+ # This list contains duplicate entries, but is only used to check if a method is |
+ # implemented for an api_class. |
+ self.methods_for_classes[classname] += property['api_methods'] |
+ self._outputs[classname + '.h'] = self.generate_property_api_h_builder(classname) |
# 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', 'methods_for_class')) |
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], |
+ methods_for_class=self.methods_for_classes[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'], |
+ 'ordered_api_method_names': self.ordered_api_method_names, |
} |
# Provides a function object given the classname of the property. |
- def generate_property_api_h_builder(self, api_classname, api_methods): |
+ def generate_property_api_h_builder(self, api_classname): |
@template_expander.use_jinja('CSSPropertyAPIFiles.h.tmpl') |
def generate_property_api_h(): |
return { |
'api_classname': api_classname, |
- 'api_methods': api_methods, |
+ 'methods_for_class': self.methods_for_classes[api_classname], |
+ 'all_api_methods': self.all_api_methods, |
} |
return generate_property_api_h |