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 os.path | 30 import re |
31 import sys | 31 import sys |
32 | 32 |
33 import in_generator | 33 import in_generator |
34 import make_runtime_features | |
35 | 34 |
36 | 35 |
37 # We want exactly the same parsing as RuntimeFeatureWriter | 36 class StyleBuilderWriter(in_generator.Writer): |
38 # but generate different files. | 37 class_name = 'StyleBuilder' |
39 class InternalRuntimeFlagsWriter(make_runtime_features.RuntimeFeatureWriter): | |
40 class_name = "InternalRuntimeFlags" | |
41 | 38 |
42 def generate_idl(self): | 39 valid_values = { |
43 return { | 40 'applytype': ['default'], |
44 'features': self._features, | 41 } |
45 } | 42 defaults = { |
| 43 'condition': None, |
| 44 'applytype': 'default', |
| 45 'nameformethods': None, |
| 46 # depends on property name by default |
| 47 'typename': None, |
| 48 'getter': None, |
| 49 'setter': None, |
| 50 'initial': None, |
| 51 } |
46 | 52 |
47 def generate_header(self): | 53 def __init__(self, in_file_path): |
48 return { | 54 super(StyleBuilderWriter, self).__init__(in_file_path) |
49 'features': self._features, | 55 self._properties = self.in_file.name_dictionaries |
50 'feature_sets': self._feature_sets(), | 56 |
51 } | 57 def set_if_none(property, key, value): |
| 58 if property[key] is None: |
| 59 property[key] = value |
| 60 |
| 61 for property in self._properties: |
| 62 cc = self._camelcase_property_name(property["name"]) |
| 63 property["propertyid"] = "CSSProperty" + cc |
| 64 cc = property["nameformethods"] or cc.replace("Webkit", "") |
| 65 set_if_none(property, "typename", "E" + cc) |
| 66 set_if_none(property, "getter", self._lower_first(cc)) |
| 67 set_if_none(property, "setter", "set" + cc) |
| 68 set_if_none(property, "initial", "initial" + cc) |
| 69 |
| 70 # FIXME: some of these might be better in a utils file |
| 71 @staticmethod |
| 72 def _camelcase_property_name(property_name): |
| 73 return re.sub(r'(^[^-])|-(.)', lambda match: (match.group(1) or match.gr
oup(2)).upper(), property_name) |
| 74 |
| 75 @staticmethod |
| 76 def _lower_first(s): |
| 77 return s[0].lower() + s[1:] |
| 78 |
| 79 @staticmethod |
| 80 def _upper_first(s): |
| 81 return s[0].upper() + s[1:] |
52 | 82 |
53 def generate_implementation(self): | 83 def generate_implementation(self): |
54 return None | 84 return { |
| 85 "properties": self._properties, |
| 86 } |
55 | 87 |
56 | 88 |
57 if __name__ == "__main__": | 89 if __name__ == "__main__": |
58 in_generator.Maker(InternalRuntimeFlagsWriter).main(sys.argv) | 90 in_generator.Maker(StyleBuilderWriter).main(sys.argv) |
OLD | NEW |