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 |
(...skipping 13 matching lines...) Expand all Loading... |
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 | 30 import re |
31 import sys | 31 import sys |
32 | 32 |
33 import in_generator | 33 import in_generator |
| 34 import template_expander |
34 | 35 |
35 | 36 |
36 class StyleBuilderWriter(in_generator.Writer): | 37 class StyleBuilderWriter(in_generator.Writer): |
37 class_name = 'StyleBuilder' | 38 class_name = 'StyleBuilder' |
38 | 39 |
39 valid_values = { | 40 valid_values = { |
40 'apply_type': ['default', 'length'], | 41 'apply_type': ['default', 'length'], |
41 'use_none': [True, False], | 42 'use_none': [True, False], |
42 'use_intrinsic': [True, False], | 43 'use_intrinsic': [True, False], |
43 'use_auto': [True, False], | 44 'use_auto': [True, False], |
| 45 'custom_all': [True, False], |
| 46 'custom_initial': [True, False], |
| 47 'custom_inherit': [True, False], |
| 48 'custom_value': [True, False], |
44 } | 49 } |
45 defaults = { | 50 defaults = { |
46 'condition': None, | 51 'condition': None, |
47 'apply_type': 'default', | 52 'apply_type': 'default', |
48 'name_for_methods': None, | 53 'name_for_methods': None, |
49 # These depend on property name by default | 54 # These depend on property name by default |
50 'type_name': None, | 55 'type_name': None, |
51 'getter': None, | 56 'getter': None, |
52 'setter': None, | 57 'setter': None, |
53 'initial': None, | 58 'initial': None, |
54 # For the length apply type | 59 # Setting these stops default handlers being generated |
| 60 # Setting custom_all is the same as setting the other three |
| 61 'custom_all': False, |
| 62 'custom_initial': False, |
| 63 'custom_inherit': False, |
| 64 'custom_value': False, |
| 65 # For the length apply type. Will get moved out to StyleBuilderFunctions.cpp.tmp
l |
55 'use_none': False, | 66 'use_none': False, |
56 'use_intrinsic': False, | 67 'use_intrinsic': False, |
57 'use_auto': False, | 68 'use_auto': False, |
58 } | 69 } |
59 | 70 |
60 def __init__(self, in_files, enabled_conditions): | 71 def __init__(self, in_files, enabled_conditions): |
61 super(StyleBuilderWriter, self).__init__(in_files, enabled_conditions) | 72 super(StyleBuilderWriter, self).__init__(in_files, enabled_conditions) |
| 73 self._outputs = {("StyleBuilderFunctions.h"): self.generate_style_builde
r_functions_h, |
| 74 ("StyleBuilderFunctions.cpp"): self.generate_style_buil
der_functions_cpp, |
| 75 ("StyleBuilder.cpp"): self.generate_style_builder, |
| 76 } |
| 77 |
62 self._properties = self.in_file.name_dictionaries | 78 self._properties = self.in_file.name_dictionaries |
63 | 79 |
64 def set_if_none(property, key, value): | 80 def set_if_none(property, key, value): |
65 if property[key] is None: | 81 if property[key] is None: |
66 property[key] = value | 82 property[key] = value |
67 | 83 |
68 for property in self._properties: | 84 for property in self._properties: |
69 cc = self._camelcase_property_name(property["name"]) | 85 cc = self._camelcase_property_name(property["name"]) |
70 property["property_id"] = "CSSProperty" + cc | 86 property["property_id"] = "CSSProperty" + cc |
71 cc = property["name_for_methods"] or cc.replace("Webkit", "") | 87 cc = property["name_for_methods"] or cc.replace("Webkit", "") |
72 set_if_none(property, "type_name", "E" + cc) | 88 set_if_none(property, "type_name", "E" + cc) |
73 set_if_none(property, "getter", self._lower_first(cc)) | 89 set_if_none(property, "getter", self._lower_first(cc)) |
74 set_if_none(property, "setter", "set" + cc) | 90 set_if_none(property, "setter", "set" + cc) |
75 set_if_none(property, "initial", "initial" + cc) | 91 set_if_none(property, "initial", "initial" + cc) |
| 92 if property["custom_all"]: |
| 93 property["custom_initial"] = True |
| 94 property["custom_inherit"] = True |
| 95 property["custom_value"] = True |
| 96 |
| 97 self._properties = dict((property["property_id"], property) for property
in self._properties) |
76 | 98 |
77 # FIXME: some of these might be better in a utils file | 99 # FIXME: some of these might be better in a utils file |
78 @staticmethod | 100 @staticmethod |
79 def _camelcase_property_name(property_name): | 101 def _camelcase_property_name(property_name): |
80 return re.sub(r'(^[^-])|-(.)', lambda match: (match.group(1) or match.gr
oup(2)).upper(), property_name) | 102 return re.sub(r'(^[^-])|-(.)', lambda match: (match.group(1) or match.gr
oup(2)).upper(), property_name) |
81 | 103 |
82 @staticmethod | 104 @staticmethod |
83 def _lower_first(s): | 105 def _lower_first(s): |
84 return s[0].lower() + s[1:] | 106 return s[0].lower() + s[1:] |
85 | 107 |
86 @staticmethod | 108 @staticmethod |
87 def _upper_first(s): | 109 def _upper_first(s): |
88 return s[0].upper() + s[1:] | 110 return s[0].upper() + s[1:] |
89 | 111 |
90 def generate_implementation(self): | 112 @template_expander.use_jinja("StyleBuilderFunctions.h.tmpl") |
| 113 def generate_style_builder_functions_h(self): |
| 114 return { |
| 115 "properties": self._properties, |
| 116 } |
| 117 |
| 118 @template_expander.use_jinja("StyleBuilderFunctions.cpp.tmpl") |
| 119 def generate_style_builder_functions_cpp(self): |
| 120 return { |
| 121 "properties": self._properties, |
| 122 } |
| 123 |
| 124 @template_expander.use_jinja("StyleBuilder.cpp.tmpl") |
| 125 def generate_style_builder(self): |
91 return { | 126 return { |
92 "properties": self._properties, | 127 "properties": self._properties, |
93 } | 128 } |
94 | 129 |
95 | 130 |
96 if __name__ == "__main__": | 131 if __name__ == "__main__": |
97 in_generator.Maker(StyleBuilderWriter).main(sys.argv) | 132 in_generator.Maker(StyleBuilderWriter).main(sys.argv) |
OLD | NEW |