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

Side by Side Diff: client/html/src/CssClassSet.dart

Issue 9148015: Example showing alternate async measurement solution (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Ready for review Created 8 years, 11 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) 2011, 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 // TODO - figure out whether classList exists, and if so use that 5 // TODO - figure out whether classList exists, and if so use that
6 // rather than the className property that is being used here. 6 // rather than the className property that is being used here.
7 7
8 class _CssClassSet implements Set<String> { 8 class _CssClassSet implements Set<String> {
9 9
10 final _element; 10 final _element;
11 11
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 /** 94 /**
95 * Helper method used to modify the set of css classes on this element. 95 * Helper method used to modify the set of css classes on this element.
96 * 96 *
97 * f - callback with: 97 * f - callback with:
98 * s - a Set of all the css class name currently on this element. 98 * s - a Set of all the css class name currently on this element.
99 * 99 *
100 * After f returns, the modified set is written to the 100 * After f returns, the modified set is written to the
101 * className property of this element. 101 * className property of this element.
102 */ 102 */
103 void _modify( f(Set<String> s)) { 103 void _modify( f(Set<String> s)) {
104 assert(!_inMeasurementFrame || !_nodeInDocument(_element));
104 Set<String> s = _read(); 105 Set<String> s = _read();
105 f(s); 106 f(s);
106 _write(s); 107 _write(s);
107 } 108 }
108 109
109 /** 110 /**
110 * Read the class names from the HTMLElement class property, 111 * Read the class names from the HTMLElement class property,
111 * and put them into a set (duplicates are discarded). 112 * and put them into a set (duplicates are discarded).
112 */ 113 */
113 Set<String> _read() { 114 Set<String> _read() {
114 // TODO(mattsh) simplify this once split can take regex. 115 // TODO(mattsh) simplify this once split can take regex.
115 Set<String> s = new Set<String>(); 116 Set<String> s = new Set<String>();
116 for (String name in _element.className.split(' ')) { 117 for (String name in _element.className.split(' ')) {
117 String trimmed = name.trim(); 118 String trimmed = name.trim();
118 if (!trimmed.isEmpty()) { 119 if (!trimmed.isEmpty()) {
119 s.add(trimmed); 120 s.add(trimmed);
120 } 121 }
121 } 122 }
122 return s; 123 return s;
123 } 124 }
124 125
125 /** 126 /**
126 * Join all the elements of a set into one string and write 127 * Join all the elements of a set into one string and write
127 * back to the element. 128 * back to the element.
128 */ 129 */
129 void _write(Set s) { 130 void _write(Set s) {
131 assert(!_inMeasurementFrame || !_nodeInDocument(_element));
130 _element.className = _formatSet(s); 132 _element.className = _formatSet(s);
131 } 133 }
132 134
133 String _formatSet(Set<String> s) { 135 String _formatSet(Set<String> s) {
134 // TODO(mattsh) should be able to pass Set to String.joins http:/b/5398605 136 // TODO(mattsh) should be able to pass Set to String.joins http:/b/5398605
135 List list = new List.from(s); 137 List list = new List.from(s);
136 return Strings.join(list, ' '); 138 return Strings.join(list, ' ');
137 } 139 }
138 140
139 } 141 }
140 142
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698