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

Side by Side Diff: tools/dom/templates/html/impl/impl_CSSStyleDeclaration.darttemplate

Issue 21182002: Allow "bulk editing" of the CssStyleDeclaration objects in an ElementList as well (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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
OLDNEW
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)Mixin $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 }
16 }
15 17
18 /**
19 * A collection of [CssStyleDeclaration]s that are associated with an
20 * [ElementList].
21 *
22 * Grouping the style objects all together provides easy editing of specific
23 * properties of a collection of elements. Setting a specific property value
24 * will set that property in all [Element]s in the [ElementList]. Getting a
25 * specific property value will return the value of the property of the first
26 * element in the [ElementList].
27 */
28 class $(CLASSNAME)Set $EXTENDS with $(CLASSNAME)Mixin {
blois 2013/07/30 00:45:18 I don't think that this one should extend Intercep
29 final Iterable<Element> _elementIterable;
30 Iterable<$(CLASSNAME)> _elementCssStyleDeclarationSetIterable;
31
32 $(CLASSNAME)Set._(this._elementIterable) {
33 _elementCssStyleDeclarationSetIterable = new List.from(
34 _elementIterable).map((e) => e.style);
35 }
36
37 String getPropertyValue(String propertyName) =>
38 _elementCssStyleDeclarationSetIterable.first.getPropertyValue(
39 propertyName);
40
41 void setProperty(String propertyName, String value, [String priority]) {
42 _elementCssStyleDeclarationSetIterable.forEach((e) =>
43 e.setProperty(propertyName, value, priority));
44 }
45 // Important note: CssStyleDeclarationSet does NOT implement every method
46 // available in CssStyleDeclaration. Some of the methods don't make so much
47 // sense in terms of having a resonable value to return when you're
48 // considering a list of Elements. You will need to manually add any of the
49 // items in the MEMBERS set if you want that functionality.
50 }
51
52 abstract class $(CLASSNAME)Mixin {
16 $!MEMBERS 53 $!MEMBERS
17
18 String getPropertyValue(String propertyName) { 54 String getPropertyValue(String propertyName) {
blois 2013/07/30 00:45:18 This should probably be on the single element one,
19 var propValue = _getPropertyValue(propertyName); 55 var propValue = _getPropertyValue(propertyName);
20 return propValue != null ? propValue : ''; 56 return propValue != null ? propValue : '';
21 } 57 }
22 58
23 $if DART2JS 59 $if DART2JS
24 @DomName('CSSStyleDeclaration.setProperty') 60 @DomName('CSSStyleDeclaration.setProperty')
25 void setProperty(String propertyName, String value, [String priority]) { 61 void setProperty(String propertyName, String value, [String priority]) {
26 // try/catch for IE9 which throws on unsupported values. 62 // try/catch for IE9 which throws on unsupported values.
27 try { 63 try {
28 if (priority == null) { 64 if (priority == null) {
29 priority = ''; 65 priority = '';
30 } 66 }
31 JS('void', '#.setProperty(#, #, #)', this, propertyName, value, priority); 67 JS('void', '#.setProperty(#, #, #)', this, propertyName, value, priority);
32 // Bug #2772, IE9 requires a poke to actually apply the value. 68 // Bug #2772, IE9 requires a poke to actually apply the value.
33 if (JS('bool', '!!#.setAttribute', this)) { 69 if (JS('bool', '!!#.setAttribute', this)) {
34 JS('void', '#.setAttribute(#, #)', this, propertyName, value); 70 JS('void', '#.setAttribute(#, #)', this, propertyName, value);
35 } 71 }
36 } catch (e) {} 72 } catch (e) {}
37 } 73 }
38 74
39 /** 75 /**
40 * Checks to see if CSS Transitions are supported. 76 * Checks to see if CSS Transitions are supported.
41 */ 77 */
42 static bool get supportsTransitions { 78 static bool get supportsTransitions {
blois 2013/07/30 00:45:18 Since its a static, should be on the CssStyleDecla
43 if (JS('bool', '"transition" in document.body.style')) { 79 if (JS('bool', '"transition" in document.body.style')) {
44 return true; 80 return true;
45 } 81 }
46 var propertyName = '${Device.propertyPrefix}Transition'; 82 var propertyName = '${Device.propertyPrefix}Transition';
47 return JS('bool', '# in document.body.style', propertyName); 83 return JS('bool', '# in document.body.style', propertyName);
48 } 84 }
49 $else 85 $else
50 /** 86 /**
51 * Checks to see if CSS Transitions are supported. 87 * Checks to see if CSS Transitions are supported.
52 */ 88 */
(...skipping 3165 matching lines...) Expand 10 before | Expand all | Expand 10 after
3218 3254
3219 /** Gets the value of "zoom" */ 3255 /** Gets the value of "zoom" */
3220 String get zoom => 3256 String get zoom =>
3221 getPropertyValue('zoom'); 3257 getPropertyValue('zoom');
3222 3258
3223 /** Sets the value of "zoom" */ 3259 /** Sets the value of "zoom" */
3224 void set zoom(String value) { 3260 void set zoom(String value) {
3225 setProperty('zoom', value, ''); 3261 setProperty('zoom', value, '');
3226 } 3262 }
3227 } 3263 }
OLDNEW
« no previous file with comments | « tests/html/cssstyledeclaration_test.dart ('k') | tools/dom/templates/html/impl/impl_Element.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698