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

Side by Side Diff: client/html/scripts/css_code_generator.py

Issue 9845043: Rename client/{dom,html} to lib/{dom,html} . (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 9 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 | « client/html/html_frog.dart ('k') | client/html/src/AnimationEvent.dart » ('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/python2.6
2 #
3 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
4 # for details. All rights reserved. Use of this source code is governed by a
5 # BSD-style license that can be found in the LICENSE file.
6
7 """Generates CSSStyleDeclaration from css property definitions defined in WebKit ."""
8
9 import tempfile, os
10
11 COMMENT_LINE_PREFIX = ' * '
12 SOURCE_PATH = 'Source/WebCore/css/CSSPropertyNames.in'
13 INPUT_URL = 'http://trac.webkit.org/export/latest/trunk/%s' % SOURCE_PATH
14 INTERFACE_FILE = '../../html/src/CSSStyleDeclaration.dart'
15 CLASS_FILE = '../../html/src/CSSStyleDeclarationWrappingImplementation.dart'
16
17 def main():
18 _, css_names_file = tempfile.mkstemp('.CSSPropertyNames.in')
19 try:
20 if os.system('wget %s -O %s' % (INPUT_URL, css_names_file)):
21 return 1
22 generate_code(css_names_file)
23 print 'Successfully generated %s and %s' % (INTERFACE_FILE, CLASS_FILE)
24 finally:
25 os.remove(css_names_file)
26
27 def camelCaseName(name):
28 """Convert a CSS property name to a lowerCamelCase name."""
29 name = name.replace('-webkit-', '')
30 words = []
31 for word in name.split('-'):
32 if words:
33 words.append(word.title())
34 else:
35 words.append(word)
36 return ''.join(words)
37
38 def generate_code(input_path):
39 data = open(input_path).readlines()
40
41 # filter CSSPropertyNames.in to only the properties
42 data = [d[:-1] for d in data
43 if len(d) > 1
44 and not d.startswith('#')
45 and not d.startswith('//')
46 and not '=' in d]
47
48 interface_file = open(INTERFACE_FILE, 'w')
49 class_file = open(CLASS_FILE, 'w')
50
51 interface_file.write("""
52 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
53 // for details. All rights reserved. Use of this source code is governed by a
54 // BSD-style license that can be found in the LICENSE file.
55
56 // WARNING: Do not edit.
57 // This file was generated by html/scripts/css_code_generator.py
58
59 // Source of CSS properties:
60 // %s
61
62 // TODO(jacobr): add versions that take numeric values in px, miliseconds, etc.
63
64 interface CSSStyleDeclaration {
65
66 String get cssText();
67
68 void set cssText(String value);
69
70 int get length();
71
72 CSSRule get parentRule();
73
74 CSSValue getPropertyCSSValue(String propertyName);
75
76 String getPropertyPriority(String propertyName);
77
78 String getPropertyShorthand(String propertyName);
79
80 String getPropertyValue(String propertyName);
81
82 bool isPropertyImplicit(String propertyName);
83
84 String item(int index);
85
86 String removeProperty(String propertyName);
87
88 void setProperty(String propertyName, String value, [String priority]);
89
90 """.lstrip() % SOURCE_PATH)
91
92
93 class_file.write("""
94 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
95 // for details. All rights reserved. Use of this source code is governed by a
96 // BSD-style license that can be found in the LICENSE file.
97
98 // WARNING: Do not edit.
99 // This file was generated by html/scripts/css_code_generator.py
100
101 // Source of CSS properties:
102 // %s
103
104 // TODO(jacobr): add versions that take numeric values in px, miliseconds, etc.
105
106 class CSSStyleDeclarationWrappingImplementation extends DOMWrapperBase implement s CSSStyleDeclaration {
107 static String _cachedBrowserPrefix;
108
109 CSSStyleDeclarationWrappingImplementation._wrap(ptr) : super._wrap(ptr) {}
110
111 static String get _browserPrefix() {
112 if (_cachedBrowserPrefix === null) {
113 if (_Device.isFirefox) {
114 _cachedBrowserPrefix = '-moz-';
115 } else {
116 _cachedBrowserPrefix = '-webkit-';
117 }
118 // TODO(jacobr): support IE 9.0 and Opera as well.
119 }
120 return _cachedBrowserPrefix;
121 }
122
123 String get cssText() { return _ptr.cssText; }
124
125 void set cssText(String value) { _ptr.cssText = value; }
126
127 int get length() { return _ptr.length; }
128
129 CSSRule get parentRule() { return LevelDom.wrapCSSRule(_ptr.parentRule); }
130
131 CSSValue getPropertyCSSValue(String propertyName) {
132 return LevelDom.wrapCSSValue(_ptr.getPropertyCSSValue(propertyName));
133 }
134
135 String getPropertyPriority(String propertyName) {
136 return _ptr.getPropertyPriority(propertyName);
137 }
138
139 String getPropertyShorthand(String propertyName) {
140 return _ptr.getPropertyShorthand(propertyName);
141 }
142
143 String getPropertyValue(String propertyName) {
144 return _ptr.getPropertyValue(propertyName);
145 }
146
147 bool isPropertyImplicit(String propertyName) {
148 return _ptr.isPropertyImplicit(propertyName);
149 }
150
151 String item(int index) {
152 return _ptr.item(index);
153 }
154
155 String removeProperty(String propertyName) {
156 return _ptr.removeProperty(propertyName);
157 }
158
159 void setProperty(String propertyName, String value, [String priority = '']) {
160 _ptr.setProperty(propertyName, value, priority);
161 }
162
163 String get typeName() { return "CSSStyleDeclaration"; }
164
165 """.lstrip() % SOURCE_PATH)
166
167 interface_lines = [];
168 class_lines = [];
169
170 seen = set()
171 for prop in sorted(data, key=lambda p: camelCaseName(p)):
172 camel_case_name = camelCaseName(prop)
173 upper_camel_case_name = camel_case_name[0].upper() + camel_case_name[1:];
174 css_name = prop.replace('-webkit-', '${_browserPrefix}')
175 base_css_name = prop.replace('-webkit-', '')
176
177 if base_css_name in seen:
178 continue
179 seen.add(base_css_name)
180
181 comment = ' /** %s the value of "' + base_css_name + '" */'
182
183 interface_lines.append(comment % 'Gets')
184 interface_lines.append("""
185 String get %s();
186
187 """ % camel_case_name)
188
189 interface_lines.append(comment % 'Sets')
190 interface_lines.append("""
191 void set %s(String value);
192
193 """ % camel_case_name)
194
195 class_lines.append('\n');
196 class_lines.append(comment % 'Gets')
197 class_lines.append("""
198 String get %s() =>
199 getPropertyValue('%s');
200
201 """ % (camel_case_name, css_name))
202
203 class_lines.append(comment % 'Sets')
204 class_lines.append("""
205 void set %s(String value) {
206 setProperty('%s', value, '');
207 }
208 """ % (camel_case_name, css_name))
209
210 interface_file.write(''.join(interface_lines));
211 interface_file.write('}\n')
212 interface_file.close()
213
214 class_file.write(''.join(class_lines));
215 class_file.write('}\n')
216 class_file.close()
217
218 if __name__ == '__main__':
219 main()
OLDNEW
« no previous file with comments | « client/html/html_frog.dart ('k') | client/html/src/AnimationEvent.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698