| OLD | NEW |
| 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' hide Symbol; | 6 import 'dart:_collection-dev' hide Symbol; |
| 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 7642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7653 } else if (JS('bool', '!!#.webkitMatchesSelector', this)) { | 7653 } else if (JS('bool', '!!#.webkitMatchesSelector', this)) { |
| 7654 return JS('bool', '#.webkitMatchesSelector(#)', this, selectors); | 7654 return JS('bool', '#.webkitMatchesSelector(#)', this, selectors); |
| 7655 } else if (JS('bool', '!!#.mozMatchesSelector', this)) { | 7655 } else if (JS('bool', '!!#.mozMatchesSelector', this)) { |
| 7656 return JS('bool', '#.mozMatchesSelector(#)', this, selectors); | 7656 return JS('bool', '#.mozMatchesSelector(#)', this, selectors); |
| 7657 } else if (JS('bool', '!!#.msMatchesSelector', this)) { | 7657 } else if (JS('bool', '!!#.msMatchesSelector', this)) { |
| 7658 return JS('bool', '#.msMatchesSelector(#)', this, selectors); | 7658 return JS('bool', '#.msMatchesSelector(#)', this, selectors); |
| 7659 } | 7659 } |
| 7660 throw new UnsupportedError("Not supported on this platform"); | 7660 throw new UnsupportedError("Not supported on this platform"); |
| 7661 } | 7661 } |
| 7662 | 7662 |
| 7663 @Creates('Null') | 7663 @Creates('Null') // Set from Dart code; does not instantiate a native type. |
| 7664 Map<String, StreamSubscription> _attributeBindings; | 7664 Map<String, StreamSubscription> _attributeBindings; |
| 7665 | 7665 |
| 7666 // TODO(jmesserly): I'm concerned about adding these to every element. | 7666 // TODO(jmesserly): I'm concerned about adding these to every element. |
| 7667 // Conceptually all of these belong on TemplateElement. They are here to | 7667 // Conceptually all of these belong on TemplateElement. They are here to |
| 7668 // support browsers that don't have <template> yet. | 7668 // support browsers that don't have <template> yet. |
| 7669 // However even in the polyfill they're restricted to certain tags | 7669 // However even in the polyfill they're restricted to certain tags |
| 7670 // (see [isTemplate]). So we can probably convert it to a (public) mixin, and | 7670 // (see [isTemplate]). So we can probably convert it to a (public) mixin, and |
| 7671 // only mix it in to the elements that need it. | 7671 // only mix it in to the elements that need it. |
| 7672 @Creates('Null') // Set from Dart code; does not instantiate a native type. | 7672 @Creates('Null') // Set from Dart code; does not instantiate a native type. |
| 7673 var _model; | 7673 var _model; |
| (...skipping 6887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14561 * after the event has fired or if the element has CSS transforms affecting | 14561 * after the event has fired or if the element has CSS transforms affecting |
| 14562 * it. | 14562 * it. |
| 14563 */ | 14563 */ |
| 14564 Point get offset { | 14564 Point get offset { |
| 14565 if (JS('bool', '!!#.offsetX', this)) { | 14565 if (JS('bool', '!!#.offsetX', this)) { |
| 14566 var x = JS('int', '#.offsetX', this); | 14566 var x = JS('int', '#.offsetX', this); |
| 14567 var y = JS('int', '#.offsetY', this); | 14567 var y = JS('int', '#.offsetY', this); |
| 14568 return new Point(x, y); | 14568 return new Point(x, y); |
| 14569 } else { | 14569 } else { |
| 14570 // Firefox does not support offsetX. | 14570 // Firefox does not support offsetX. |
| 14571 var target = this.target; | 14571 if (!(this.target is Element)) { |
| 14572 if (!(target is Element)) { | |
| 14573 throw new UnsupportedError( | 14572 throw new UnsupportedError( |
| 14574 'offsetX is only supported on elements'); | 14573 'offsetX is only supported on elements'); |
| 14575 } | 14574 } |
| 14576 return (this.client - | 14575 Element target = this.target; |
| 14577 this.target.getBoundingClientRect().topLeft).toInt(); | 14576 return (this.client - target.getBoundingClientRect().topLeft).toInt(); |
| 14578 } | 14577 } |
| 14579 } | 14578 } |
| 14580 | 14579 |
| 14581 @DomName('MouseEvent.screenX') | 14580 @DomName('MouseEvent.screenX') |
| 14582 @DomName('MouseEvent.screenY') | 14581 @DomName('MouseEvent.screenY') |
| 14583 Point get screen => new Point($dom_screenX, $dom_screenY); | 14582 Point get screen => new Point($dom_screenX, $dom_screenY); |
| 14584 } | 14583 } |
| 14585 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 14584 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 14586 // for details. All rights reserved. Use of this source code is governed by a | 14585 // for details. All rights reserved. Use of this source code is governed by a |
| 14587 // BSD-style license that can be found in the LICENSE file. | 14586 // BSD-style license that can be found in the LICENSE file. |
| (...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15120 if (l > 1) throw new StateError("More than one element"); | 15119 if (l > 1) throw new StateError("More than one element"); |
| 15121 return JS('Node|Null', '#.firstChild', _this); | 15120 return JS('Node|Null', '#.firstChild', _this); |
| 15122 } | 15121 } |
| 15123 | 15122 |
| 15124 void add(Node value) { | 15123 void add(Node value) { |
| 15125 _this.append(value); | 15124 _this.append(value); |
| 15126 } | 15125 } |
| 15127 | 15126 |
| 15128 void addAll(Iterable<Node> iterable) { | 15127 void addAll(Iterable<Node> iterable) { |
| 15129 if (iterable is _ChildNodeListLazy) { | 15128 if (iterable is _ChildNodeListLazy) { |
| 15130 if (!identical(iterable._this, _this)) { | 15129 _ChildNodeListLazy otherList = iterable; |
| 15130 if (!identical(otherList._this, _this)) { |
| 15131 // Optimized route for copying between nodes. | 15131 // Optimized route for copying between nodes. |
| 15132 for (var i = 0, len = iterable.length; i < len; ++i) { | 15132 for (var i = 0, len = otherList.length; i < len; ++i) { |
| 15133 // Should use $dom_firstChild, Bug 8886. | 15133 // Should use $dom_firstChild, Bug 8886. |
| 15134 _this.append(iterable[0]); | 15134 _this.append(otherList[0]); |
| 15135 } | 15135 } |
| 15136 } | 15136 } |
| 15137 return; | 15137 return; |
| 15138 } | 15138 } |
| 15139 for (Node node in iterable) { | 15139 for (Node node in iterable) { |
| 15140 _this.append(node); | 15140 _this.append(node); |
| 15141 } | 15141 } |
| 15142 } | 15142 } |
| 15143 | 15143 |
| 15144 void insert(int index, Node node) { | 15144 void insert(int index, Node node) { |
| (...skipping 9298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 24443 void pause([Future resumeSignal]) { | 24443 void pause([Future resumeSignal]) { |
| 24444 if (_canceled) return; | 24444 if (_canceled) return; |
| 24445 ++_pauseCount; | 24445 ++_pauseCount; |
| 24446 _unlisten(); | 24446 _unlisten(); |
| 24447 | 24447 |
| 24448 if (resumeSignal != null) { | 24448 if (resumeSignal != null) { |
| 24449 resumeSignal.whenComplete(resume); | 24449 resumeSignal.whenComplete(resume); |
| 24450 } | 24450 } |
| 24451 } | 24451 } |
| 24452 | 24452 |
| 24453 bool get _paused => _pauseCount > 0; | 24453 bool get isPaused => _pauseCount > 0; |
| 24454 | 24454 |
| 24455 void resume() { | 24455 void resume() { |
| 24456 if (_canceled || !_paused) return; | 24456 if (_canceled || !isPaused) return; |
| 24457 --_pauseCount; | 24457 --_pauseCount; |
| 24458 _tryResume(); | 24458 _tryResume(); |
| 24459 } | 24459 } |
| 24460 | 24460 |
| 24461 void _tryResume() { | 24461 void _tryResume() { |
| 24462 if (_onData != null && !_paused) { | 24462 if (_onData != null && !isPaused) { |
| 24463 _target.$dom_addEventListener(_eventType, _onData, _useCapture); | 24463 _target.$dom_addEventListener(_eventType, _onData, _useCapture); |
| 24464 } | 24464 } |
| 24465 } | 24465 } |
| 24466 | 24466 |
| 24467 void _unlisten() { | 24467 void _unlisten() { |
| 24468 if (_onData != null) { | 24468 if (_onData != null) { |
| 24469 _target.$dom_removeEventListener(_eventType, _onData, _useCapture); | 24469 _target.$dom_removeEventListener(_eventType, _onData, _useCapture); |
| 24470 } | 24470 } |
| 24471 } | 24471 } |
| 24472 | 24472 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 24576 } | 24576 } |
| 24577 | 24577 |
| 24578 E removeAt(int pos) { | 24578 E removeAt(int pos) { |
| 24579 throw new UnsupportedError("Cannot remove from immutable List."); | 24579 throw new UnsupportedError("Cannot remove from immutable List."); |
| 24580 } | 24580 } |
| 24581 | 24581 |
| 24582 E removeLast() { | 24582 E removeLast() { |
| 24583 throw new UnsupportedError("Cannot remove from immutable List."); | 24583 throw new UnsupportedError("Cannot remove from immutable List."); |
| 24584 } | 24584 } |
| 24585 | 24585 |
| 24586 void remove(Object object) { | 24586 bool remove(Object object) { |
| 24587 throw new UnsupportedError("Cannot remove from immutable List."); | 24587 throw new UnsupportedError("Cannot remove from immutable List."); |
| 24588 } | 24588 } |
| 24589 | 24589 |
| 24590 void removeWhere(bool test(E element)) { | 24590 void removeWhere(bool test(E element)) { |
| 24591 throw new UnsupportedError("Cannot remove from immutable List."); | 24591 throw new UnsupportedError("Cannot remove from immutable List."); |
| 24592 } | 24592 } |
| 24593 | 24593 |
| 24594 void retainWhere(bool test(E element)) { | 24594 void retainWhere(bool test(E element)) { |
| 24595 throw new UnsupportedError("Cannot remove from immutable List."); | 24595 throw new UnsupportedError("Cannot remove from immutable List."); |
| 24596 } | 24596 } |
| 24597 | 24597 |
| 24598 void setRange(int start, int end, Iterable<E> iterable, [int skipCount]) { | 24598 void setRange(int start, int end, Iterable<E> iterable, [int skipCount = 0]) { |
| 24599 throw new UnsupportedError("Cannot setRange on immutable List."); | 24599 throw new UnsupportedError("Cannot setRange on immutable List."); |
| 24600 } | 24600 } |
| 24601 | 24601 |
| 24602 void removeRange(int start, int end) { | 24602 void removeRange(int start, int end) { |
| 24603 throw new UnsupportedError("Cannot removeRange on immutable List."); | 24603 throw new UnsupportedError("Cannot removeRange on immutable List."); |
| 24604 } | 24604 } |
| 24605 | 24605 |
| 24606 void replaceRange(int start, int end, Iterable<E> iterable) { | 24606 void replaceRange(int start, int end, Iterable<E> iterable) { |
| 24607 throw new UnsupportedError("Cannot modify an immutable List."); | 24607 throw new UnsupportedError("Cannot modify an immutable List."); |
| 24608 } | 24608 } |
| (...skipping 2051 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 26660 } | 26660 } |
| 26661 } | 26661 } |
| 26662 | 26662 |
| 26663 for (var c = node.$dom_firstChild; c != null; c = c.nextNode) { | 26663 for (var c = node.$dom_firstChild; c != null; c = c.nextNode) { |
| 26664 clone.append(_createDeepCloneAndDecorateTemplates(c, syntax)); | 26664 clone.append(_createDeepCloneAndDecorateTemplates(c, syntax)); |
| 26665 } | 26665 } |
| 26666 return clone; | 26666 return clone; |
| 26667 } | 26667 } |
| 26668 | 26668 |
| 26669 // http://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/templates/index.html#
dfn-template-contents-owner | 26669 // http://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/templates/index.html#
dfn-template-contents-owner |
| 26670 static Document _getTemplateContentsOwner(Document doc) { | 26670 static Document _getTemplateContentsOwner(HtmlDocument doc) { |
| 26671 if (doc.window == null) { | 26671 if (doc.window == null) { |
| 26672 return doc; | 26672 return doc; |
| 26673 } | 26673 } |
| 26674 var d = doc._templateContentsOwner; | 26674 var d = doc._templateContentsOwner; |
| 26675 if (d == null) { | 26675 if (d == null) { |
| 26676 // TODO(arv): This should either be a Document or HTMLDocument depending | 26676 // TODO(arv): This should either be a Document or HTMLDocument depending |
| 26677 // on doc. | 26677 // on doc. |
| 26678 d = doc.implementation.createHtmlDocument(''); | 26678 d = doc.implementation.createHtmlDocument(''); |
| 26679 while (d.$dom_lastChild != null) { | 26679 while (d.$dom_lastChild != null) { |
| 26680 d.$dom_lastChild.remove(); | 26680 d.$dom_lastChild.remove(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 26738 void bootstrap(template) { | 26738 void bootstrap(template) { |
| 26739 if (!TemplateElement.decorate(template)) { | 26739 if (!TemplateElement.decorate(template)) { |
| 26740 _bootstrapTemplatesRecursivelyFrom(template.content); | 26740 _bootstrapTemplatesRecursivelyFrom(template.content); |
| 26741 } | 26741 } |
| 26742 } | 26742 } |
| 26743 | 26743 |
| 26744 // Need to do this first as the contents may get lifted if |node| is | 26744 // Need to do this first as the contents may get lifted if |node| is |
| 26745 // template. | 26745 // template. |
| 26746 // TODO(jmesserly): node is DocumentFragment or Element | 26746 // TODO(jmesserly): node is DocumentFragment or Element |
| 26747 var descendents = (node as dynamic).queryAll(_allTemplatesSelectors); | 26747 var descendents = (node as dynamic).queryAll(_allTemplatesSelectors); |
| 26748 if (node is Element && node.isTemplate) bootstrap(node); | 26748 if (node is Element && (node as Element).isTemplate) bootstrap(node); |
| 26749 | 26749 |
| 26750 descendents.forEach(bootstrap); | 26750 descendents.forEach(bootstrap); |
| 26751 } | 26751 } |
| 26752 | 26752 |
| 26753 static final String _allTemplatesSelectors = 'template, option[template], ' + | 26753 static final String _allTemplatesSelectors = 'template, option[template], ' + |
| 26754 Element._TABLE_TAGS.keys.map((k) => "$k[template]").join(", "); | 26754 Element._TABLE_TAGS.keys.map((k) => "$k[template]").join(", "); |
| 26755 | 26755 |
| 26756 static void _addBindings(Node node, model, [CustomBindingSyntax syntax]) { | 26756 static void _addBindings(Node node, model, [CustomBindingSyntax syntax]) { |
| 26757 if (node is Element) { | 26757 if (node is Element) { |
| 26758 _addAttributeBindings(node, model, syntax); | 26758 _addAttributeBindings(node, model, syntax); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 26892 | 26892 |
| 26893 static void _removeAllBindingsRecursively(Node node) { | 26893 static void _removeAllBindingsRecursively(Node node) { |
| 26894 _nodeOrCustom(node).unbindAll(); | 26894 _nodeOrCustom(node).unbindAll(); |
| 26895 for (var c = node.$dom_firstChild; c != null; c = c.nextNode) { | 26895 for (var c = node.$dom_firstChild; c != null; c = c.nextNode) { |
| 26896 _removeAllBindingsRecursively(c); | 26896 _removeAllBindingsRecursively(c); |
| 26897 } | 26897 } |
| 26898 } | 26898 } |
| 26899 | 26899 |
| 26900 static void _removeChild(Node parent, Node child) { | 26900 static void _removeChild(Node parent, Node child) { |
| 26901 child._templateInstance = null; | 26901 child._templateInstance = null; |
| 26902 if (child is Element && child.isTemplate) { | 26902 if (child is Element && (child as Element).isTemplate) { |
| 26903 // Make sure we stop observing when we remove an element. | 26903 // Make sure we stop observing when we remove an element. |
| 26904 var templateIterator = child._templateIterator; | 26904 var templateIterator = child._templateIterator; |
| 26905 if (templateIterator != null) { | 26905 if (templateIterator != null) { |
| 26906 templateIterator.abandon(); | 26906 templateIterator.abandon(); |
| 26907 child._templateIterator = null; | 26907 child._templateIterator = null; |
| 26908 } | 26908 } |
| 26909 } | 26909 } |
| 26910 child.remove(); | 26910 child.remove(); |
| 26911 _removeAllBindingsRecursively(child); | 26911 _removeAllBindingsRecursively(child); |
| 26912 } | 26912 } |
| (...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 27727 // Iterable APIs | 27727 // Iterable APIs |
| 27728 | 27728 |
| 27729 Iterator<E> get iterator => new _WrappedIterator(_list.iterator); | 27729 Iterator<E> get iterator => new _WrappedIterator(_list.iterator); |
| 27730 | 27730 |
| 27731 int get length => _list.length; | 27731 int get length => _list.length; |
| 27732 | 27732 |
| 27733 // Collection APIs | 27733 // Collection APIs |
| 27734 | 27734 |
| 27735 void add(E element) { _list.add(element); } | 27735 void add(E element) { _list.add(element); } |
| 27736 | 27736 |
| 27737 void remove(Object element) { _list.remove(element); } | 27737 bool remove(Object element) => _list.remove(element); |
| 27738 | 27738 |
| 27739 void clear() { _list.clear(); } | 27739 void clear() { _list.clear(); } |
| 27740 | 27740 |
| 27741 // List APIs | 27741 // List APIs |
| 27742 | 27742 |
| 27743 E operator [](int index) => _list[index]; | 27743 E operator [](int index) => _list[index]; |
| 27744 | 27744 |
| 27745 void operator []=(int index, E value) { _list[index] = value; } | 27745 void operator []=(int index, E value) { _list[index] = value; } |
| 27746 | 27746 |
| 27747 void set length(int newLength) { _list.length = newLength; } | 27747 void set length(int newLength) { _list.length = newLength; } |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 27862 return _DOMWindowCrossFrame._createSafe(win); | 27862 return _DOMWindowCrossFrame._createSafe(win); |
| 27863 } | 27863 } |
| 27864 | 27864 |
| 27865 EventTarget _convertNativeToDart_EventTarget(e) { | 27865 EventTarget _convertNativeToDart_EventTarget(e) { |
| 27866 if (e == null) { | 27866 if (e == null) { |
| 27867 return null; | 27867 return null; |
| 27868 } | 27868 } |
| 27869 // Assume it's a Window if it contains the setInterval property. It may be | 27869 // Assume it's a Window if it contains the setInterval property. It may be |
| 27870 // from a different frame - without a patched prototype - so we cannot | 27870 // from a different frame - without a patched prototype - so we cannot |
| 27871 // rely on Dart type checking. | 27871 // rely on Dart type checking. |
| 27872 if (JS('bool', r'"setInterval" in #', e)) | 27872 if (JS('bool', r'"setInterval" in #', e)) { |
| 27873 return _DOMWindowCrossFrame._createSafe(e); | 27873 var window = _DOMWindowCrossFrame._createSafe(e); |
| 27874 // If it's a native window. |
| 27875 if (window is EventTarget) { |
| 27876 return window; |
| 27877 } |
| 27878 return null; |
| 27879 } |
| 27874 else | 27880 else |
| 27875 return e; | 27881 return e; |
| 27876 } | 27882 } |
| 27877 | 27883 |
| 27878 EventTarget _convertDartToNative_EventTarget(e) { | 27884 EventTarget _convertDartToNative_EventTarget(e) { |
| 27879 if (e is _DOMWindowCrossFrame) { | 27885 if (e is _DOMWindowCrossFrame) { |
| 27880 return e._window; | 27886 return e._window; |
| 27881 } else { | 27887 } else { |
| 27882 return e; | 27888 return e; |
| 27883 } | 27889 } |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 28296 _position = nextPosition; | 28302 _position = nextPosition; |
| 28297 return true; | 28303 return true; |
| 28298 } | 28304 } |
| 28299 _current = null; | 28305 _current = null; |
| 28300 _position = _array.length; | 28306 _position = _array.length; |
| 28301 return false; | 28307 return false; |
| 28302 } | 28308 } |
| 28303 | 28309 |
| 28304 T get current => _current; | 28310 T get current => _current; |
| 28305 } | 28311 } |
| OLD | NEW |