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

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: Add TODO 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 # TODO(shend): Rearrange the code below to separate assignment and set_if_no ne
45 upper_camel = upper_camel_case(property_['name'])
46 set_if_none(property_, 'name_for_methods', upper_camel.replace('Webkit', '') )
47 name = property_['name_for_methods']
48 simple_type_name = str(property_['type_name']).split('::')[-1]
49 set_if_none(property_, 'type_name', 'E' + name)
50 set_if_none(property_, 'getter', name if simple_type_name != name else 'Get' + name)
51 set_if_none(property_, 'setter', 'Set' + name)
52 set_if_none(property_, 'inherited', False)
53 set_if_none(property_, 'initial', 'Initial' + name)
54
55 if property_['custom_all']:
56 property_['custom_initial'] = True
57 property_['custom_inherit'] = True
58 property_['custom_value'] = True
59 if property_['inherited']:
60 property_['is_inherited_setter'] = 'Set' + name + 'IsInherited'
61 property_['should_declare_functions'] = not property_['use_handlers_for'] an d not property_['longhands'] \
62 and not property_['direction_aware'] and not property_['builder_skip'] \
63 and property_['is_property']
64
65
38 class StyleBuilderWriter(css_properties.CSSProperties): 66 class StyleBuilderWriter(css_properties.CSSProperties):
39 filters = { 67 filters = {
40 'lower_first': lower_first, 68 'lower_first': lower_first,
41 } 69 }
42 70
43 def __init__(self, json5_file_path): 71 def __init__(self, json5_file_path):
44 super(StyleBuilderWriter, self).__init__(json5_file_path) 72 super(StyleBuilderWriter, self).__init__(json5_file_path)
45 self._outputs = {('StyleBuilderFunctions.h'): self.generate_style_builde r_functions_h, 73 self._outputs = {('StyleBuilderFunctions.h'): self.generate_style_builde r_functions_h,
46 ('StyleBuilderFunctions.cpp'): self.generate_style_buil der_functions_cpp, 74 ('StyleBuilderFunctions.cpp'): self.generate_style_buil der_functions_cpp,
47 ('StyleBuilder.cpp'): self.generate_style_builder, 75 ('StyleBuilder.cpp'): self.generate_style_builder,
48 } 76 }
49 77
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(): 78 for property in self._properties.values():
55 upper_camel = property['upper_camel_name'] 79 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 80
74 @template_expander.use_jinja('StyleBuilderFunctions.h.tmpl', 81 @template_expander.use_jinja('StyleBuilderFunctions.h.tmpl',
75 filters=filters) 82 filters=filters)
76 def generate_style_builder_functions_h(self): 83 def generate_style_builder_functions_h(self):
77 return { 84 return {
78 'properties': self._properties, 85 'properties': self._properties,
79 } 86 }
80 87
81 @template_expander.use_jinja('StyleBuilderFunctions.cpp.tmpl', 88 @template_expander.use_jinja('StyleBuilderFunctions.cpp.tmpl',
82 filters=filters) 89 filters=filters)
83 def generate_style_builder_functions_cpp(self): 90 def generate_style_builder_functions_cpp(self):
84 return { 91 return {
85 'properties': self._properties, 92 'properties': self._properties,
86 } 93 }
87 94
88 @template_expander.use_jinja('StyleBuilder.cpp.tmpl', filters=filters) 95 @template_expander.use_jinja('StyleBuilder.cpp.tmpl', filters=filters)
89 def generate_style_builder(self): 96 def generate_style_builder(self):
90 return { 97 return {
91 'properties': self._properties, 98 'properties': self._properties,
92 } 99 }
93 100
94 101
95 if __name__ == '__main__': 102 if __name__ == '__main__':
96 json5_generator.Maker(StyleBuilderWriter).main() 103 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