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

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

Issue 2811253002: Extract default naming logic in StyleBuilderWriter to a method. (Closed)
Patch Set: Address comments Created 3 years, 8 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 | « third_party/WebKit/Source/build/scripts/make_computed_style_base.py ('k') | no next file » | 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 (C) 2013 Google Inc. All rights reserved. 2 # Copyright (C) 2013 Google Inc. All rights reserved.
3 # 3 #
4 # Redistribution and use in source and binary forms, with or without 4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are 5 # modification, are permitted provided that the following conditions are
6 # met: 6 # met:
7 # 7 #
8 # * Redistributions of source code must retain the above copyright 8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer. 9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above 10 # * Redistributions in binary form must reproduce the above
(...skipping 13 matching lines...) Expand all
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 29
30 import sys 30 import sys
31 31
32 import css_properties 32 import css_properties
33 import json5_generator 33 import json5_generator
34 from name_utilities import lower_first 34 from name_utilities import lower_first, upper_camel_case
35 import template_expander 35 import template_expander
36 36
37 37
38 def apply_property_naming_defaults(property_):
39 def set_if_none(property_, key, value):
40 if property_[key] is None:
41 property_[key] = value
42
43 # TODO(shend): Use name_utilities for manipulating names.
44 upper_camel = upper_camel_case(property_['name'])
45 set_if_none(property_, 'name_for_methods', upper_camel.replace('Webkit', '') )
46 name = property_['name_for_methods']
47 simple_type_name = str(property_['type_name']).split('::')[-1]
alancutter (OOO until 2018) 2017/04/20 04:39:48 Nit: The interlacing of these statements is a bit
shend 2017/04/20 06:32:53 Added a TODO.
48 set_if_none(property_, 'type_name', 'E' + name)
49 set_if_none(property_, 'getter', name if simple_type_name != name else 'Get' + name)
50 set_if_none(property_, 'setter', 'Set' + name)
51 set_if_none(property_, 'inherited', False)
52 set_if_none(property_, 'initial', 'Initial' + name)
53
54 if property_['custom_all']:
55 property_['custom_initial'] = True
56 property_['custom_inherit'] = True
57 property_['custom_value'] = True
58 if property_['inherited']:
59 property_['is_inherited_setter'] = 'Set' + name + 'IsInherited'
60 property_['should_declare_functions'] = not property_['use_handlers_for'] an d not property_['longhands'] \
61 and not property_['direction_aware'] and not property_['builder_skip'] \
62 and property_['is_property']
63
64
38 class StyleBuilderWriter(css_properties.CSSProperties): 65 class StyleBuilderWriter(css_properties.CSSProperties):
39 filters = { 66 filters = {
40 'lower_first': lower_first, 67 'lower_first': lower_first,
41 } 68 }
42 69
43 def __init__(self, json5_file_path): 70 def __init__(self, json5_file_path):
44 super(StyleBuilderWriter, self).__init__(json5_file_path) 71 super(StyleBuilderWriter, self).__init__(json5_file_path)
45 self._outputs = {('StyleBuilderFunctions.h'): self.generate_style_builde r_functions_h, 72 self._outputs = {('StyleBuilderFunctions.h'): self.generate_style_builde r_functions_h,
46 ('StyleBuilderFunctions.cpp'): self.generate_style_buil der_functions_cpp, 73 ('StyleBuilderFunctions.cpp'): self.generate_style_buil der_functions_cpp,
47 ('StyleBuilder.cpp'): self.generate_style_builder, 74 ('StyleBuilder.cpp'): self.generate_style_builder,
48 } 75 }
49 76
50 def set_if_none(property, key, value):
51 if property[key] is None:
52 property[key] = value
53
54 for property in self._properties.values(): 77 for property in self._properties.values():
55 upper_camel = property['upper_camel_name'] 78 apply_property_naming_defaults(property)
56 set_if_none(property, 'name_for_methods', upper_camel.replace('Webki t', ''))
57 name = property['name_for_methods']
58 simple_type_name = str(property['type_name']).split('::')[-1]
59 set_if_none(property, 'type_name', 'E' + name)
60 set_if_none(property, 'getter', name if simple_type_name != name els e 'Get' + name)
61 set_if_none(property, 'setter', 'Set' + name)
62 set_if_none(property, 'inherited', False)
63 set_if_none(property, 'initial', 'Initial' + name)
64 if property['custom_all']:
65 property['custom_initial'] = True
66 property['custom_inherit'] = True
67 property['custom_value'] = True
68 if property['inherited']:
69 property['is_inherited_setter'] = 'Set' + name + 'IsInherited'
70 property['should_declare_functions'] = not property['use_handlers_fo r'] and not property['longhands'] \
71 and not property['direction_aware'] and not property['builder_sk ip'] \
72 and property['is_property']
73 79
74 @template_expander.use_jinja('StyleBuilderFunctions.h.tmpl', 80 @template_expander.use_jinja('StyleBuilderFunctions.h.tmpl',
75 filters=filters) 81 filters=filters)
76 def generate_style_builder_functions_h(self): 82 def generate_style_builder_functions_h(self):
77 return { 83 return {
78 'properties': self._properties, 84 'properties': self._properties,
79 } 85 }
80 86
81 @template_expander.use_jinja('StyleBuilderFunctions.cpp.tmpl', 87 @template_expander.use_jinja('StyleBuilderFunctions.cpp.tmpl',
82 filters=filters) 88 filters=filters)
83 def generate_style_builder_functions_cpp(self): 89 def generate_style_builder_functions_cpp(self):
84 return { 90 return {
85 'properties': self._properties, 91 'properties': self._properties,
86 } 92 }
87 93
88 @template_expander.use_jinja('StyleBuilder.cpp.tmpl', filters=filters) 94 @template_expander.use_jinja('StyleBuilder.cpp.tmpl', filters=filters)
89 def generate_style_builder(self): 95 def generate_style_builder(self):
90 return { 96 return {
91 'properties': self._properties, 97 'properties': self._properties,
92 } 98 }
93 99
94 100
95 if __name__ == '__main__': 101 if __name__ == '__main__':
96 json5_generator.Maker(StyleBuilderWriter).main() 102 json5_generator.Maker(StyleBuilderWriter).main()
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/build/scripts/make_computed_style_base.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698