| OLD | NEW |
| 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 |
| 11 # copyright notice, this list of conditions and the following disclaimer | 11 # copyright notice, this list of conditions and the following disclaimer |
| 12 # in the documentation and/or other materials provided with the | 12 # in the documentation and/or other materials provided with the |
| 13 # distribution. | 13 # distribution. |
| 14 # * Neither the name of Google Inc. nor the names of its | 14 # * Neither the name of Google Inc. nor the names of its |
| 15 # contributors may be used to endorse or promote products derived from | 15 # contributors may be used to endorse or promote products derived from |
| 16 # this software without specific prior written permission. | 16 # this software without specific prior written permission. |
| 17 # | 17 # |
| 18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 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 re | |
| 31 import sys | 30 import sys |
| 32 | 31 |
| 32 import css_properties |
| 33 import in_generator | 33 import in_generator |
| 34 import name_utilities | 34 from name_utilities import lower_first |
| 35 from name_utilities import camelcase_property_name, lower_first | |
| 36 import template_expander | 35 import template_expander |
| 37 | 36 |
| 38 | 37 |
| 39 class StyleBuilderWriter(in_generator.Writer): | 38 class StyleBuilderWriter(css_properties.CSSProperties): |
| 40 class_name = 'StyleBuilder' | |
| 41 filters = { | 39 filters = { |
| 42 'lower_first': lower_first, | 40 'lower_first': lower_first, |
| 43 } | 41 } |
| 44 | 42 |
| 45 valid_values = { | 43 def __init__(self, in_file_path): |
| 46 'svg': [True, False], | 44 super(StyleBuilderWriter, self).__init__(in_file_path) |
| 47 'font': [True, False], | |
| 48 'custom_all': [True, False], | |
| 49 'custom_initial': [True, False], | |
| 50 'custom_inherit': [True, False], | |
| 51 'custom_value': [True, False], | |
| 52 'skip': [True, False], | |
| 53 } | |
| 54 defaults = { | |
| 55 'name_for_methods': None, | |
| 56 'svg': False, | |
| 57 'font': False, | |
| 58 'converter': None, | |
| 59 'skip': False, | |
| 60 # These depend on property name by default | |
| 61 'type_name': None, | |
| 62 'getter': None, | |
| 63 'setter': None, | |
| 64 'initial': None, | |
| 65 # Setting these stops default handlers being generated | |
| 66 # Setting custom_all is the same as setting the other three | |
| 67 'custom_all': False, | |
| 68 'custom_initial': False, | |
| 69 'custom_inherit': False, | |
| 70 'custom_value': False, | |
| 71 } | |
| 72 | |
| 73 def __init__(self, in_files): | |
| 74 super(StyleBuilderWriter, self).__init__(in_files) | |
| 75 self._outputs = {('StyleBuilderFunctions.h'): self.generate_style_builde
r_functions_h, | 45 self._outputs = {('StyleBuilderFunctions.h'): self.generate_style_builde
r_functions_h, |
| 76 ('StyleBuilderFunctions.cpp'): self.generate_style_buil
der_functions_cpp, | 46 ('StyleBuilderFunctions.cpp'): self.generate_style_buil
der_functions_cpp, |
| 77 ('StyleBuilder.cpp'): self.generate_style_builder, | 47 ('StyleBuilder.cpp'): self.generate_style_builder, |
| 78 } | 48 } |
| 79 | 49 |
| 80 self._properties = self.in_file.name_dictionaries | |
| 81 | |
| 82 def set_if_none(property, key, value): | 50 def set_if_none(property, key, value): |
| 83 if property[key] is None: | 51 if property[key] is None: |
| 84 property[key] = value | 52 property[key] = value |
| 85 | 53 |
| 86 for property in self._properties: | 54 for property in self._properties.values(): |
| 87 cc = camelcase_property_name(property['name']) | 55 upper_camel = property['upper_camel_name'] |
| 88 property['property_id'] = 'CSSProperty' + cc | 56 set_if_none(property, 'name_for_methods', upper_camel.replace('Webki
t', '')) |
| 89 cc = property['name_for_methods'] or cc.replace('Webkit', '') | 57 name = property['name_for_methods'] |
| 90 property['camel_case_name'] = cc | 58 set_if_none(property, 'type_name', 'E' + name) |
| 91 set_if_none(property, 'type_name', 'E' + cc) | 59 set_if_none(property, 'getter', lower_first(name)) |
| 92 set_if_none(property, 'getter', lower_first(cc)) | 60 set_if_none(property, 'setter', 'set' + name) |
| 93 set_if_none(property, 'setter', 'set' + cc) | 61 set_if_none(property, 'initial', 'initial' + name) |
| 94 set_if_none(property, 'initial', 'initial' + cc) | 62 if property['sb_custom_all']: |
| 95 if property['custom_all']: | 63 property['sb_custom_initial'] = True |
| 96 property['custom_initial'] = True | 64 property['sb_custom_inherit'] = True |
| 97 property['custom_inherit'] = True | 65 property['sb_custom_value'] = True |
| 98 property['custom_value'] = True | 66 if property['longhands']: |
| 99 property['should_declare_functions'] = not property['skip'] | 67 property['sb_unreachable'] = True |
| 68 property['should_declare_functions'] = not property['sb_unreachable'
] and not property['sb_skip'] |
| 100 | 69 |
| 101 self._properties = dict((property['property_id'], property) for property
in self._properties) | 70 self._properties['CSSPropertyFont']['should_declare_functions'] = True |
| 102 | 71 |
| 103 @template_expander.use_jinja('StyleBuilderFunctions.h.tmpl', | 72 @template_expander.use_jinja('StyleBuilderFunctions.h.tmpl', |
| 104 filters=filters) | 73 filters=filters) |
| 105 def generate_style_builder_functions_h(self): | 74 def generate_style_builder_functions_h(self): |
| 106 return { | 75 return { |
| 107 'properties': self._properties, | 76 'properties': self._properties, |
| 108 } | 77 } |
| 109 | 78 |
| 110 @template_expander.use_jinja('StyleBuilderFunctions.cpp.tmpl', | 79 @template_expander.use_jinja('StyleBuilderFunctions.cpp.tmpl', |
| 111 filters=filters) | 80 filters=filters) |
| 112 def generate_style_builder_functions_cpp(self): | 81 def generate_style_builder_functions_cpp(self): |
| 113 return { | 82 return { |
| 114 'properties': self._properties, | 83 'properties': self._properties, |
| 115 } | 84 } |
| 116 | 85 |
| 117 @template_expander.use_jinja('StyleBuilder.cpp.tmpl', filters=filters) | 86 @template_expander.use_jinja('StyleBuilder.cpp.tmpl', filters=filters) |
| 118 def generate_style_builder(self): | 87 def generate_style_builder(self): |
| 119 return { | 88 return { |
| 120 'properties': self._properties, | 89 'properties': self._properties, |
| 121 } | 90 } |
| 122 | 91 |
| 123 | 92 |
| 124 if __name__ == '__main__': | 93 if __name__ == '__main__': |
| 125 in_generator.Maker(StyleBuilderWriter).main(sys.argv) | 94 in_generator.Maker(StyleBuilderWriter).main(sys.argv) |
| OLD | NEW |