2 # Copyright (C) 2013 Google Inc. All rights reserved.
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following disclaimer
12 # in the documentation and/or other materials provided with the
14 # * Neither the name of Google Inc. nor the names of its
15 # contributors may be used to endorse or promote products derived from
16 # this software without specific prior written permission.
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
35 from name_utilities import camelcase_property_name, lower_first
36 import template_expander
39 class StyleBuilderWriter(in_generator.Writer):
40 class_name = 'StyleBuilder'
42 'lower_first': lower_first,
47 'font': [True, False],
48 'custom_all': [True, False],
49 'custom_initial': [True, False],
50 'custom_inherit': [True, False],
51 'custom_value': [True, False],
54 'name_for_methods': None,
55 'use_handlers_for': None,
59 # These depend on property name by default
64 # Setting these stops default handlers being generated
65 # Setting custom_all is the same as setting the other three
67 'custom_initial': False,
68 'custom_inherit': False,
69 'custom_value': False,
72 def __init__(self, in_files):
73 super(StyleBuilderWriter, self).__init__(in_files)
74 self._outputs = {('StyleBuilderFunctions.h'): self.generate_style_builder_functions_h,
75 ('StyleBuilderFunctions.cpp'): self.generate_style_builder_functions_cpp,
76 ('StyleBuilder.cpp'): self.generate_style_builder,
79 self._properties = self.in_file.name_dictionaries
81 def set_if_none(property, key, value):
82 if property[key] is None:
85 for property in self._properties:
86 cc = camelcase_property_name(property['name'])
87 property['property_id'] = 'CSSProperty' + cc
88 cc = property['name_for_methods'] or cc.replace('Webkit', '')
89 property['camel_case_name'] = cc
90 set_if_none(property, 'type_name', 'E' + cc)
91 set_if_none(property, 'getter', lower_first(cc))
92 set_if_none(property, 'setter', 'set' + cc)
93 set_if_none(property, 'initial', 'initial' + cc)
94 if property['custom_all']:
95 property['custom_initial'] = True
96 property['custom_inherit'] = True
97 property['custom_value'] = True
99 self._properties = dict((property['property_id'], property) for property in self._properties)
101 @template_expander.use_jinja('StyleBuilderFunctions.h.tmpl',
103 def generate_style_builder_functions_h(self):
105 'properties': self._properties,
108 @template_expander.use_jinja('StyleBuilderFunctions.cpp.tmpl',
110 def generate_style_builder_functions_cpp(self):
112 'properties': self._properties,
115 @template_expander.use_jinja('StyleBuilder.cpp.tmpl', filters=filters)
116 def generate_style_builder(self):
118 'properties': self._properties,
122 if __name__ == '__main__':
123 in_generator.Maker(StyleBuilderWriter).main(sys.argv)