| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of $LIBRARYNAME; | 5 part of $LIBRARYNAME; |
| 6 | 6 |
| 7 $(ANNOTATIONS)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { | 7 $(ANNOTATIONS)$(CLASS_MODIFIERS) class $CLASSNAME $EXTENDS with |
| 8 $(CLASSNAME)Base $IMPLEMENTS$NATIVESPEC { |
| 8 factory $CLASSNAME() => new CssStyleDeclaration.css(''); | 9 factory $CLASSNAME() => new CssStyleDeclaration.css(''); |
| 9 | 10 |
| 10 factory $CLASSNAME.css(String css) { | 11 factory $CLASSNAME.css(String css) { |
| 11 final style = new Element.tag('div').style; | 12 final style = new Element.tag('div').style; |
| 12 style.cssText = css; | 13 style.cssText = css; |
| 13 return style; | 14 return style; |
| 14 } | 15 } |
| 15 | 16 |
| 16 $!MEMBERS | |
| 17 | |
| 18 String getPropertyValue(String propertyName) { | 17 String getPropertyValue(String propertyName) { |
| 19 var propValue = _getPropertyValue(propertyName); | 18 var propValue = _getPropertyValue(propertyName); |
| 20 return propValue != null ? propValue : ''; | 19 return propValue != null ? propValue : ''; |
| 21 } | 20 } |
| 22 | 21 |
| 23 $if DART2JS | 22 $if DART2JS |
| 24 @DomName('CSSStyleDeclaration.setProperty') | 23 @DomName('CSSStyleDeclaration.setProperty') |
| 25 void setProperty(String propertyName, String value, [String priority]) { | 24 void setProperty(String propertyName, String value, [String priority]) { |
| 26 // try/catch for IE9 which throws on unsupported values. | 25 // try/catch for IE9 which throws on unsupported values. |
| 27 try { | 26 try { |
| 28 if (priority == null) { | 27 if (priority == null) { |
| 29 priority = ''; | 28 priority = ''; |
| 30 } | 29 } |
| 31 JS('void', '#.setProperty(#, #, #)', this, propertyName, value, priority); | 30 JS('void', '#.setProperty(#, #, #)', this, propertyName, value, priority); |
| 32 // Bug #2772, IE9 requires a poke to actually apply the value. | 31 // Bug #2772, IE9 requires a poke to actually apply the value. |
| 33 if (JS('bool', '!!#.setAttribute', this)) { | 32 if (JS('bool', '!!#.setAttribute', this)) { |
| 34 JS('void', '#.setAttribute(#, #)', this, propertyName, value); | 33 JS('void', '#.setAttribute(#, #)', this, propertyName, value); |
| 35 } | 34 } |
| 36 } catch (e) {} | 35 } catch (e) {} |
| 37 } | 36 } |
| 38 | 37 |
| 39 /** | 38 /** |
| 40 * Checks to see if CSS Transitions are supported. | 39 * Checks to see if CSS Transitions are supported. |
| 41 */ | 40 */ |
| 42 static bool get supportsTransitions { | 41 static bool get supportsTransitions { |
| 43 if (JS('bool', '"transition" in document.body.style')) { | 42 if (JS('bool', '"transition" in document.body.style')) { |
| 44 return true; | 43 return true; |
| 45 } | 44 } |
| 46 var propertyName = '${Device.propertyPrefix}Transition'; | 45 var propertyName = '${Device.propertyPrefix}Transition'; |
| 47 return JS('bool', '# in document.body.style', propertyName); | 46 return JS('bool', '# in document.body.style', propertyName); |
| 48 } | 47 } |
| 49 $else | 48 $else |
| 50 /** | |
| 51 * Checks to see if CSS Transitions are supported. | |
| 52 */ | |
| 53 static bool get supportsTransitions => true; | |
| 54 | |
| 55 @DomName('CSSStyleDeclaration.setProperty') | 49 @DomName('CSSStyleDeclaration.setProperty') |
| 56 void setProperty(String propertyName, String value, [String priority]) { | 50 void setProperty(String propertyName, String value, [String priority]) { |
| 57 if (priority == null) { | 51 if (priority == null) { |
| 58 priority = ''; | 52 priority = ''; |
| 59 } | 53 } |
| 60 _setProperty(propertyName, value, priority); | 54 _setProperty(propertyName, value, priority); |
| 61 } | 55 } |
| 56 |
| 57 /** |
| 58 * Checks to see if CSS Transitions are supported. |
| 59 */ |
| 60 static bool get supportsTransitions => true; |
| 62 $endif | 61 $endif |
| 62 $!MEMBERS |
| 63 } |
| 64 |
| 65 class _CssStyleDeclarationSet extends Object with CssStyleDeclarationBase { |
| 66 final Iterable<Element> _elementIterable; |
| 67 Iterable<CssStyleDeclaration> _elementCssStyleDeclarationSetIterable; |
| 68 |
| 69 _CssStyleDeclarationSet(this._elementIterable) { |
| 70 _elementCssStyleDeclarationSetIterable = new List.from( |
| 71 _elementIterable).map((e) => e.style); |
| 72 } |
| 73 |
| 74 String getPropertyValue(String propertyName) => |
| 75 _elementCssStyleDeclarationSetIterable.first.getPropertyValue( |
| 76 propertyName); |
| 77 |
| 78 void setProperty(String propertyName, String value, [String priority]) { |
| 79 _elementCssStyleDeclarationSetIterable.forEach((e) => |
| 80 e.setProperty(propertyName, value, priority)); |
| 81 } |
| 82 // Important note: CssStyleDeclarationSet does NOT implement every method |
| 83 // available in CssStyleDeclaration. Some of the methods don't make so much |
| 84 // sense in terms of having a resonable value to return when you're |
| 85 // considering a list of Elements. You will need to manually add any of the |
| 86 // items in the MEMBERS set if you want that functionality. |
| 87 } |
| 88 |
| 89 abstract class CssStyleDeclarationBase { |
| 90 String getPropertyValue(String propertyName); |
| 91 void setProperty(String propertyName, String value, [String priority]); |
| 63 | 92 |
| 64 // TODO(jacobr): generate this list of properties using the existing script. | 93 // TODO(jacobr): generate this list of properties using the existing script. |
| 65 /** Gets the value of "align-content" */ | 94 /** Gets the value of "align-content" */ |
| 66 String get alignContent => | 95 String get alignContent => |
| 67 getPropertyValue('${Device.cssPrefix}align-content'); | 96 getPropertyValue('${Device.cssPrefix}align-content'); |
| 68 | 97 |
| 69 /** Sets the value of "align-content" */ | 98 /** Sets the value of "align-content" */ |
| 70 void set alignContent(String value) { | 99 void set alignContent(String value) { |
| 71 setProperty('${Device.cssPrefix}align-content', value, ''); | 100 setProperty('${Device.cssPrefix}align-content', value, ''); |
| 72 } | 101 } |
| (...skipping 3145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3218 | 3247 |
| 3219 /** Gets the value of "zoom" */ | 3248 /** Gets the value of "zoom" */ |
| 3220 String get zoom => | 3249 String get zoom => |
| 3221 getPropertyValue('zoom'); | 3250 getPropertyValue('zoom'); |
| 3222 | 3251 |
| 3223 /** Sets the value of "zoom" */ | 3252 /** Sets the value of "zoom" */ |
| 3224 void set zoom(String value) { | 3253 void set zoom(String value) { |
| 3225 setProperty('zoom', value, ''); | 3254 setProperty('zoom', value, ''); |
| 3226 } | 3255 } |
| 3227 } | 3256 } |
| OLD | NEW |