OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # | 2 # |
3 # Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 3 # Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
4 # for details. All rights reserved. Use of this source code is governed by a | 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. | 5 # BSD-style license that can be found in the LICENSE file. |
6 | 6 |
7 """Generates CSSStyleDeclaration template file from css property definitions | 7 """Generates CSSStyleDeclaration template file from css property definitions |
8 defined in WebKit.""" | 8 defined in WebKit.""" |
9 | 9 |
10 import tempfile, os, re | 10 import tempfile, os, re |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 // The template file was generated by scripts/css_code_generator.py | 95 // The template file was generated by scripts/css_code_generator.py |
96 | 96 |
97 // Source of CSS properties: | 97 // Source of CSS properties: |
98 // %s | 98 // %s |
99 | 99 |
100 part of $LIBRARYNAME; | 100 part of $LIBRARYNAME; |
101 """ % SOURCE_PATH) | 101 """ % SOURCE_PATH) |
102 | 102 |
103 | 103 |
104 class_file.write(""" | 104 class_file.write(""" |
105 $if DART2JS | |
106 $(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME $EXTENDS with | 105 $(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME $EXTENDS with |
107 $(CLASSNAME)Base $IMPLEMENTS { | 106 $(CLASSNAME)Base $IMPLEMENTS { |
108 $else | |
109 $if JSINTEROP | |
110 $(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS) class $CLASSNAME extends | |
111 $(CLASSNAME)Base $IMPLEMENTS { | |
112 $else | |
113 $(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME $EXTENDS with | |
114 $(CLASSNAME)Base $IMPLEMENTS { | |
115 $endif | |
116 $endif | |
117 factory $CLASSNAME() => new CssStyleDeclaration.css(''); | 107 factory $CLASSNAME() => new CssStyleDeclaration.css(''); |
118 | 108 |
119 factory $CLASSNAME.css(String css) { | 109 factory $CLASSNAME.css(String css) { |
120 final style = new Element.tag('div').style; | 110 final style = new Element.tag('div').style; |
121 style.cssText = css; | 111 style.cssText = css; |
122 return style; | 112 return style; |
123 } | 113 } |
124 | 114 |
125 String getPropertyValue(String propertyName) { | 115 String getPropertyValue(String propertyName) { |
126 var propValue = _getPropertyValueHelper(propertyName); | 116 var propValue = _getPropertyValueHelper(propertyName); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 $if DART2JS | 235 $if DART2JS |
246 """) | 236 """) |
247 | 237 |
248 for camelName in sorted(universal_properties): | 238 for camelName in sorted(universal_properties): |
249 property = dashifyName(camelName) | 239 property = dashifyName(camelName) |
250 class_file.write(""" | 240 class_file.write(""" |
251 /** Gets the value of "%s" */ | 241 /** Gets the value of "%s" */ |
252 String get %s => this._%s; | 242 String get %s => this._%s; |
253 | 243 |
254 /** Sets the value of "%s" */ | 244 /** Sets the value of "%s" */ |
255 void set %s(String value) { | 245 set %s(String value) { |
256 _%s = value == null ? '' : value; | 246 _%s = value == null ? '' : value; |
257 } | 247 } |
258 @Returns('String') | 248 @Returns('String') |
259 @JSName('%s') | 249 @JSName('%s') |
260 String _%s; | 250 String _%s; |
261 """ % (property, camelName, camelName, | 251 """ % (property, camelName, camelName, |
262 property, camelName, camelName, | 252 property, camelName, camelName, |
263 camelName, camelName)) | 253 camelName, camelName)) |
264 | 254 |
265 class_file.write(""" | 255 class_file.write(""" |
266 $endif | 256 $endif |
267 } | 257 } |
268 | 258 |
269 $if DART2JS | |
270 class _CssStyleDeclarationSet extends Object with CssStyleDeclarationBase { | 259 class _CssStyleDeclarationSet extends Object with CssStyleDeclarationBase { |
271 $else | |
272 $if JSINTEROP | |
273 class _CssStyleDeclarationSet extends CssStyleDeclarationBase { | |
274 $else | |
275 class _CssStyleDeclarationSet extends Object with CssStyleDeclarationBase { | |
276 $endif | |
277 $endif | |
278 final Iterable<Element> _elementIterable; | 260 final Iterable<Element> _elementIterable; |
279 Iterable<CssStyleDeclaration> _elementCssStyleDeclarationSetIterable; | 261 Iterable<CssStyleDeclaration> _elementCssStyleDeclarationSetIterable; |
280 | 262 |
281 _CssStyleDeclarationSet(this._elementIterable) { | 263 _CssStyleDeclarationSet(this._elementIterable) { |
282 _elementCssStyleDeclarationSetIterable = new List.from( | 264 _elementCssStyleDeclarationSetIterable = new List.from( |
283 _elementIterable).map((e) => e.style); | 265 _elementIterable).map((e) => e.style); |
284 } | 266 } |
285 | 267 |
286 String getPropertyValue(String propertyName) => | 268 String getPropertyValue(String propertyName) => |
287 _elementCssStyleDeclarationSetIterable.first.getPropertyValue( | 269 _elementCssStyleDeclarationSetIterable.first.getPropertyValue( |
(...skipping 14 matching lines...) Expand all Loading... |
302 JS('void', '#.style[#] = #', element, propertyName, value); | 284 JS('void', '#.style[#] = #', element, propertyName, value); |
303 } | 285 } |
304 } | 286 } |
305 """) | 287 """) |
306 | 288 |
307 | 289 |
308 for camelName in sorted(universal_properties): | 290 for camelName in sorted(universal_properties): |
309 property = dashifyName(camelName) | 291 property = dashifyName(camelName) |
310 class_file.write(""" | 292 class_file.write(""" |
311 /** Sets the value of "%s" */ | 293 /** Sets the value of "%s" */ |
312 void set %s(String value) { | 294 set %s(String value) { |
313 _setAll('%s', value); | 295 _setAll('%s', value); |
314 } | 296 } |
315 """ % (property, camelName, camelName)) | 297 """ % (property, camelName, camelName)) |
316 | 298 |
317 class_file.write(""" | 299 class_file.write(""" |
318 $endif | 300 $endif |
319 | 301 |
320 // Important note: CssStyleDeclarationSet does NOT implement every method | 302 // Important note: CssStyleDeclarationSet does NOT implement every method |
321 // available in CssStyleDeclaration. Some of the methods don't make so much | 303 // available in CssStyleDeclaration. Some of the methods don't make so much |
322 // sense in terms of having a resonable value to return when you're | 304 // sense in terms of having a resonable value to return when you're |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 class_lines.append(""" | 346 class_lines.append(""" |
365 String get %s => | 347 String get %s => |
366 getPropertyValue('%s'); | 348 getPropertyValue('%s'); |
367 | 349 |
368 """ % (camel_case_name, css_name)) | 350 """ % (camel_case_name, css_name)) |
369 | 351 |
370 class_lines.append(comment % 'Sets') | 352 class_lines.append(comment % 'Sets') |
371 if base_css_name in annotated: | 353 if base_css_name in annotated: |
372 class_lines.append(annotated[base_css_name]) | 354 class_lines.append(annotated[base_css_name]) |
373 class_lines.append(""" | 355 class_lines.append(""" |
374 void set %s(String value) { | 356 set %s(String value) { |
375 setProperty('%s', value, ''); | 357 setProperty('%s', value, ''); |
376 } | 358 } |
377 """ % (camel_case_name, css_name)) | 359 """ % (camel_case_name, css_name)) |
378 | 360 |
379 class_file.write(''.join(class_lines)); | 361 class_file.write(''.join(class_lines)); |
380 class_file.write('}\n') | 362 class_file.write('}\n') |
381 class_file.close() | 363 class_file.close() |
OLD | NEW |