| 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 |
| 105 $(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME $EXTENDS with | 106 $(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME $EXTENDS with |
| 106 $(CLASSNAME)Base $IMPLEMENTS { | 107 $(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 |
| 107 factory $CLASSNAME() => new CssStyleDeclaration.css(''); | 117 factory $CLASSNAME() => new CssStyleDeclaration.css(''); |
| 108 | 118 |
| 109 factory $CLASSNAME.css(String css) { | 119 factory $CLASSNAME.css(String css) { |
| 110 final style = new Element.tag('div').style; | 120 final style = new Element.tag('div').style; |
| 111 style.cssText = css; | 121 style.cssText = css; |
| 112 return style; | 122 return style; |
| 113 } | 123 } |
| 114 | 124 |
| 115 String getPropertyValue(String propertyName) { | 125 String getPropertyValue(String propertyName) { |
| 116 var propValue = _getPropertyValueHelper(propertyName); | 126 var propValue = _getPropertyValueHelper(propertyName); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 $if DART2JS | 245 $if DART2JS |
| 236 """) | 246 """) |
| 237 | 247 |
| 238 for camelName in sorted(universal_properties): | 248 for camelName in sorted(universal_properties): |
| 239 property = dashifyName(camelName) | 249 property = dashifyName(camelName) |
| 240 class_file.write(""" | 250 class_file.write(""" |
| 241 /** Gets the value of "%s" */ | 251 /** Gets the value of "%s" */ |
| 242 String get %s => this._%s; | 252 String get %s => this._%s; |
| 243 | 253 |
| 244 /** Sets the value of "%s" */ | 254 /** Sets the value of "%s" */ |
| 245 set %s(String value) { | 255 void set %s(String value) { |
| 246 _%s = value == null ? '' : value; | 256 _%s = value == null ? '' : value; |
| 247 } | 257 } |
| 248 @Returns('String') | 258 @Returns('String') |
| 249 @JSName('%s') | 259 @JSName('%s') |
| 250 String _%s; | 260 String _%s; |
| 251 """ % (property, camelName, camelName, | 261 """ % (property, camelName, camelName, |
| 252 property, camelName, camelName, | 262 property, camelName, camelName, |
| 253 camelName, camelName)) | 263 camelName, camelName)) |
| 254 | 264 |
| 255 class_file.write(""" | 265 class_file.write(""" |
| 256 $endif | 266 $endif |
| 257 } | 267 } |
| 258 | 268 |
| 269 $if DART2JS |
| 259 class _CssStyleDeclarationSet extends Object with CssStyleDeclarationBase { | 270 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 |
| 260 final Iterable<Element> _elementIterable; | 278 final Iterable<Element> _elementIterable; |
| 261 Iterable<CssStyleDeclaration> _elementCssStyleDeclarationSetIterable; | 279 Iterable<CssStyleDeclaration> _elementCssStyleDeclarationSetIterable; |
| 262 | 280 |
| 263 _CssStyleDeclarationSet(this._elementIterable) { | 281 _CssStyleDeclarationSet(this._elementIterable) { |
| 264 _elementCssStyleDeclarationSetIterable = new List.from( | 282 _elementCssStyleDeclarationSetIterable = new List.from( |
| 265 _elementIterable).map((e) => e.style); | 283 _elementIterable).map((e) => e.style); |
| 266 } | 284 } |
| 267 | 285 |
| 268 String getPropertyValue(String propertyName) => | 286 String getPropertyValue(String propertyName) => |
| 269 _elementCssStyleDeclarationSetIterable.first.getPropertyValue( | 287 _elementCssStyleDeclarationSetIterable.first.getPropertyValue( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 284 JS('void', '#.style[#] = #', element, propertyName, value); | 302 JS('void', '#.style[#] = #', element, propertyName, value); |
| 285 } | 303 } |
| 286 } | 304 } |
| 287 """) | 305 """) |
| 288 | 306 |
| 289 | 307 |
| 290 for camelName in sorted(universal_properties): | 308 for camelName in sorted(universal_properties): |
| 291 property = dashifyName(camelName) | 309 property = dashifyName(camelName) |
| 292 class_file.write(""" | 310 class_file.write(""" |
| 293 /** Sets the value of "%s" */ | 311 /** Sets the value of "%s" */ |
| 294 set %s(String value) { | 312 void set %s(String value) { |
| 295 _setAll('%s', value); | 313 _setAll('%s', value); |
| 296 } | 314 } |
| 297 """ % (property, camelName, camelName)) | 315 """ % (property, camelName, camelName)) |
| 298 | 316 |
| 299 class_file.write(""" | 317 class_file.write(""" |
| 300 $endif | 318 $endif |
| 301 | 319 |
| 302 // Important note: CssStyleDeclarationSet does NOT implement every method | 320 // Important note: CssStyleDeclarationSet does NOT implement every method |
| 303 // available in CssStyleDeclaration. Some of the methods don't make so much | 321 // available in CssStyleDeclaration. Some of the methods don't make so much |
| 304 // sense in terms of having a resonable value to return when you're | 322 // 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... |
| 346 class_lines.append(""" | 364 class_lines.append(""" |
| 347 String get %s => | 365 String get %s => |
| 348 getPropertyValue('%s'); | 366 getPropertyValue('%s'); |
| 349 | 367 |
| 350 """ % (camel_case_name, css_name)) | 368 """ % (camel_case_name, css_name)) |
| 351 | 369 |
| 352 class_lines.append(comment % 'Sets') | 370 class_lines.append(comment % 'Sets') |
| 353 if base_css_name in annotated: | 371 if base_css_name in annotated: |
| 354 class_lines.append(annotated[base_css_name]) | 372 class_lines.append(annotated[base_css_name]) |
| 355 class_lines.append(""" | 373 class_lines.append(""" |
| 356 set %s(String value) { | 374 void set %s(String value) { |
| 357 setProperty('%s', value, ''); | 375 setProperty('%s', value, ''); |
| 358 } | 376 } |
| 359 """ % (camel_case_name, css_name)) | 377 """ % (camel_case_name, css_name)) |
| 360 | 378 |
| 361 class_file.write(''.join(class_lines)); | 379 class_file.write(''.join(class_lines)); |
| 362 class_file.write('}\n') | 380 class_file.write('}\n') |
| 363 class_file.close() | 381 class_file.close() |
| OLD | NEW |