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

Side by Side Diff: lib/html/templates/html/impl/impl_Element.darttemplate

Issue 11267018: Make getKeys, getValues getters (keys, values). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update status files with co19 issue number. Created 8 years, 1 month 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 // TODO(jacobr): use _Lists.dart to remove some of the duplicated 5 // TODO(jacobr): use _Lists.dart to remove some of the duplicated
6 // functionality. 6 // functionality.
7 class _ChildrenElementList implements List { 7 class _ChildrenElementList implements List {
8 // Raw Element. 8 // Raw Element.
9 final _ElementImpl _element; 9 final _ElementImpl _element;
10 final _HTMLCollectionImpl _childElements; 10 final _HTMLCollectionImpl _childElements;
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 } 345 }
346 346
347 void forEach(void f(String key, String value)) { 347 void forEach(void f(String key, String value)) {
348 final attributes = _element.$dom_attributes; 348 final attributes = _element.$dom_attributes;
349 for (int i = 0, len = attributes.length; i < len; i++) { 349 for (int i = 0, len = attributes.length; i < len; i++) {
350 final item = attributes[i]; 350 final item = attributes[i];
351 f(item.name, item.value); 351 f(item.name, item.value);
352 } 352 }
353 } 353 }
354 354
355 Collection<String> getKeys() { 355 Collection<String> get keys {
356 // TODO(jacobr): generate a lazy collection instead. 356 // TODO(jacobr): generate a lazy collection instead.
357 final attributes = _element.$dom_attributes; 357 final attributes = _element.$dom_attributes;
358 final keys = new List<String>(attributes.length); 358 final keys = new List<String>(attributes.length);
359 for (int i = 0, len = attributes.length; i < len; i++) { 359 for (int i = 0, len = attributes.length; i < len; i++) {
360 keys[i] = attributes[i].name; 360 keys[i] = attributes[i].name;
361 } 361 }
362 return keys; 362 return keys;
363 } 363 }
364 364
365 Collection<String> getValues() { 365 Collection<String> get values {
366 // TODO(jacobr): generate a lazy collection instead. 366 // TODO(jacobr): generate a lazy collection instead.
367 final attributes = _element.$dom_attributes; 367 final attributes = _element.$dom_attributes;
368 final values = new List<String>(attributes.length); 368 final values = new List<String>(attributes.length);
369 for (int i = 0, len = attributes.length; i < len; i++) { 369 for (int i = 0, len = attributes.length; i < len; i++) {
370 values[i] = attributes[i].value; 370 values[i] = attributes[i].value;
371 } 371 }
372 return values; 372 return values;
373 } 373 }
374 374
375 /** 375 /**
(...skipping 17 matching lines...) Expand all
393 */ 393 */
394 class _DataAttributeMap implements AttributeMap { 394 class _DataAttributeMap implements AttributeMap {
395 395
396 final Map<String, String> $dom_attributes; 396 final Map<String, String> $dom_attributes;
397 397
398 _DataAttributeMap(this.$dom_attributes); 398 _DataAttributeMap(this.$dom_attributes);
399 399
400 // interface Map 400 // interface Map
401 401
402 // TODO: Use lazy iterator when it is available on Map. 402 // TODO: Use lazy iterator when it is available on Map.
403 bool containsValue(String value) => getValues().some((v) => v == value); 403 bool containsValue(String value) => values.some((v) => v == value);
404 404
405 bool containsKey(String key) => $dom_attributes.containsKey(_attr(key)); 405 bool containsKey(String key) => $dom_attributes.containsKey(_attr(key));
406 406
407 String operator [](String key) => $dom_attributes[_attr(key)]; 407 String operator [](String key) => $dom_attributes[_attr(key)];
408 408
409 void operator []=(String key, value) { 409 void operator []=(String key, value) {
410 $dom_attributes[_attr(key)] = '$value'; 410 $dom_attributes[_attr(key)] = '$value';
411 } 411 }
412 412
413 String putIfAbsent(String key, String ifAbsent()) => 413 String putIfAbsent(String key, String ifAbsent()) =>
414 $dom_attributes.putIfAbsent(_attr(key), ifAbsent); 414 $dom_attributes.putIfAbsent(_attr(key), ifAbsent);
415 415
416 String remove(String key) => $dom_attributes.remove(_attr(key)); 416 String remove(String key) => $dom_attributes.remove(_attr(key));
417 417
418 void clear() { 418 void clear() {
419 // Needs to operate on a snapshot since we are mutating the collection. 419 // Needs to operate on a snapshot since we are mutating the collection.
420 for (String key in getKeys()) { 420 for (String key in keys) {
421 remove(key); 421 remove(key);
422 } 422 }
423 } 423 }
424 424
425 void forEach(void f(String key, String value)) { 425 void forEach(void f(String key, String value)) {
426 $dom_attributes.forEach((String key, String value) { 426 $dom_attributes.forEach((String key, String value) {
427 if (_matches(key)) { 427 if (_matches(key)) {
428 f(_strip(key), value); 428 f(_strip(key), value);
429 } 429 }
430 }); 430 });
431 } 431 }
432 432
433 Collection<String> getKeys() { 433 Collection<String> get keys {
434 final keys = new List<String>(); 434 final keys = new List<String>();
435 $dom_attributes.forEach((String key, String value) { 435 $dom_attributes.forEach((String key, String value) {
436 if (_matches(key)) { 436 if (_matches(key)) {
437 keys.add(_strip(key)); 437 keys.add(_strip(key));
438 } 438 }
439 }); 439 });
440 return keys; 440 return keys;
441 } 441 }
442 442
443 Collection<String> getValues() { 443 Collection<String> get values {
444 final values = new List<String>(); 444 final values = new List<String>();
445 $dom_attributes.forEach((String key, String value) { 445 $dom_attributes.forEach((String key, String value) {
446 if (_matches(key)) { 446 if (_matches(key)) {
447 values.add(value); 447 values.add(value);
448 } 448 }
449 }); 449 });
450 return values; 450 return values;
451 } 451 }
452 452
453 int get length => getKeys().length; 453 int get length => keys.length;
454 454
455 // TODO: Use lazy iterator when it is available on Map. 455 // TODO: Use lazy iterator when it is available on Map.
456 bool get isEmpty => length == 0; 456 bool get isEmpty => length == 0;
457 457
458 // Helpers. 458 // Helpers.
459 String _attr(String key) => 'data-$key'; 459 String _attr(String key) => 'data-$key';
460 bool _matches(String key) => key.startsWith('data-'); 460 bool _matches(String key) => key.startsWith('data-');
461 String _strip(String key) => key.substring(5); 461 String _strip(String key) => key.substring(5);
462 } 462 }
463 463
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 665
666 /** 666 /**
667 * @domName Element.hasAttribute, Element.getAttribute, Element.setAttribute, 667 * @domName Element.hasAttribute, Element.getAttribute, Element.setAttribute,
668 * Element.removeAttribute 668 * Element.removeAttribute
669 */ 669 */
670 _ElementAttributeMap get attributes => new _ElementAttributeMap(this); 670 _ElementAttributeMap get attributes => new _ElementAttributeMap(this);
671 671
672 void set attributes(Map<String, String> value) { 672 void set attributes(Map<String, String> value) {
673 Map<String, String> attributes = this.attributes; 673 Map<String, String> attributes = this.attributes;
674 attributes.clear(); 674 attributes.clear();
675 for (String key in value.getKeys()) { 675 for (String key in value.keys) {
676 attributes[key] = value[key]; 676 attributes[key] = value[key];
677 } 677 }
678 } 678 }
679 679
680 void set elements(Collection<Element> value) { 680 void set elements(Collection<Element> value) {
681 final elements = this.elements; 681 final elements = this.elements;
682 elements.clear(); 682 elements.clear();
683 elements.addAll(value); 683 elements.addAll(value);
684 } 684 }
685 685
(...skipping 11 matching lines...) Expand all
697 classSet.clear(); 697 classSet.clear();
698 classSet.addAll(value); 698 classSet.addAll(value);
699 } 699 }
700 700
701 Map<String, String> get dataAttributes => 701 Map<String, String> get dataAttributes =>
702 new _DataAttributeMap(attributes); 702 new _DataAttributeMap(attributes);
703 703
704 void set dataAttributes(Map<String, String> value) { 704 void set dataAttributes(Map<String, String> value) {
705 final dataAttributes = this.dataAttributes; 705 final dataAttributes = this.dataAttributes;
706 dataAttributes.clear(); 706 dataAttributes.clear();
707 for (String key in value.getKeys()) { 707 for (String key in value.keys) {
708 dataAttributes[key] = value[key]; 708 dataAttributes[key] = value[key];
709 } 709 }
710 } 710 }
711 711
712 Future<ElementRect> get rect { 712 Future<ElementRect> get rect {
713 return _createMeasurementFuture( 713 return _createMeasurementFuture(
714 () => new _ElementRectImpl(this), 714 () => new _ElementRectImpl(this),
715 new Completer<ElementRect>()); 715 new Completer<ElementRect>());
716 } 716 }
717 717
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 $if DART2JS 871 $if DART2JS
872 // Optimization to improve performance until the dart2js compiler inlines this 872 // Optimization to improve performance until the dart2js compiler inlines this
873 // method. 873 // method.
874 static Element createElement_tag(String tag) => 874 static Element createElement_tag(String tag) =>
875 JS('Element', 'document.createElement(#)', tag); 875 JS('Element', 'document.createElement(#)', tag);
876 $else 876 $else
877 static Element createElement_tag(String tag) => 877 static Element createElement_tag(String tag) =>
878 _document.$dom_createElement(tag); 878 _document.$dom_createElement(tag);
879 $endif 879 $endif
880 } 880 }
OLDNEW
« no previous file with comments | « lib/html/src/native_DOMImplementation.dart ('k') | lib/html/templates/html/impl/impl_Storage.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698