Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (C) 2013 Intel Corporation. All rights reserved. | 2 # Copyright (C) 2013 Intel Corporation. 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 10 matching lines...) Expand all Loading... | |
| 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 from collections import defaultdict | 30 from collections import defaultdict |
| 31 import re | |
| 32 import sys | 31 import sys |
| 33 | 32 |
| 33 import css_properties | |
| 34 import in_generator | 34 import in_generator |
| 35 from name_utilities import camelcase_property_name, lower_first | 35 from name_utilities import lower_first |
| 36 import template_expander | 36 import template_expander |
| 37 | 37 |
| 38 | 38 |
| 39 def _create_css_property_name_enum_value(property_name): | 39 class StylePropertyShorthandWriter(css_properties.CSSProperties): |
| 40 return 'CSSProperty' + property_name | |
| 41 | |
| 42 | |
| 43 class StylePropertyShorthandWriter(in_generator.Writer): | |
| 44 class_name = 'StylePropertyShorthand' | 40 class_name = 'StylePropertyShorthand' |
| 45 | 41 |
| 46 defaults = { | 42 def __init__(self, in_file_path): |
| 47 'longhands': '', | 43 super(StylePropertyShorthandWriter, self).__init__(in_file_path) |
| 48 'runtimeEnabledShorthand': None, | |
| 49 } | |
| 50 | |
| 51 def __init__(self, in_files): | |
| 52 super(StylePropertyShorthandWriter, self).__init__(in_files) | |
| 53 self._outputs = { | 44 self._outputs = { |
| 54 ('StylePropertyShorthand.cpp'): self.generate_style_property_shortha nd_cpp, | 45 ('StylePropertyShorthand.cpp'): self.generate_style_property_shortha nd_cpp, |
| 55 ('StylePropertyShorthand.h'): self.generate_style_property_shorthand _h} | 46 ('StylePropertyShorthand.h'): self.generate_style_property_shorthand _h} |
| 56 | 47 |
| 57 self._properties = self.in_file.name_dictionaries | |
| 58 self._longhand_dictionary = defaultdict(list) | 48 self._longhand_dictionary = defaultdict(list) |
| 59 | 49 |
| 60 for property in self._properties: | 50 self._properties = {property_id: property for property_id, property in s elf._properties.items() if property['longhands']} |
|
Nils Barth (inactive)
2014/07/07 16:43:28
dict()
| |
| 61 cc = camelcase_property_name(property['name']) | 51 |
| 62 property['property_id'] = _create_css_property_name_enum_value(cc) | 52 for property in self._properties.values(): |
| 63 cc = lower_first(cc) | 53 property['camel_case_longhands'] = map(self._css_name_to_enum, prope rty['longhands'].split(';')) |
|
Nils Barth (inactive)
2014/07/07 16:43:28
list comp
| |
| 64 property['camel_case_name'] = cc | 54 if property['runtime_enabled_shorthand']: |
| 65 longhands = property['longhands'].split(';') | 55 property['runtime_enabled_shorthand'] = lower_first(property['ru ntime_enabled_shorthand']) |
|
Nils Barth (inactive)
2014/07/07 16:43:28
FWIW, if special-cased None in lower_first, could
| |
| 66 property['camel_case_longhands'] = list() | 56 for longhand in property['camel_case_longhands']: |
| 67 for longhand in longhands: | |
| 68 longhand = camelcase_property_name(longhand) | |
| 69 longhand = _create_css_property_name_enum_value(longhand) | |
| 70 property['camel_case_longhands'].append(longhand) | |
| 71 self._longhand_dictionary[longhand].append(property) | 57 self._longhand_dictionary[longhand].append(property) |
| 72 if property['runtimeEnabledShorthand'] is not None: | |
| 73 lowerFirstConditional = lower_first(property['runtimeEnabledShor thand']) | |
| 74 property['runtime_conditional_getter'] = '%sEnabled' % lowerFirs tConditional | |
| 75 self._properties = dict((property['property_id'], property) for property in self._properties) | |
| 76 | 58 |
| 77 @template_expander.use_jinja('StylePropertyShorthand.cpp.tmpl') | 59 @template_expander.use_jinja('StylePropertyShorthand.cpp.tmpl') |
| 78 def generate_style_property_shorthand_cpp(self): | 60 def generate_style_property_shorthand_cpp(self): |
| 79 return { | 61 return { |
| 80 'properties': self._properties, | 62 'properties': self._properties, |
| 81 'longhands_dictionary': self._longhand_dictionary, | 63 'longhands_dictionary': self._longhand_dictionary, |
|
Nils Barth (inactive)
2014/07/07 16:43:28
alpha?
| |
| 82 } | 64 } |
| 83 | 65 |
| 84 @template_expander.use_jinja('StylePropertyShorthand.h.tmpl') | 66 @template_expander.use_jinja('StylePropertyShorthand.h.tmpl') |
| 85 def generate_style_property_shorthand_h(self): | 67 def generate_style_property_shorthand_h(self): |
| 86 return { | 68 return { |
| 87 'properties': self._properties, | 69 'properties': self._properties, |
| 88 } | 70 } |
| 89 | 71 |
| 90 if __name__ == '__main__': | 72 if __name__ == '__main__': |
| 91 in_generator.Maker(StylePropertyShorthandWriter).main(sys.argv) | 73 in_generator.Maker(StylePropertyShorthandWriter).main(sys.argv) |
| OLD | NEW |