Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(989)

Side by Side Diff: core/scripts/make_style_shorthands.py

Issue 23014006: Roll IDL to multivm@1350 (Closed) Base URL: https://dart.googlecode.com/svn/third_party/WebCore
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « core/scripts/make_style_builder.py ('k') | core/svg/SVGDescElement.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 22 matching lines...) Expand all
33 33
34 import in_generator 34 import in_generator
35 import template_expander 35 import template_expander
36 36
37 37
38 class StylePropertyShorthandWriter(in_generator.Writer): 38 class StylePropertyShorthandWriter(in_generator.Writer):
39 class_name = 'StylePropertyShorthand' 39 class_name = 'StylePropertyShorthand'
40 40
41 defaults = { 41 defaults = {
42 'longhands': "", 42 'longhands': "",
43 'runtimeEnabledShorthand': None,
43 } 44 }
44 45
45 def __init__(self, in_files, enabled_conditions): 46 def __init__(self, in_files, enabled_conditions):
46 super(StylePropertyShorthandWriter, self).__init__(in_files, enabled_con ditions) 47 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 self._outputs = {("StylePropertyShorthand.cpp"): self.generate_style_pro perty_shorthand_cpp, ("StylePropertyShorthand.h"): self.generate_style_property_ shorthand_h}
48 49
49 self._properties = self.in_file.name_dictionaries 50 self._properties = self.in_file.name_dictionaries
50 self._longhand_dictionary = defaultdict(list) 51 self._longhand_dictionary = defaultdict(list)
51 52
52 for property in self._properties: 53 for property in self._properties:
53 cc = self._camelcase_property_name(property["name"]) 54 cc = self._camelcase_property_name(property["name"])
54 property["property_id"] = self._create_css_property_name_enum_value( cc) 55 property["property_id"] = self._create_css_property_name_enum_value( cc)
55 cc = cc[0].lower() + cc[1:] 56 cc = cc[0].lower() + cc[1:]
56 property["camel_case_name"] = cc 57 property["camel_case_name"] = cc
57 longhands = property["longhands"].split(';') 58 longhands = property["longhands"].split(';')
58 property["camel_case_longhands"] = list() 59 property["camel_case_longhands"] = list()
59 for longhand in longhands: 60 for longhand in longhands:
60 longhand = self._camelcase_property_name(longhand) 61 longhand = self._camelcase_property_name(longhand)
61 longhand = self._create_css_property_name_enum_value(longhand) 62 longhand = self._create_css_property_name_enum_value(longhand)
62 property["camel_case_longhands"].append(longhand) 63 property["camel_case_longhands"].append(longhand)
63 self._longhand_dictionary[longhand].append(property) 64 self._longhand_dictionary[longhand].append(property)
65 if property["runtimeEnabledShorthand"] is not None:
66 lowerFirstConditional = self._lower_first(property["runtimeEnabl edShorthand"])
67 property["runtime_conditional_getter"] = "%sEnabled" % lowerFirs tConditional
64 self._properties = dict((property["property_id"], property) for property in self._properties) 68 self._properties = dict((property["property_id"], property) for property in self._properties)
65 69
66 # FIXME: some of these might be better in a utils file 70 # FIXME: some of these might be better in a utils file
67 def _camelcase_property_name(self, property_name): 71 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) 72 return re.sub(r'(^[^-])|-(.)', lambda match: (match.group(1) or match.gr oup(2)).upper(), property_name)
69 73
70 def _create_css_property_name_enum_value(self, property_name): 74 def _create_css_property_name_enum_value(self, property_name):
71 return "CSSProperty" + property_name 75 return "CSSProperty" + property_name
72 76
77 def _lower_first(self, string):
78 lowered = string[0].lower() + string[1:]
79 lowered = lowered.replace("cSS", "css")
80 return lowered
81
73 @template_expander.use_jinja("StylePropertyShorthand.cpp.tmpl") 82 @template_expander.use_jinja("StylePropertyShorthand.cpp.tmpl")
74 def generate_style_property_shorthand_cpp(self): 83 def generate_style_property_shorthand_cpp(self):
75 return { 84 return {
76 "properties": self._properties, 85 "properties": self._properties,
77 "longhands_dictionary": self._longhand_dictionary, 86 "longhands_dictionary": self._longhand_dictionary,
78 } 87 }
79 88
80 @template_expander.use_jinja("StylePropertyShorthand.h.tmpl") 89 @template_expander.use_jinja("StylePropertyShorthand.h.tmpl")
81 def generate_style_property_shorthand_h(self): 90 def generate_style_property_shorthand_h(self):
82 return { 91 return {
83 "properties": self._properties, 92 "properties": self._properties,
84 } 93 }
85 94
86 if __name__ == "__main__": 95 if __name__ == "__main__":
87 in_generator.Maker(StylePropertyShorthandWriter).main(sys.argv) 96 in_generator.Maker(StylePropertyShorthandWriter).main(sys.argv)
OLDNEW
« no previous file with comments | « core/scripts/make_style_builder.py ('k') | core/svg/SVGDescElement.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698