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

Side by Side Diff: sdk/lib/html/dart2js/html_dart2js.dart

Issue 14965003: "Reverting 22400" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 7 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
« no previous file with comments | « no previous file | sdk/lib/html/dartium/html_dartium.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /// The Dart HTML library. 1 /// The Dart HTML library.
2 library dart.dom.html; 2 library dart.dom.html;
3 3
4 import 'dart:async'; 4 import 'dart:async';
5 import 'dart:collection'; 5 import 'dart:collection';
6 import 'dart:_collection-dev'; 6 import 'dart:_collection-dev';
7 import 'dart:html_common'; 7 import 'dart:html_common';
8 import 'dart:indexed_db'; 8 import 'dart:indexed_db';
9 import 'dart:isolate'; 9 import 'dart:isolate';
10 import 'dart:json' as json; 10 import 'dart:json' as json;
(...skipping 6523 matching lines...) Expand 10 before | Expand all | Expand 10 after
6534 * Unless your webpage contains multiple documents, the top-level queryAll 6534 * Unless your webpage contains multiple documents, the top-level queryAll
6535 * method behaves the same as this method, so you should use it instead to 6535 * method behaves the same as this method, so you should use it instead to
6536 * save typing a few characters. 6536 * save typing a few characters.
6537 * 6537 *
6538 * [selectors] should be a string using CSS selector syntax. 6538 * [selectors] should be a string using CSS selector syntax.
6539 * var items = document.queryAll('.itemClassName'); 6539 * var items = document.queryAll('.itemClassName');
6540 * 6540 *
6541 * For details about CSS selector syntax, see the 6541 * For details about CSS selector syntax, see the
6542 * [CSS selector specification](http://www.w3.org/TR/css3-selectors/). 6542 * [CSS selector specification](http://www.w3.org/TR/css3-selectors/).
6543 */ 6543 */
6544 ElementList queryAll(String selectors) { 6544 List<Element> queryAll(String selectors) {
6545 return new _FrozenElementList._wrap($dom_querySelectorAll(selectors)); 6545 return new _FrozenElementList._wrap($dom_querySelectorAll(selectors));
6546 } 6546 }
6547 } 6547 }
6548 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 6548 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
6549 // for details. All rights reserved. Use of this source code is governed by a 6549 // for details. All rights reserved. Use of this source code is governed by a
6550 // BSD-style license that can be found in the LICENSE file. 6550 // BSD-style license that can be found in the LICENSE file.
6551 6551
6552 6552
6553 @DomName('DocumentFragment') 6553 @DomName('DocumentFragment')
6554 class DocumentFragment extends Node native "DocumentFragment" { 6554 class DocumentFragment extends Node native "DocumentFragment" {
(...skipping 1373 matching lines...) Expand 10 before | Expand all | Expand 10 after
7928 if (result == null) throw new StateError("No elements"); 7928 if (result == null) throw new StateError("No elements");
7929 return result; 7929 return result;
7930 } 7930 }
7931 7931
7932 Element get single { 7932 Element get single {
7933 if (length > 1) throw new StateError("More than one element"); 7933 if (length > 1) throw new StateError("More than one element");
7934 return first; 7934 return first;
7935 } 7935 }
7936 } 7936 }
7937 7937
7938 /**
7939 * An immutable list containing HTML elements. This list contains some
7940 * additional methods for ease of CSS manipulation on a group of elements.
7941 */
7942 abstract class ElementList<T extends Element> extends ListBase<T> {
7943 /**
7944 * The union of all CSS classes applied to the elements in this list.
7945 *
7946 * This set makes it easy to add, remove or toggle (add if not present, remove
7947 * if present) the classes applied to a collection of elements.
7948 *
7949 * htmlList.classes.add('selected');
7950 * htmlList.classes.toggle('isOnline');
7951 * htmlList.classes.remove('selected');
7952 */
7953 CssClassSet get classes;
7954
7955 /** Replace the classes with `value` for every element in this list. */
7956 set classes(Iterable<String> value);
7957 }
7958
7959 // TODO(jacobr): this is an inefficient implementation but it is hard to see 7938 // TODO(jacobr): this is an inefficient implementation but it is hard to see
7960 // a better option given that we cannot quite force NodeList to be an 7939 // a better option given that we cannot quite force NodeList to be an
7961 // ElementList as there are valid cases where a NodeList JavaScript object 7940 // ElementList as there are valid cases where a NodeList JavaScript object
7962 // contains Node objects that are not Elements. 7941 // contains Node objects that are not Elements.
7963 class _FrozenElementList<T extends Element> extends ListBase<T> implements Eleme ntList { 7942 class _FrozenElementList<T extends Element> extends ListBase<T> {
7964 final List<Node> _nodeList; 7943 final List<Node> _nodeList;
7965 7944
7966 _FrozenElementList._wrap(this._nodeList); 7945 _FrozenElementList._wrap(this._nodeList);
7967 7946
7968 int get length => _nodeList.length; 7947 int get length => _nodeList.length;
7969 7948
7970 Element operator [](int index) => _nodeList[index]; 7949 Element operator [](int index) => _nodeList[index];
7971 7950
7972 void operator []=(int index, Element value) { 7951 void operator []=(int index, Element value) {
7973 throw new UnsupportedError('Cannot modify list'); 7952 throw new UnsupportedError('Cannot modify list');
7974 } 7953 }
7975 7954
7976 void set length(int newLength) { 7955 void set length(int newLength) {
7977 throw new UnsupportedError('Cannot modify list'); 7956 throw new UnsupportedError('Cannot modify list');
7978 } 7957 }
7979 7958
7980 void sort([Comparator<Element> compare]) { 7959 void sort([Comparator<Element> compare]) {
7981 throw new UnsupportedError('Cannot sort list'); 7960 throw new UnsupportedError('Cannot sort list');
7982 } 7961 }
7983 7962
7984 Element get first => _nodeList.first; 7963 Element get first => _nodeList.first;
7985 7964
7986 Element get last => _nodeList.last; 7965 Element get last => _nodeList.last;
7987 7966
7988 Element get single => _nodeList.single; 7967 Element get single => _nodeList.single;
7968 }
7989 7969
7990 CssClassSet get classes => new _MultiElementCssClassSet( 7970 class _ElementCssClassSet extends CssClassSet {
7991 _nodeList.where((e) => e is Element));
7992 7971
7993 void set classes(Iterable<String> value) { 7972 final Element _element;
7994 _nodeList.where((e) => e is Element).forEach((e) => e.classes = value); 7973
7974 _ElementCssClassSet(this._element);
7975
7976 Set<String> readClasses() {
7977 var s = new LinkedHashSet<String>();
7978 var classname = _element.$dom_className;
7979
7980 for (String name in classname.split(' ')) {
7981 String trimmed = name.trim();
7982 if (!trimmed.isEmpty) {
7983 s.add(trimmed);
7984 }
7985 }
7986 return s;
7987 }
7988
7989 void writeClasses(Set<String> s) {
7990 List list = new List.from(s);
7991 _element.$dom_className = s.join(' ');
7995 } 7992 }
7996 } 7993 }
7997 7994
7998 /** 7995 /**
7999 * An abstract class, which all HTML elements extend. 7996 * An abstract class, which all HTML elements extend.
8000 */ 7997 */
8001 @DomName('Element') 7998 @DomName('Element')
8002 abstract class Element extends Node implements ElementTraversal native "Element" { 7999 abstract class Element extends Node implements ElementTraversal native "Element" {
8003 8000
8004 /** 8001 /**
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
8084 } 8081 }
8085 8082
8086 /** 8083 /**
8087 * Finds all descendent elements of this element that match the specified 8084 * Finds all descendent elements of this element that match the specified
8088 * group of selectors. 8085 * group of selectors.
8089 * 8086 *
8090 * [selectors] should be a string using CSS selector syntax. 8087 * [selectors] should be a string using CSS selector syntax.
8091 * 8088 *
8092 * var items = element.query('.itemClassName'); 8089 * var items = element.query('.itemClassName');
8093 */ 8090 */
8094 ElementList queryAll(String selectors) => 8091 List<Element> queryAll(String selectors) =>
8095 new _FrozenElementList._wrap($dom_querySelectorAll(selectors)); 8092 new _FrozenElementList._wrap($dom_querySelectorAll(selectors));
8096 8093
8097 /** 8094 /**
8098 * The set of CSS classes applied to this element. 8095 * The set of CSS classes applied to this element.
8099 * 8096 *
8100 * This set makes it easy to add, remove or toggle the classes applied to 8097 * This set makes it easy to add, remove or toggle the classes applied to
8101 * this element. 8098 * this element.
8102 * 8099 *
8103 * element.classes.add('selected'); 8100 * element.classes.add('selected');
8104 * element.classes.toggle('isOnline'); 8101 * element.classes.toggle('isOnline');
(...skipping 18381 matching lines...) Expand 10 before | Expand all | Expand 10 after
26486 abstract class HistoryBase { 26483 abstract class HistoryBase {
26487 void back(); 26484 void back();
26488 void forward(); 26485 void forward();
26489 void go(int distance); 26486 void go(int distance);
26490 } 26487 }
26491 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 26488 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
26492 // for details. All rights reserved. Use of this source code is governed by a 26489 // for details. All rights reserved. Use of this source code is governed by a
26493 // BSD-style license that can be found in the LICENSE file. 26490 // BSD-style license that can be found in the LICENSE file.
26494 26491
26495 26492
26496 /** A Set that stores the CSS class names for an element. */
26497 abstract class CssClassSet implements Set<String> { 26493 abstract class CssClassSet implements Set<String> {
26498 26494
26495 String toString() {
26496 return readClasses().join(' ');
26497 }
26498
26499 /** 26499 /**
26500 * Adds the class [value] to the element if it is not on it, removes it if it 26500 * Adds the class [value] to the element if it is not on it, removes it if it
26501 * is. 26501 * is.
26502 */ 26502 */
26503 bool toggle(String value); 26503 bool toggle(String value) {
26504 Set<String> s = readClasses();
26505 bool result = false;
26506 if (s.contains(value)) {
26507 s.remove(value);
26508 } else {
26509 s.add(value);
26510 result = true;
26511 }
26512 writeClasses(s);
26513 return result;
26514 }
26504 26515
26505 /** 26516 /**
26506 * Returns [:true:] if classes cannot be added or removed from this 26517 * Returns [:true:] if classes cannot be added or removed from this
26507 * [:CssClassSet:]. 26518 * [:CssClassSet:].
26508 */ 26519 */
26509 bool get frozen; 26520 bool get frozen => false;
26510 26521
26522 // interface Iterable - BEGIN
26523 Iterator<String> get iterator => readClasses().iterator;
26524 // interface Iterable - END
26525
26526 // interface Collection - BEGIN
26527 void forEach(void f(String element)) {
26528 readClasses().forEach(f);
26529 }
26530
26531 String join([String separator = ""]) => readClasses().join(separator);
26532
26533 Iterable map(f(String element)) => readClasses().map(f);
26534
26535 Iterable<String> where(bool f(String element)) => readClasses().where(f);
26536
26537 Iterable expand(Iterable f(String element)) => readClasses().expand(f);
26538
26539 bool every(bool f(String element)) => readClasses().every(f);
26540
26541 bool any(bool f(String element)) => readClasses().any(f);
26542
26543 bool get isEmpty => readClasses().isEmpty;
26544
26545 int get length => readClasses().length;
26546
26547 String reduce(String combine(String value, String element)) {
26548 return readClasses().reduce(combine);
26549 }
26550
26551 dynamic fold(dynamic initialValue,
26552 dynamic combine(dynamic previousValue, String element)) {
26553 return readClasses().fold(initialValue, combine);
26554 }
26555 // interface Collection - END
26556
26557 // interface Set - BEGIN
26511 /** 26558 /**
26512 * Determine if this element contains the class [value]. 26559 * Determine if this element contains the class [value].
26513 * 26560 *
26514 * This is the Dart equivalent of jQuery's 26561 * This is the Dart equivalent of jQuery's
26515 * [hasClass](http://api.jquery.com/hasClass/). 26562 * [hasClass](http://api.jquery.com/hasClass/).
26516 */ 26563 */
26517 bool contains(String value); 26564 bool contains(String value) => readClasses().contains(value);
26518 26565
26519 /** 26566 /**
26520 * Add the class [value] to element. 26567 * Add the class [value] to element.
26521 * 26568 *
26522 * This is the Dart equivalent of jQuery's 26569 * This is the Dart equivalent of jQuery's
26523 * [addClass](http://api.jquery.com/addClass/). 26570 * [addClass](http://api.jquery.com/addClass/).
26524 */ 26571 */
26525 void add(String value); 26572 void add(String value) {
26573 // TODO - figure out if we need to do any validation here
26574 // or if the browser natively does enough.
26575 _modify((s) => s.add(value));
26576 }
26526 26577
26527 /** 26578 /**
26528 * Remove the class [value] from element, and return true on successful 26579 * Remove the class [value] from element, and return true on successful
26529 * removal. 26580 * removal.
26530 * 26581 *
26531 * This is the Dart equivalent of jQuery's 26582 * This is the Dart equivalent of jQuery's
26532 * [removeClass](http://api.jquery.com/removeClass/). 26583 * [removeClass](http://api.jquery.com/removeClass/).
26533 */ 26584 */
26534 bool remove(Object value); 26585 bool remove(Object value) {
26586 if (value is! String) return false;
26587 Set<String> s = readClasses();
26588 bool result = s.remove(value);
26589 writeClasses(s);
26590 return result;
26591 }
26535 26592
26536 /** 26593 /**
26537 * Add all classes specified in [iterable] to element. 26594 * Add all classes specified in [iterable] to element.
26538 * 26595 *
26539 * This is the Dart equivalent of jQuery's 26596 * This is the Dart equivalent of jQuery's
26540 * [addClass](http://api.jquery.com/addClass/). 26597 * [addClass](http://api.jquery.com/addClass/).
26541 */ 26598 */
26542 void addAll(Iterable<String> iterable); 26599 void addAll(Iterable<String> iterable) {
26600 // TODO - see comment above about validation.
26601 _modify((s) => s.addAll(iterable));
26602 }
26543 26603
26544 /** 26604 /**
26545 * Remove all classes specified in [iterable] from element. 26605 * Remove all classes specified in [iterable] from element.
26546 * 26606 *
26547 * This is the Dart equivalent of jQuery's 26607 * This is the Dart equivalent of jQuery's
26548 * [removeClass](http://api.jquery.com/removeClass/). 26608 * [removeClass](http://api.jquery.com/removeClass/).
26549 */ 26609 */
26550 void removeAll(Iterable<String> iterable); 26610 void removeAll(Iterable<String> iterable) {
26611 _modify((s) => s.removeAll(iterable));
26612 }
26551 26613
26552 /** 26614 /**
26553 * Toggles all classes specified in [iterable] on element. 26615 * Toggles all classes specified in [iterable] on element.
26554 * 26616 *
26555 * Iterate through [iterable]'s items, and add it if it is not on it, or 26617 * Iterate through [iterable]'s items, and add it if it is not on it, or
26556 * remove it if it is. This is the Dart equivalent of jQuery's 26618 * remove it if it is. This is the Dart equivalent of jQuery's
26557 * [toggleClass](http://api.jquery.com/toggleClass/). 26619 * [toggleClass](http://api.jquery.com/toggleClass/).
26558 */ 26620 */
26559 void toggleAll(Iterable<String> iterable); 26621 void toggleAll(Iterable<String> iterable) {
26560 } 26622 iterable.forEach(toggle);
26561
26562 /**
26563 * A set (union) of the CSS classes that are present in a set of elements.
26564 * Implemented separately from _ElementCssClassSet for performance.
26565 */
26566 class _MultiElementCssClassSet extends CssClassSetImpl {
26567 final Iterable<Element> _elementIterable;
26568 Iterable<_ElementCssClassSet> _elementCssClassSetIterable;
26569
26570 _MultiElementCssClassSet(this._elementIterable) {
26571 _elementCssClassSetIterable = new List.from(_elementIterable).map(
26572 (e) => new _ElementCssClassSet(e));
26573 } 26623 }
26574 26624
26575 Set<String> readClasses() { 26625 void retainAll(Iterable<String> iterable) {
26576 var s = new LinkedHashSet<String>(); 26626 _modify((s) => s.retainAll(iterable));
26577 _elementCssClassSetIterable.forEach((e) => s.addAll(e.readClasses()));
26578 return s;
26579 } 26627 }
26580 26628
26581 void writeClasses(Set<String> s) { 26629 void removeWhere(bool test(String name)) {
26582 var classes = new List.from(s).join(' '); 26630 _modify((s) => s.removeWhere(test));
26583 for (Element e in _elementIterable) {
26584 e.$dom_className = classes;
26585 }
26586 } 26631 }
26587 26632
26633 void retainWhere(bool test(String name)) {
26634 _modify((s) => s.retainWhere(test));
26635 }
26636
26637 bool containsAll(Iterable<String> collection) =>
26638 readClasses().containsAll(collection);
26639
26640 Set<String> intersection(Set<String> other) =>
26641 readClasses().intersection(other);
26642
26643 Set<String> union(Set<String> other) =>
26644 readClasses().union(other);
26645
26646 Set<String> difference(Set<String> other) =>
26647 readClasses().difference(other);
26648
26649 String get first => readClasses().first;
26650 String get last => readClasses().last;
26651 String get single => readClasses().single;
26652 List<String> toList({ bool growable: true }) =>
26653 readClasses().toList(growable: growable);
26654 Set<String> toSet() => readClasses().toSet();
26655 Iterable<String> take(int n) => readClasses().take(n);
26656 Iterable<String> takeWhile(bool test(String value)) =>
26657 readClasses().takeWhile(test);
26658 Iterable<String> skip(int n) => readClasses().skip(n);
26659 Iterable<String> skipWhile(bool test(String value)) =>
26660 readClasses().skipWhile(test);
26661 String firstWhere(bool test(String value), { String orElse() }) =>
26662 readClasses().firstWhere(test, orElse: orElse);
26663 String lastWhere(bool test(String value), {String orElse()}) =>
26664 readClasses().lastWhere(test, orElse: orElse);
26665 String singleWhere(bool test(String value)) =>
26666 readClasses().singleWhere(test);
26667 String elementAt(int index) => readClasses().elementAt(index);
26668
26669 void clear() {
26670 _modify((s) => s.clear());
26671 }
26672 // interface Set - END
26673
26588 /** 26674 /**
26589 * Helper method used to modify the set of css classes on this element. 26675 * Helper method used to modify the set of css classes on this element.
26590 * 26676 *
26591 * f - callback with: 26677 * f - callback with:
26592 * s - a Set of all the css class name currently on this element. 26678 * s - a Set of all the css class name currently on this element.
26593 * 26679 *
26594 * After f returns, the modified set is written to the 26680 * After f returns, the modified set is written to the
26595 * className property of this element. 26681 * className property of this element.
26596 */ 26682 */
26597 void modify( f(Set<String> s)) { 26683 void _modify( f(Set<String> s)) {
26598 _elementCssClassSetIterable.forEach((e) => e.modify(f)); 26684 Set<String> s = readClasses();
26685 f(s);
26686 writeClasses(s);
26599 } 26687 }
26600 26688
26601 /** 26689 /**
26602 * Adds the class [value] to the element if it is not on it, removes it if it 26690 * Read the class names from the Element class property,
26603 * is. 26691 * and put them into a set (duplicates are discarded).
26692 * This is intended to be overridden by specific implementations.
26604 */ 26693 */
26605 bool toggle(String value) => 26694 Set<String> readClasses();
26606 _modifyWithReturnValue((e) => e.toggle(value));
26607 26695
26608 /** 26696 /**
26609 * Remove the class [value] from element, and return true on successful 26697 * Join all the elements of a set into one string and write
26610 * removal. 26698 * back to the element.
26611 * 26699 * This is intended to be overridden by specific implementations.
26612 * This is the Dart equivalent of jQuery's
26613 * [removeClass](http://api.jquery.com/removeClass/).
26614 */ 26700 */
26615 bool remove(Object value) => _modifyWithReturnValue((e) => e.remove(value)); 26701 void writeClasses(Set<String> s);
26616
26617 bool _modifyWithReturnValue(f) => _elementCssClassSetIterable.fold(
26618 false, (prevValue, element) => f(element) || prevValue);
26619 }
26620
26621 class _ElementCssClassSet extends CssClassSetImpl {
26622
26623 final Element _element;
26624
26625 _ElementCssClassSet(this._element);
26626
26627 Set<String> readClasses() {
26628 var s = new LinkedHashSet<String>();
26629 var classname = _element.$dom_className;
26630
26631 for (String name in classname.split(' ')) {
26632 String trimmed = name.trim();
26633 if (!trimmed.isEmpty) {
26634 s.add(trimmed);
26635 }
26636 }
26637 return s;
26638 }
26639
26640 void writeClasses(Set<String> s) {
26641 List list = new List.from(s);
26642 _element.$dom_className = s.join(' ');
26643 }
26644 } 26702 }
26645 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 26703 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
26646 // for details. All rights reserved. Use of this source code is governed by a 26704 // for details. All rights reserved. Use of this source code is governed by a
26647 // BSD-style license that can be found in the LICENSE file. 26705 // BSD-style license that can be found in the LICENSE file.
26648 26706
26649 26707
26650 typedef EventListener(Event event); 26708 typedef EventListener(Event event);
26651 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 26709 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
26652 // for details. All rights reserved. Use of this source code is governed by a 26710 // for details. All rights reserved. Use of this source code is governed by a
26653 // BSD-style license that can be found in the LICENSE file. 26711 // BSD-style license that can be found in the LICENSE file.
(...skipping 2864 matching lines...) Expand 10 before | Expand all | Expand 10 after
29518 _position = nextPosition; 29576 _position = nextPosition;
29519 return true; 29577 return true;
29520 } 29578 }
29521 _current = null; 29579 _current = null;
29522 _position = _array.length; 29580 _position = _array.length;
29523 return false; 29581 return false;
29524 } 29582 }
29525 29583
29526 T get current => _current; 29584 T get current => _current;
29527 } 29585 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/html/dartium/html_dartium.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698