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

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

Issue 126143003: Update IDL to Chrome 32 (Closed) Base URL: https://dart.googlecode.com/svn/third_party/WebCore
Patch Set: Add new files Created 6 years, 11 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_runtime_features.py ('k') | core/scripts/make_style_shorthands.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright (C) 2013 Google Inc. 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
33 import in_generator
34 import template_expander
35
36
37 class StyleBuilderWriter(in_generator.Writer):
38 class_name = 'StyleBuilder'
39
40 valid_values = {
41 'svg': [True, False],
42 'custom_all': [True, False],
43 'custom_initial': [True, False],
44 'custom_inherit': [True, False],
45 'custom_value': [True, False],
46 }
47 defaults = {
48 'condition': None,
49 'name_for_methods': None,
50 'use_handlers_for': None,
51 'svg': False,
52 'converter': None,
53 # These depend on property name by default
54 'type_name': None,
55 'getter': None,
56 'setter': None,
57 'initial': None,
58 # Setting these stops default handlers being generated
59 # Setting custom_all is the same as setting the other three
60 'custom_all': False,
61 'custom_initial': False,
62 'custom_inherit': False,
63 'custom_value': False,
64 }
65
66 def __init__(self, in_files, enabled_conditions):
67 super(StyleBuilderWriter, self).__init__(in_files, enabled_conditions)
68 self._outputs = {("StyleBuilderFunctions.h"): self.generate_style_builde r_functions_h,
69 ("StyleBuilderFunctions.cpp"): self.generate_style_buil der_functions_cpp,
70 ("StyleBuilder.cpp"): self.generate_style_builder,
71 }
72
73 self._properties = self.in_file.name_dictionaries
74
75 def set_if_none(property, key, value):
76 if property[key] is None:
77 property[key] = value
78
79 for property in self._properties:
80 cc = self._camelcase_property_name(property["name"])
81 property["property_id"] = "CSSProperty" + cc
82 cc = property["name_for_methods"] or cc.replace("Webkit", "")
83 property["camel_case_name"] = cc
84 set_if_none(property, "type_name", "E" + cc)
85 set_if_none(property, "getter", self._lower_first(cc))
86 set_if_none(property, "setter", "set" + cc)
87 set_if_none(property, "initial", "initial" + cc)
88 if property["custom_all"]:
89 property["custom_initial"] = True
90 property["custom_inherit"] = True
91 property["custom_value"] = True
92
93 self._properties = dict((property["property_id"], property) for property in self._properties)
94
95 # FIXME: some of these might be better in a utils file
96 @staticmethod
97 def _camelcase_property_name(property_name):
98 return re.sub(r'(^[^-])|-(.)', lambda match: (match.group(1) or match.gr oup(2)).upper(), property_name)
99
100 @staticmethod
101 def _lower_first(s):
102 return s[0].lower() + s[1:]
103
104 @staticmethod
105 def _upper_first(s):
106 return s[0].upper() + s[1:]
107
108 @template_expander.use_jinja("StyleBuilderFunctions.h.tmpl")
109 def generate_style_builder_functions_h(self):
110 return {
111 "properties": self._properties,
112 }
113
114 @template_expander.use_jinja("StyleBuilderFunctions.cpp.tmpl")
115 def generate_style_builder_functions_cpp(self):
116 return {
117 "properties": self._properties,
118 }
119
120 @template_expander.use_jinja("StyleBuilder.cpp.tmpl")
121 def generate_style_builder(self):
122 return {
123 "properties": self._properties,
124 }
125
126
127 if __name__ == "__main__":
128 in_generator.Maker(StyleBuilderWriter).main(sys.argv)
OLDNEW
« no previous file with comments | « core/scripts/make_runtime_features.py ('k') | core/scripts/make_style_shorthands.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698