• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
30import sys
31
32import css_properties
33import in_generator
34from name_utilities import lower_first
35import template_expander
36
37
38class 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        self._properties['CSSPropertyFont']['should_declare_functions'] = True
70
71    @template_expander.use_jinja('StyleBuilderFunctions.h.tmpl',
72                                 filters=filters)
73    def generate_style_builder_functions_h(self):
74        return {
75            'properties': self._properties,
76        }
77
78    @template_expander.use_jinja('StyleBuilderFunctions.cpp.tmpl',
79                                 filters=filters)
80    def generate_style_builder_functions_cpp(self):
81        return {
82            'properties': self._properties,
83        }
84
85    @template_expander.use_jinja('StyleBuilder.cpp.tmpl', filters=filters)
86    def generate_style_builder(self):
87        return {
88            'properties': self._properties,
89        }
90
91
92if __name__ == '__main__':
93    in_generator.Maker(StyleBuilderWriter).main(sys.argv)
94