| 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 } | |
| 49 | |
| 50 def __init__(self, in_files): | |
| 51 super(StylePropertyShorthandWriter, self).__init__(in_files) | |
| 52 self._outputs = { | 44 self._outputs = { |
| 53 ('StylePropertyShorthand.cpp'): self.generate_style_property_shortha
nd_cpp, | 45 ('StylePropertyShorthand.cpp'): self.generate_style_property_shortha
nd_cpp, |
| 54 ('StylePropertyShorthand.h'): self.generate_style_property_shorthand
_h} | 46 ('StylePropertyShorthand.h'): self.generate_style_property_shorthand
_h} |
| 55 | 47 |
| 56 self._properties = self.in_file.name_dictionaries | |
| 57 self._longhand_dictionary = defaultdict(list) | 48 self._longhand_dictionary = defaultdict(list) |
| 58 | 49 |
| 59 for property in self._properties: | 50 self._properties = {property_id: property for property_id, property in s
elf._properties.items() if property['longhands']} |
| 60 cc = camelcase_property_name(property['name']) | 51 |
| 61 property['property_id'] = _create_css_property_name_enum_value(cc) | 52 for property in self._properties.values(): |
| 62 cc = lower_first(cc) | 53 property['longhand_property_ids'] = map(css_properties.css_name_to_e
num, property['longhands'].split(';')) |
| 63 property['camel_case_name'] = cc | 54 for longhand in property['longhand_property_ids']: |
| 64 longhands = property['longhands'].split(';') | |
| 65 property['camel_case_longhands'] = list() | |
| 66 for longhand in longhands: | |
| 67 longhand = camelcase_property_name(longhand) | |
| 68 longhand = _create_css_property_name_enum_value(longhand) | |
| 69 property['camel_case_longhands'].append(longhand) | |
| 70 self._longhand_dictionary[longhand].append(property) | 55 self._longhand_dictionary[longhand].append(property) |
| 71 self._properties = dict((property['property_id'], property) for property
in self._properties) | |
| 72 | 56 |
| 73 @template_expander.use_jinja('StylePropertyShorthand.cpp.tmpl') | 57 @template_expander.use_jinja('StylePropertyShorthand.cpp.tmpl') |
| 74 def generate_style_property_shorthand_cpp(self): | 58 def generate_style_property_shorthand_cpp(self): |
| 75 return { | 59 return { |
| 76 'properties': self._properties, | 60 'properties': self._properties, |
| 77 'longhands_dictionary': self._longhand_dictionary, | 61 'longhands_dictionary': self._longhand_dictionary, |
| 78 } | 62 } |
| 79 | 63 |
| 80 @template_expander.use_jinja('StylePropertyShorthand.h.tmpl') | 64 @template_expander.use_jinja('StylePropertyShorthand.h.tmpl') |
| 81 def generate_style_property_shorthand_h(self): | 65 def generate_style_property_shorthand_h(self): |
| 82 return { | 66 return { |
| 83 'properties': self._properties, | 67 'properties': self._properties, |
| 84 } | 68 } |
| 85 | 69 |
| 86 if __name__ == '__main__': | 70 if __name__ == '__main__': |
| 87 in_generator.Maker(StylePropertyShorthandWriter).main(sys.argv) | 71 in_generator.Maker(StylePropertyShorthandWriter).main(sys.argv) |
| OLD | NEW |