Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / build / scripts / make_style_builder.py
1 #!/usr/bin/env python
2 # Copyright (C) 2013 Google Inc. All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
6 # met:
7 #
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
13 # distribution.
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.
17 #
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.
29
30 import sys
31
32 import css_properties
33 import in_generator
34 from name_utilities import lower_first
35 import template_expander
36
37
38 class StyleBuilderWriter(css_properties.CSSProperties):
39     filters = {
40         'lower_first': lower_first,
41     }
42
43     def __init__(self, in_file_path):
44         super(StyleBuilderWriter, self).__init__(in_file_path)
45         self._outputs = {('StyleBuilderFunctions.h'): self.generate_style_builder_functions_h,
46                          ('StyleBuilderFunctions.cpp'): self.generate_style_builder_functions_cpp,
47                          ('StyleBuilder.cpp'): self.generate_style_builder,
48                         }
49
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():
55             upper_camel = property['upper_camel_name']
56             set_if_none(property, 'name_for_methods', upper_camel.replace('Webkit', ''))
57             name = property['name_for_methods']
58             set_if_none(property, 'type_name', 'E' + name)
59             set_if_none(property, 'getter', lower_first(name))
60             set_if_none(property, 'setter', 'set' + name)
61             set_if_none(property, 'initial', 'initial' + name)
62             if property['custom_all']:
63                 property['custom_initial'] = True
64                 property['custom_inherit'] = True
65                 property['custom_value'] = True
66             property['should_declare_functions'] = not property['use_handlers_for'] and not property['longhands'] \
67                                                    and not property['direction_aware'] and not property['builder_skip']
68
69     @template_expander.use_jinja('StyleBuilderFunctions.h.tmpl',
70                                  filters=filters)
71     def generate_style_builder_functions_h(self):
72         return {
73             'properties': self._properties,
74         }
75
76     @template_expander.use_jinja('StyleBuilderFunctions.cpp.tmpl',
77                                  filters=filters)
78     def generate_style_builder_functions_cpp(self):
79         return {
80             'properties': self._properties,
81         }
82
83     @template_expander.use_jinja('StyleBuilder.cpp.tmpl', filters=filters)
84     def generate_style_builder(self):
85         return {
86             'properties': self._properties,
87         }
88
89
90 if __name__ == '__main__':
91     in_generator.Maker(StyleBuilderWriter).main(sys.argv)