Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(687)

Side by Side Diff: third_party/WebKit/Source/build/scripts/make_css_property_apis.py

Issue 2669243009: Added CSSPropertyAPIMethods.json5 which defines all API methods. (Closed)
Patch Set: Added comment Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2016 The Chromium Authors. All rights reserved. 2 # Copyright 2016 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import sys 6 import sys
7 7
8 import json5_generator 8 import json5_generator
9 import template_expander 9 import template_expander
10 import make_style_builder 10 import make_style_builder
11 11
12 from collections import namedtuple, defaultdict 12 from collections import namedtuple, defaultdict
13 from json5_generator import Json5File
14 from css_properties import CSSProperties
13 15
14 # Gets the classname for a given property. 16 # Gets the classname for a given property.
15 def get_classname(property): 17 def get_classname(property):
16 if property['api_class'] is True: 18 if property['api_class'] is True:
17 # This property had the generated_api_class flag set in CSSProperties.js on5. 19 # This property had the generated_api_class flag set in CSSProperties.js on5.
18 return 'CSSPropertyAPI' + property['upper_camel_name'] 20 return 'CSSPropertyAPI' + property['upper_camel_name']
19 # This property has a specified class name. 21 # This property has a specified class name.
20 assert isinstance(property['api_class'], str), \ 22 assert isinstance(property['api_class'], str), \
21 ("api_class value for " + property['api_class'] + " should be None, True or a string") 23 ("api_class value for " + property['api_class'] + " should be None, True or a string")
22 return property['api_class'] 24 return property['api_class']
23 25
24 26
25 class CSSPropertyAPIWriter(make_style_builder.StyleBuilderWriter): 27 class CSSPropertyAPIWriter(json5_generator.Writer):
26 def __init__(self, json5_file_path): 28 def __init__(self, json5_file_paths):
27 super(CSSPropertyAPIWriter, self).__init__(json5_file_path) 29 super(CSSPropertyAPIWriter, self).__init__(None)
30 assert len(json5_file_paths) == 2, 'CSSPropertyAPIWriter requires 2 inpu t json5 files files, got %d.' % len(json5_file_paths)
31
32 self.css_properties = CSSProperties([json5_file_paths.pop(0)])
sashab 2017/02/08 04:00:03 CSSProperties -> StyleBuilderWriter
33 self.css_property_api_methods = Json5File.load_from_files([json5_file_pa ths.pop()], {}, {})
sashab 2017/02/08 04:00:03 Replace .pop() with actual indices, eg [0] and [1]
34
28 self._outputs = { 35 self._outputs = {
29 'CSSPropertyDescriptor.cpp': self.generate_property_descriptor_cpp, 36 'CSSPropertyDescriptor.cpp': self.generate_property_descriptor_cpp,
30 } 37 }
31 38
39 ApiMethod = namedtuple('ApiMethod', ('definition', 'name', 'classnames') )
sashab 2017/02/08 04:00:03 This is a tuple defining each api method and its d
40 self.api_methods_implemented_in = []
sashab 2017/02/08 04:00:03 A list of all the API methods self.all_api_method
41 for api_method in self.css_property_api_methods.name_dictionaries:
42 # Temporary set of classnames
43 properties_method_is_implemented_in = []
sashab 2017/02/08 04:00:03 classnames_method_is_implemented_in = []
44 for property in self.css_properties.properties().values():
45 if api_method['name'] in property['api_methods']:
46 properties_method_is_implemented_in.append(get_classname(pro perty))
47 self.api_methods_implemented_in.append(ApiMethod(
48 definition=api_method['definition'],
49 name=api_method['name'],
50 classnames=properties_method_is_implemented_in,
51 ))
52
sashab 2017/02/08 04:00:03 # Build ordered, complete list of api methods for
32 # Temporary map of API classname to list of propertyIDs that the API cla ss is for. 53 # Temporary map of API classname to list of propertyIDs that the API cla ss is for.
33 properties_for_class = defaultdict(list) 54 properties_for_class = defaultdict(list)
34 # Temporary map of API classname to set of method names this API class i mplements 55 for property in self.css_properties.properties().values():
35 api_methods_for_class = defaultdict(set)
36 for property in self._properties.values():
37 if property['api_class'] is None: 56 if property['api_class'] is None:
38 continue 57 continue
39 classname = get_classname(property) 58 classname = get_classname(property)
40 api_methods_for_class[classname] = property['api_methods']
41 properties_for_class[classname].append(property['property_id']) 59 properties_for_class[classname].append(property['property_id'])
42 self._outputs[classname + '.h'] = self.generate_property_api_h_build er(classname, property['api_methods']) 60 self._outputs[classname + '.h'] = self.generate_property_api_h_build er(classname, self.api_methods_implemented_in)
43 61
44 # Stores a list of classes with elements (index, classname, [propertyIDs , ..], [api_methods, ...]). 62 # Stores a list of classes with elements (index, classname, [propertyIDs , ..], [api_methods, ...]).
45 self._api_classes = [] 63 self._api_classes = []
46 64
47 ApiClass = namedtuple('ApiClass', ('index', 'classname', 'property_ids', 'api_methods')) 65 ApiClass = namedtuple('ApiClass', ('index', 'classname', 'property_ids') )
48 for i, classname in enumerate(properties_for_class.keys()): 66 for i, classname in enumerate(properties_for_class.keys()):
49 self._api_classes.append(ApiClass( 67 self._api_classes.append(ApiClass(
50 index=i + 1, 68 index=i + 1,
51 classname=classname, 69 classname=classname,
52 property_ids=properties_for_class[classname], 70 property_ids=properties_for_class[classname],
53 api_methods=api_methods_for_class[classname],
54 )) 71 ))
55 72
56 @template_expander.use_jinja('CSSPropertyDescriptor.cpp.tmpl') 73 @template_expander.use_jinja('CSSPropertyDescriptor.cpp.tmpl')
57 def generate_property_descriptor_cpp(self): 74 def generate_property_descriptor_cpp(self):
58 return { 75 return {
59 'api_classes': self._api_classes, 76 'api_classes': self._api_classes,
60 'api_methods': self.json5_file.parameters['api_methods']['valid_valu es'], 77 'api_methods': self.api_methods_implemented_in,
61 } 78 }
62 79
63 # Provides a function object given the classname of the property. 80 # Provides a function object given the classname of the property.
64 def generate_property_api_h_builder(self, api_classname, api_methods): 81 def generate_property_api_h_builder(self, api_classname, api_methods):
65 @template_expander.use_jinja('CSSPropertyAPIFiles.h.tmpl') 82 @template_expander.use_jinja('CSSPropertyAPIFiles.h.tmpl')
66 def generate_property_api_h(): 83 def generate_property_api_h():
67 return { 84 return {
68 'api_classname': api_classname, 85 'api_classname': api_classname,
69 'api_methods': api_methods, 86 'api_methods': api_methods,
70 } 87 }
71 return generate_property_api_h 88 return generate_property_api_h
72 89
73 if __name__ == '__main__': 90 if __name__ == '__main__':
74 json5_generator.Maker(CSSPropertyAPIWriter).main() 91 json5_generator.Maker(CSSPropertyAPIWriter).main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698