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

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

Issue 2654403003: Added api_methods flag to CSSProperties.json5. (Closed)
Patch Set: Removed parseShorthand from valid_methods 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/build/scripts/templates/CSSPropertyAPIFiles.h.tmpl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 13
14
15 # Gets the classname for a given property. 14 # Gets the classname for a given property.
16 def get_classname(property): 15 def get_classname(property):
17 if property['api_class'] is True: 16 if property['api_class'] is True:
18 # This property had the generated_api_class flag set in CSSProperties.js on5. 17 # This property had the generated_api_class flag set in CSSProperties.js on5.
19 return 'CSSPropertyAPI' + property['upper_camel_name'] 18 return 'CSSPropertyAPI' + property['upper_camel_name']
20 # This property has a specified class name. 19 # This property has a specified class name.
21 assert isinstance(property['api_class'], str), \ 20 assert isinstance(property['api_class'], str), \
22 ("api_class value for " + property['api_class'] + " should be None, True or a string") 21 ("api_class value for " + property['api_class'] + " should be None, True or a string")
23 return property['api_class'] 22 return property['api_class']
24 23
25 24
26 class CSSPropertyAPIWriter(make_style_builder.StyleBuilderWriter): 25 class CSSPropertyAPIWriter(make_style_builder.StyleBuilderWriter):
27 def __init__(self, json5_file_path): 26 def __init__(self, json5_file_path):
27 # Holds names of all valid methods in the API. When a new method is adde d
28 # to the API, it must also be added to this list.
29 valid_methods = ["parseSingleValue"]
30
28 super(CSSPropertyAPIWriter, self).__init__(json5_file_path) 31 super(CSSPropertyAPIWriter, self).__init__(json5_file_path)
29 self._outputs = { 32 self._outputs = {
30 'CSSPropertyDescriptor.cpp': self.generate_property_descriptor_cpp, 33 'CSSPropertyDescriptor.cpp': self.generate_property_descriptor_cpp,
31 } 34 }
32 35
33 # Temporary map of API classname to list of propertyIDs that the API cla ss is for. 36 # Temporary map of API classname to list of propertyIDs that the API cla ss is for.
34 properties_for_class = defaultdict(list) 37 properties_for_class = defaultdict(list)
35 for property in self._properties.values(): 38 for property in self._properties.values():
36 if property['api_class'] is None: 39 if property['api_class'] is None:
37 continue 40 continue
38 classname = get_classname(property) 41 classname = get_classname(property)
39 properties_for_class[classname].append(property['property_id']) 42 properties_for_class[classname].append(property['property_id'])
40 self._outputs[classname + '.h'] = self.generate_property_api_h_build er(classname) 43 for method in property['api_methods']:
44 assert method in valid_methods, 'Invalid method ' + method + \
45 '. Methods added to the API must also be added to list of va lid methods.'
nainar 2017/01/31 03:21:19 valid methods -> valid_methods
46 self._outputs[classname + '.h'] = self.generate_property_api_h_build er(classname, property['api_methods'])
41 47
42 # Stores a list of classes with elements (index, classname, [propertyIDs , ..]). 48 # Stores a list of classes with elements (index, classname, [propertyIDs , ..]).
43 self._api_classes = [] 49 self._api_classes = []
44 50
45 ApiClass = namedtuple('ApiClass', ('index', 'classname', 'property_ids') ) 51 ApiClass = namedtuple('ApiClass', ('index', 'classname', 'property_ids') )
46 for i, classname in enumerate(properties_for_class.keys()): 52 for i, classname in enumerate(properties_for_class.keys()):
47 self._api_classes.append(ApiClass( 53 self._api_classes.append(ApiClass(
48 index=i + 1, 54 index=i + 1,
49 classname=classname, 55 classname=classname,
50 property_ids=properties_for_class[classname] 56 property_ids=properties_for_class[classname]
51 )) 57 ))
52 58
53 @template_expander.use_jinja('CSSPropertyDescriptor.cpp.tmpl') 59 @template_expander.use_jinja('CSSPropertyDescriptor.cpp.tmpl')
54 def generate_property_descriptor_cpp(self): 60 def generate_property_descriptor_cpp(self):
55 return { 61 return {
56 'api_classes': self._api_classes, 62 'api_classes': self._api_classes,
57 } 63 }
58 64
59 # Provides a function object given the classname of the property. 65 # Provides a function object given the classname of the property.
60 # This returned function generates a .h file for the specified property. 66 # This returned function generates a .h file for the specified property.
61 def generate_property_api_h_builder(self, api_classname): 67 def generate_property_api_h_builder(self, api_classname, implemented_functio ns):
62 @template_expander.use_jinja('CSSPropertyAPIFiles.h.tmpl') 68 @template_expander.use_jinja('CSSPropertyAPIFiles.h.tmpl')
63 def generate_property_api_h(): 69 def generate_property_api_h():
64 return { 70 return {
65 'api_classname': api_classname, 71 'api_classname': api_classname,
72 'implemented_functions': implemented_functions,
66 } 73 }
67 return generate_property_api_h 74 return generate_property_api_h
68 75
69 if __name__ == '__main__': 76 if __name__ == '__main__':
70 json5_generator.Maker(CSSPropertyAPIWriter).main() 77 json5_generator.Maker(CSSPropertyAPIWriter).main()
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/build/scripts/templates/CSSPropertyAPIFiles.h.tmpl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698