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

Side by Side Diff: tools/dom/src/AttributeMap.dart

Issue 23055008: Making almost all dom_ methods private. Exceptions will be addressed in a later CL. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 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 html; 5 part of html;
6 6
7 abstract class _AttributeMap implements Map<String, String> { 7 abstract class _AttributeMap implements Map<String, String> {
8 final Element _element; 8 final Element _element;
9 9
10 _AttributeMap(this._element); 10 _AttributeMap(this._element);
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 bool _matches(Node node) => node.$dom_namespaceUri == _namespace; 152 bool _matches(Node node) => node.$dom_namespaceUri == _namespace;
153 } 153 }
154 154
155 155
156 /** 156 /**
157 * Provides a Map abstraction on top of data-* attributes, similar to the 157 * Provides a Map abstraction on top of data-* attributes, similar to the
158 * dataSet in the old DOM. 158 * dataSet in the old DOM.
159 */ 159 */
160 class _DataAttributeMap implements Map<String, String> { 160 class _DataAttributeMap implements Map<String, String> {
161 161
162 final Map<String, String> $dom_attributes; 162 final Map<String, String> _attributes;
163 163
164 _DataAttributeMap(this.$dom_attributes); 164 _DataAttributeMap(this._attributes);
165 165
166 // interface Map 166 // interface Map
167 167
168 // TODO: Use lazy iterator when it is available on Map. 168 // TODO: Use lazy iterator when it is available on Map.
169 bool containsValue(String value) => values.any((v) => v == value); 169 bool containsValue(String value) => values.any((v) => v == value);
170 170
171 bool containsKey(String key) => $dom_attributes.containsKey(_attr(key)); 171 bool containsKey(String key) => _attributes.containsKey(_attr(key));
172 172
173 String operator [](String key) => $dom_attributes[_attr(key)]; 173 String operator [](String key) => _attributes[_attr(key)];
174 174
175 void operator []=(String key, String value) { 175 void operator []=(String key, String value) {
176 $dom_attributes[_attr(key)] = value; 176 _attributes[_attr(key)] = value;
177 } 177 }
178 178
179 String putIfAbsent(String key, String ifAbsent()) => 179 String putIfAbsent(String key, String ifAbsent()) =>
180 $dom_attributes.putIfAbsent(_attr(key), ifAbsent); 180 _attributes.putIfAbsent(_attr(key), ifAbsent);
181 181
182 String remove(String key) => $dom_attributes.remove(_attr(key)); 182 String remove(String key) => _attributes.remove(_attr(key));
183 183
184 void clear() { 184 void clear() {
185 // Needs to operate on a snapshot since we are mutating the collection. 185 // Needs to operate on a snapshot since we are mutating the collection.
186 for (String key in keys) { 186 for (String key in keys) {
187 remove(key); 187 remove(key);
188 } 188 }
189 } 189 }
190 190
191 void forEach(void f(String key, String value)) { 191 void forEach(void f(String key, String value)) {
192 $dom_attributes.forEach((String key, String value) { 192 _attributes.forEach((String key, String value) {
193 if (_matches(key)) { 193 if (_matches(key)) {
194 f(_strip(key), value); 194 f(_strip(key), value);
195 } 195 }
196 }); 196 });
197 } 197 }
198 198
199 Iterable<String> get keys { 199 Iterable<String> get keys {
200 final keys = new List<String>(); 200 final keys = new List<String>();
201 $dom_attributes.forEach((String key, String value) { 201 _attributes.forEach((String key, String value) {
202 if (_matches(key)) { 202 if (_matches(key)) {
203 keys.add(_strip(key)); 203 keys.add(_strip(key));
204 } 204 }
205 }); 205 });
206 return keys; 206 return keys;
207 } 207 }
208 208
209 Iterable<String> get values { 209 Iterable<String> get values {
210 final values = new List<String>(); 210 final values = new List<String>();
211 $dom_attributes.forEach((String key, String value) { 211 _attributes.forEach((String key, String value) {
212 if (_matches(key)) { 212 if (_matches(key)) {
213 values.add(value); 213 values.add(value);
214 } 214 }
215 }); 215 });
216 return values; 216 return values;
217 } 217 }
218 218
219 int get length => keys.length; 219 int get length => keys.length;
220 220
221 // TODO: Use lazy iterator when it is available on Map. 221 // TODO: Use lazy iterator when it is available on Map.
222 bool get isEmpty => length == 0; 222 bool get isEmpty => length == 0;
223 223
224 bool get isNotEmpty => !isEmpty; 224 bool get isNotEmpty => !isEmpty;
225 225
226 // Helpers. 226 // Helpers.
227 String _attr(String key) => 'data-$key'; 227 String _attr(String key) => 'data-$key';
228 bool _matches(String key) => key.startsWith('data-'); 228 bool _matches(String key) => key.startsWith('data-');
229 String _strip(String key) => key.substring(5); 229 String _strip(String key) => key.substring(5);
230 } 230 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698