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

Side by Side Diff: sdk/lib/html/html_common/css_class_set.dart

Issue 1894713002: Strong html (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Ran formatter on NodeValidatorBuilder.dart instead of manually mucking with my bad formatting. Created 4 years, 8 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
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 html_common; 5 part of html_common;
6 6
7 abstract class CssClassSetImpl implements CssClassSet { 7 abstract class CssClassSetImpl implements CssClassSet {
8 8
9 static final RegExp _validTokenRE = new RegExp(r'^\S+$'); 9 static final RegExp _validTokenRE = new RegExp(r'^\S+$');
10 10
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 Iterator<String> get iterator => readClasses().iterator; 49 Iterator<String> get iterator => readClasses().iterator;
50 // interface Iterable - END 50 // interface Iterable - END
51 51
52 // interface Collection - BEGIN 52 // interface Collection - BEGIN
53 void forEach(void f(String element)) { 53 void forEach(void f(String element)) {
54 readClasses().forEach(f); 54 readClasses().forEach(f);
55 } 55 }
56 56
57 String join([String separator = ""]) => readClasses().join(separator); 57 String join([String separator = ""]) => readClasses().join(separator);
58 58
59 Iterable map(f(String element)) => readClasses().map(f); 59 Iterable/*<T>*/ map/*<T>*/(/*=T*/ f(String e)) =>
Alan Knight 2016/04/19 18:24:34 Where does T come from? Is it the <String> in CssC
Jacob 2016/04/19 21:50:45 This is the correct form for the now generic map m
Alan Knight 2016/04/19 22:04:08 I was thinking that because we get Iterable throug
60 readClasses().map/*<T>*/(f);
60 61
61 Iterable<String> where(bool f(String element)) => readClasses().where(f); 62 Iterable<String> where(bool f(String element)) => readClasses().where(f);
62 63
63 Iterable expand(Iterable f(String element)) => readClasses().expand(f); 64 Iterable/*<T>*/ expand/*<T>*/(Iterable/*<T>*/ f(String element)) =>
65 readClasses().expand/*<T>*/(f);
64 66
65 bool every(bool f(String element)) => readClasses().every(f); 67 bool every(bool f(String element)) => readClasses().every(f);
66 68
67 bool any(bool f(String element)) => readClasses().any(f); 69 bool any(bool f(String element)) => readClasses().any(f);
68 70
69 bool get isEmpty => readClasses().isEmpty; 71 bool get isEmpty => readClasses().isEmpty;
70 72
71 bool get isNotEmpty => readClasses().isNotEmpty; 73 bool get isNotEmpty => readClasses().isNotEmpty;
72 74
73 int get length => readClasses().length; 75 int get length => readClasses().length;
74 76
75 String reduce(String combine(String value, String element)) { 77 String reduce(String combine(String value, String element)) {
76 return readClasses().reduce(combine); 78 return readClasses().reduce(combine);
77 } 79 }
78 80
79 dynamic fold(dynamic initialValue, 81 dynamic/*=T*/ fold/*<T>*/(var/*=T*/ initialValue,
80 dynamic combine(dynamic previousValue, String element)) { 82 dynamic/*=T*/ combine(var/*=T*/ previousValue, String element)) {
81 return readClasses().fold(initialValue, combine); 83 return readClasses().fold/*<T>*/(initialValue, combine);
82 } 84 }
85
83 // interface Collection - END 86 // interface Collection - END
84 87
85 // interface Set - BEGIN 88 // interface Set - BEGIN
86 /** 89 /**
87 * Determine if this element contains the class [value]. 90 * Determine if this element contains the class [value].
88 * 91 *
89 * This is the Dart equivalent of jQuery's 92 * This is the Dart equivalent of jQuery's
90 * [hasClass](http://api.jquery.com/hasClass/). 93 * [hasClass](http://api.jquery.com/hasClass/).
91 */ 94 */
92 bool contains(Object value) { 95 bool contains(Object value) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 modify((s) => s.addAll(iterable.map(_validateToken))); 141 modify((s) => s.addAll(iterable.map(_validateToken)));
139 } 142 }
140 143
141 /** 144 /**
142 * Remove all classes specified in [iterable] from element. 145 * Remove all classes specified in [iterable] from element.
143 * 146 *
144 * This is the Dart equivalent of jQuery's 147 * This is the Dart equivalent of jQuery's
145 * [removeClass](http://api.jquery.com/removeClass/). 148 * [removeClass](http://api.jquery.com/removeClass/).
146 */ 149 */
147 void removeAll(Iterable<Object> iterable) { 150 void removeAll(Iterable<Object> iterable) {
148 modify((s) => s.removeAll(iterable.map(_validateToken))); 151 modify((s) => s.removeAll(iterable));
149 } 152 }
150 153
151 /** 154 /**
152 * Toggles all classes specified in [iterable] on element. 155 * Toggles all classes specified in [iterable] on element.
153 * 156 *
154 * Iterate through [iterable]'s items, and add it if it is not on it, or 157 * Iterate through [iterable]'s items, and add it if it is not on it, or
155 * remove it if it is. This is the Dart equivalent of jQuery's 158 * remove it if it is. This is the Dart equivalent of jQuery's
156 * [toggleClass](http://api.jquery.com/toggleClass/). 159 * [toggleClass](http://api.jquery.com/toggleClass/).
157 * If [shouldAdd] is true, then we always add all the classes in [iterable] 160 * If [shouldAdd] is true, then we always add all the classes in [iterable]
158 * element. If [shouldAdd] is false then we always remove all the classes in 161 * element. If [shouldAdd] is false then we always remove all the classes in
(...skipping 17 matching lines...) Expand all
176 179
177 bool containsAll(Iterable<Object> collection) => 180 bool containsAll(Iterable<Object> collection) =>
178 readClasses().containsAll(collection); 181 readClasses().containsAll(collection);
179 182
180 Set<String> intersection(Set<Object> other) => 183 Set<String> intersection(Set<Object> other) =>
181 readClasses().intersection(other); 184 readClasses().intersection(other);
182 185
183 Set<String> union(Set<String> other) => 186 Set<String> union(Set<String> other) =>
184 readClasses().union(other); 187 readClasses().union(other);
185 188
186 Set<String> difference(Set<String> other) => 189 Set<String> difference(Set<Object> other) =>
187 readClasses().difference(other); 190 readClasses().difference(other);
188 191
189 String get first => readClasses().first; 192 String get first => readClasses().first;
190 String get last => readClasses().last; 193 String get last => readClasses().last;
191 String get single => readClasses().single; 194 String get single => readClasses().single;
192 List<String> toList({ bool growable: true }) => 195 List<String> toList({ bool growable: true }) =>
193 readClasses().toList(growable: growable); 196 readClasses().toList(growable: growable);
194 Set<String> toSet() => readClasses().toSet(); 197 Set<String> toSet() => readClasses().toSet();
195 Iterable<String> take(int n) => readClasses().take(n); 198 Iterable<String> take(int n) => readClasses().take(n);
196 Iterable<String> takeWhile(bool test(String value)) => 199 Iterable<String> takeWhile(bool test(String value)) =>
(...skipping 17 matching lines...) Expand all
214 217
215 /** 218 /**
216 * Helper method used to modify the set of css classes on this element. 219 * Helper method used to modify the set of css classes on this element.
217 * 220 *
218 * f - callback with: 221 * f - callback with:
219 * s - a Set of all the css class name currently on this element. 222 * s - a Set of all the css class name currently on this element.
220 * 223 *
221 * After f returns, the modified set is written to the 224 * After f returns, the modified set is written to the
222 * className property of this element. 225 * className property of this element.
223 */ 226 */
224 modify( f(Set<String> s)) { 227 modify(f(Set<String> s)) {
225 Set<String> s = readClasses(); 228 Set<String> s = readClasses();
226 var ret = f(s); 229 var ret = f(s);
227 writeClasses(s); 230 writeClasses(s);
228 return ret; 231 return ret;
229 } 232 }
230 233
231 /** 234 /**
232 * Read the class names from the Element class property, 235 * Read the class names from the Element class property,
233 * and put them into a set (duplicates are discarded). 236 * and put them into a set (duplicates are discarded).
234 * This is intended to be overridden by specific implementations. 237 * This is intended to be overridden by specific implementations.
235 */ 238 */
236 Set<String> readClasses(); 239 Set<String> readClasses();
237 240
238 /** 241 /**
239 * Join all the elements of a set into one string and write 242 * Join all the elements of a set into one string and write
240 * back to the element. 243 * back to the element.
241 * This is intended to be overridden by specific implementations. 244 * This is intended to be overridden by specific implementations.
242 */ 245 */
243 void writeClasses(Set<String> s); 246 void writeClasses(Set<String> s);
244 } 247 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698