OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright (C) 2013 Intel Corporation. All rights reserved. |
| 3 # |
| 4 # Redistribution and use in source and binary forms, with or without |
| 5 # modification, are permitted provided that the following conditions are |
| 6 # met: |
| 7 # |
| 8 # * Redistributions of source code must retain the above copyright |
| 9 # notice, this list of conditions and the following disclaimer. |
| 10 # * Redistributions in binary form must reproduce the above |
| 11 # copyright notice, this list of conditions and the following disclaimer |
| 12 # in the documentation and/or other materials provided with the |
| 13 # distribution. |
| 14 # * Neither the name of Google Inc. nor the names of its |
| 15 # contributors may be used to endorse or promote products derived from |
| 16 # this software without specific prior written permission. |
| 17 # |
| 18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 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. |
| 29 |
| 30 import re |
| 31 import sys |
| 32 from collections import defaultdict |
| 33 |
| 34 import in_generator |
| 35 import template_expander |
| 36 |
| 37 |
| 38 class StylePropertyShorthandWriter(in_generator.Writer): |
| 39 class_name = 'StylePropertyShorthand' |
| 40 |
| 41 defaults = { |
| 42 'longhands': "", |
| 43 } |
| 44 |
| 45 def __init__(self, in_files, enabled_conditions): |
| 46 super(StylePropertyShorthandWriter, self).__init__(in_files, enabled_con
ditions) |
| 47 self._outputs = {("StylePropertyShorthand.cpp"): self.generate_style_pro
perty_shorthand_cpp, ("StylePropertyShorthand.h"): self.generate_style_property_
shorthand_h} |
| 48 |
| 49 self._properties = self.in_file.name_dictionaries |
| 50 self._longhand_dictionary = defaultdict(list) |
| 51 |
| 52 for property in self._properties: |
| 53 cc = self._camelcase_property_name(property["name"]) |
| 54 property["property_id"] = self._create_css_property_name_enum_value(
cc) |
| 55 cc = cc[0].lower() + cc[1:] |
| 56 property["camel_case_name"] = cc |
| 57 longhands = property["longhands"].split(';') |
| 58 property["camel_case_longhands"] = list() |
| 59 for longhand in longhands: |
| 60 longhand = self._camelcase_property_name(longhand) |
| 61 longhand = self._create_css_property_name_enum_value(longhand) |
| 62 property["camel_case_longhands"].append(longhand) |
| 63 self._longhand_dictionary[longhand].append(property) |
| 64 self._properties = dict((property["property_id"], property) for property
in self._properties) |
| 65 |
| 66 # FIXME: some of these might be better in a utils file |
| 67 def _camelcase_property_name(self, property_name): |
| 68 return re.sub(r'(^[^-])|-(.)', lambda match: (match.group(1) or match.gr
oup(2)).upper(), property_name) |
| 69 |
| 70 def _create_css_property_name_enum_value(self, property_name): |
| 71 return "CSSProperty" + property_name |
| 72 |
| 73 @template_expander.use_jinja("StylePropertyShorthand.cpp.tmpl") |
| 74 def generate_style_property_shorthand_cpp(self): |
| 75 return { |
| 76 "properties": self._properties, |
| 77 "longhands_dictionary": self._longhand_dictionary, |
| 78 } |
| 79 |
| 80 @template_expander.use_jinja("StylePropertyShorthand.h.tmpl") |
| 81 def generate_style_property_shorthand_h(self): |
| 82 return { |
| 83 "properties": self._properties, |
| 84 } |
| 85 |
| 86 if __name__ == "__main__": |
| 87 in_generator.Maker(StylePropertyShorthandWriter).main(sys.argv) |
OLD | NEW |