| OLD | NEW |
| 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 ElementList { | 7 class _ChildrenElementList implements ElementList { |
| 8 // Raw Element. | 8 // Raw Element. |
| 9 final _ElementImpl _element; | 9 final _ElementImpl _element; |
| 10 final _HTMLCollectionImpl _childElements; | 10 final _HTMLCollectionImpl _childElements; |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 | 463 |
| 464 // TODO: Use lazy iterator when it is available on Map. | 464 // TODO: Use lazy iterator when it is available on Map. |
| 465 bool isEmpty() => length == 0; | 465 bool isEmpty() => length == 0; |
| 466 | 466 |
| 467 // Helpers. | 467 // Helpers. |
| 468 String _attr(String key) => 'data-$key'; | 468 String _attr(String key) => 'data-$key'; |
| 469 bool _matches(String key) => key.startsWith('data-'); | 469 bool _matches(String key) => key.startsWith('data-'); |
| 470 String _strip(String key) => key.substring(5); | 470 String _strip(String key) => key.substring(5); |
| 471 } | 471 } |
| 472 | 472 |
| 473 class _CssClassSet implements Set<String> { | 473 class _CssClassSet implements CSSClassSet { |
| 474 | 474 |
| 475 final _ElementImpl _element; | 475 final _ElementImpl _element; |
| 476 | 476 |
| 477 _CssClassSet(this._element); | 477 _CssClassSet(this._element); |
| 478 | 478 |
| 479 String toString() => _formatSet(_read()); | 479 String toString() => _formatSet(_read()); |
| 480 | 480 |
| 481 // interface Iterable - BEGIN | 481 // interface Iterable - BEGIN |
| 482 Iterator<String> iterator() => _read().iterator(); | 482 Iterator<String> iterator() => _read().iterator(); |
| 483 // interface Iterable - END | 483 // interface Iterable - END |
| 484 | 484 |
| 485 // interface Collection - BEGIN | 485 // interface Collection - BEGIN |
| 486 void forEach(void f(String element)) { | 486 void forEach(void f(String element)) { |
| 487 _read().forEach(f); | 487 _read().forEach(f); |
| 488 } | 488 } |
| 489 | 489 |
| 490 Collection map(f(String element)) => _read().map(f); | 490 Collection map(f(String element)) => _read().map(f); |
| 491 | 491 |
| 492 Collection<String> filter(bool f(String element)) => _read().filter(f); | 492 Collection<String> filter(bool f(String element)) => _read().filter(f); |
| 493 | 493 |
| 494 bool every(bool f(String element)) => _read().every(f); | 494 bool every(bool f(String element)) => _read().every(f); |
| 495 | 495 |
| 496 bool some(bool f(String element)) => _read().some(f); | 496 bool some(bool f(String element)) => _read().some(f); |
| 497 | 497 |
| 498 bool isEmpty() => _read().isEmpty(); | 498 bool isEmpty() => _read().isEmpty(); |
| 499 | 499 |
| 500 bool isFrozen() => false; |
| 501 |
| 500 int get length() =>_read().length; | 502 int get length() =>_read().length; |
| 501 | 503 |
| 502 // interface Collection - END | 504 // interface Collection - END |
| 503 | 505 |
| 504 // interface Set - BEGIN | 506 // interface Set - BEGIN |
| 505 bool contains(String value) => _read().contains(value); | 507 bool contains(String value) => _read().contains(value); |
| 506 | 508 |
| 507 void add(String value) { | 509 void add(String value) { |
| 508 // TODO - figure out if we need to do any validation here | 510 // TODO - figure out if we need to do any validation here |
| 509 // or if the browser natively does enough | 511 // or if the browser natively does enough |
| 510 _modify((s) => s.add(value)); | 512 _modify((s) => s.add(value)); |
| 511 } | 513 } |
| 512 | 514 |
| 513 bool remove(String value) { | 515 bool remove(String value) { |
| 514 Set<String> s = _read(); | 516 Set<String> s = _read(); |
| 515 bool result = s.remove(value); | 517 bool result = s.remove(value); |
| 516 _write(s); | 518 _write(s); |
| 517 return result; | 519 return result; |
| 518 } | 520 } |
| 519 | 521 |
| 522 bool toggle(String value) { |
| 523 Set<String> s = _read(); |
| 524 bool result = false; |
| 525 if (s.contains(value)) { |
| 526 s.remove(value); |
| 527 } else { |
| 528 s.add(value); |
| 529 result = true; |
| 530 } |
| 531 _write(s); |
| 532 return result; |
| 533 } |
| 534 |
| 520 void addAll(Collection<String> collection) { | 535 void addAll(Collection<String> collection) { |
| 521 // TODO - see comment above about validation | 536 // TODO - see comment above about validation |
| 522 _modify((s) => s.addAll(collection)); | 537 _modify((s) => s.addAll(collection)); |
| 523 } | 538 } |
| 524 | 539 |
| 525 void removeAll(Collection<String> collection) { | 540 void removeAll(Collection<String> collection) { |
| 526 _modify((s) => s.removeAll(collection)); | 541 _modify((s) => s.removeAll(collection)); |
| 527 } | 542 } |
| 528 | 543 |
| 529 bool isSubsetOf(Collection<String> collection) => | 544 bool isSubsetOf(Collection<String> collection) => |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 * All your element measurement needs in one place | 632 * All your element measurement needs in one place |
| 618 * @domName none | 633 * @domName none |
| 619 */ | 634 */ |
| 620 class _ElementRectImpl implements ElementRect { | 635 class _ElementRectImpl implements ElementRect { |
| 621 final ClientRect client; | 636 final ClientRect client; |
| 622 final ClientRect offset; | 637 final ClientRect offset; |
| 623 final ClientRect scroll; | 638 final ClientRect scroll; |
| 624 | 639 |
| 625 // TODO(jacobr): should we move these outside of ElementRect to avoid the | 640 // TODO(jacobr): should we move these outside of ElementRect to avoid the |
| 626 // overhead of computing them every time even though they are rarely used. | 641 // overhead of computing them every time even though they are rarely used. |
| 627 final _ClientRectImpl _boundingClientRect; | 642 final _ClientRectImpl _boundingClientRect; |
| 628 final _ClientRectListImpl _clientRects; | 643 final _ClientRectListImpl _clientRects; |
| 629 | 644 |
| 630 _ElementRectImpl(_ElementImpl element) : | 645 _ElementRectImpl(_ElementImpl element) : |
| 631 client = new _SimpleClientRect(element.$dom_clientLeft, | 646 client = new _SimpleClientRect(element.$dom_clientLeft, |
| 632 element.$dom_clientTop, | 647 element.$dom_clientTop, |
| 633 element.$dom_clientWidth, | 648 element.$dom_clientWidth, |
| 634 element.$dom_clientHeight), | 649 element.$dom_clientHeight), |
| 635 offset = new _SimpleClientRect(element.$dom_offsetLeft, | 650 offset = new _SimpleClientRect(element.$dom_offsetLeft, |
| 636 element.$dom_offsetTop, | 651 element.$dom_offsetTop, |
| 637 element.$dom_offsetWidth, | 652 element.$dom_offsetWidth, |
| 638 element.$dom_offsetHeight), | 653 element.$dom_offsetHeight), |
| 639 scroll = new _SimpleClientRect(element.$dom_scrollLeft, | 654 scroll = new _SimpleClientRect(element.$dom_scrollLeft, |
| 640 element.$dom_scrollTop, | 655 element.$dom_scrollTop, |
| 641 element.$dom_scrollWidth, | 656 element.$dom_scrollWidth, |
| 642 element.$dom_scrollHeight), | 657 element.$dom_scrollHeight), |
| 643 _boundingClientRect = element.$dom_getBoundingClientRect(), | 658 _boundingClientRect = element.$dom_getBoundingClientRect(), |
| 644 _clientRects = element.$dom_getClientRects(); | 659 _clientRects = element.$dom_getClientRects(); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 | 810 |
| 796 /** @domName Document.createElement */ | 811 /** @domName Document.createElement */ |
| 797 $if DART2JS | 812 $if DART2JS |
| 798 // Optimization to improve performance until the dart2js compiler inlines this | 813 // Optimization to improve performance until the dart2js compiler inlines this |
| 799 // method. | 814 // method. |
| 800 factory Element.tag(String tag) native "return document.createElement(tag)"; | 815 factory Element.tag(String tag) native "return document.createElement(tag)"; |
| 801 $else | 816 $else |
| 802 factory Element.tag(String tag) => _document.$dom_createElement(tag); | 817 factory Element.tag(String tag) => _document.$dom_createElement(tag); |
| 803 $endif | 818 $endif |
| 804 } | 819 } |
| OLD | NEW |