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 10630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10641 } | 10641 } |
10642 if (timeout != null) { | 10642 if (timeout != null) { |
10643 options['timeout'] = timeout.inMilliseconds; | 10643 options['timeout'] = timeout.inMilliseconds; |
10644 } | 10644 } |
10645 if (maximumAge != null) { | 10645 if (maximumAge != null) { |
10646 options['maximumAge'] = maximumAge.inMilliseconds; | 10646 options['maximumAge'] = maximumAge.inMilliseconds; |
10647 } | 10647 } |
10648 | 10648 |
10649 int watchId; | 10649 int watchId; |
10650 var controller; | 10650 var controller; |
10651 controller = new StreamController<Geoposition>( | 10651 controller = new StreamController<Geoposition>(sync: true, |
10652 onListen: () { | 10652 onListen: () { |
10653 assert(watchId == null); | 10653 assert(watchId == null); |
10654 watchId = $dom_watchPosition( | 10654 watchId = $dom_watchPosition( |
10655 (position) { | 10655 (position) { |
10656 controller.add(_ensurePosition(position)); | 10656 controller.add(_ensurePosition(position)); |
10657 }, | 10657 }, |
10658 (error) { | 10658 (error) { |
10659 controller.addError(error); | 10659 controller.addError(error); |
10660 }, | 10660 }, |
10661 options); | 10661 options); |
(...skipping 9717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20379 * should not be used in your code. | 20379 * should not be used in your code. |
20380 * | 20380 * |
20381 * This event is fired whenever a template is instantiated via | 20381 * This event is fired whenever a template is instantiated via |
20382 * [createInstance]. | 20382 * [createInstance]. |
20383 */ | 20383 */ |
20384 // TODO(rafaelw): This is a hack, and is neccesary for the polyfill | 20384 // TODO(rafaelw): This is a hack, and is neccesary for the polyfill |
20385 // because custom elements are not upgraded during clone() | 20385 // because custom elements are not upgraded during clone() |
20386 @Experimental | 20386 @Experimental |
20387 static Stream<DocumentFragment> get instanceCreated { | 20387 static Stream<DocumentFragment> get instanceCreated { |
20388 if (_instanceCreated == null) { | 20388 if (_instanceCreated == null) { |
20389 _instanceCreated = new StreamController<DocumentFragment>(); | 20389 _instanceCreated = new StreamController<DocumentFragment>(sync: true); |
20390 } | 20390 } |
20391 return _instanceCreated.stream; | 20391 return _instanceCreated.stream; |
20392 } | 20392 } |
20393 | 20393 |
20394 /** | 20394 /** |
20395 * Ensures proper API and content model for template elements. | 20395 * Ensures proper API and content model for template elements. |
20396 * | 20396 * |
20397 * [instanceRef] can be used to set the [Element.ref] property of [template], | 20397 * [instanceRef] can be used to set the [Element.ref] property of [template], |
20398 * and use the ref's content will be used as source when createInstance() is | 20398 * and use the ref's content will be used as source when createInstance() is |
20399 * invoked. | 20399 * invoked. |
(...skipping 2905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
23305 } | 23305 } |
23306 } | 23306 } |
23307 | 23307 |
23308 class _BeforeUnloadEventStreamProvider implements | 23308 class _BeforeUnloadEventStreamProvider implements |
23309 EventStreamProvider<BeforeUnloadEvent> { | 23309 EventStreamProvider<BeforeUnloadEvent> { |
23310 final String _eventType; | 23310 final String _eventType; |
23311 | 23311 |
23312 const _BeforeUnloadEventStreamProvider(this._eventType); | 23312 const _BeforeUnloadEventStreamProvider(this._eventType); |
23313 | 23313 |
23314 Stream<BeforeUnloadEvent> forTarget(EventTarget e, {bool useCapture: false}) { | 23314 Stream<BeforeUnloadEvent> forTarget(EventTarget e, {bool useCapture: false}) { |
23315 var controller = new StreamController(); | 23315 var controller = new StreamController(sync: true); |
23316 var stream = new _EventStream(e, _eventType, useCapture); | 23316 var stream = new _EventStream(e, _eventType, useCapture); |
23317 stream.listen((event) { | 23317 stream.listen((event) { |
23318 var wrapped = new _BeforeUnloadEvent(event); | 23318 var wrapped = new _BeforeUnloadEvent(event); |
23319 controller.add(wrapped); | 23319 controller.add(wrapped); |
23320 return wrapped.returnValue; | 23320 return wrapped.returnValue; |
23321 }); | 23321 }); |
23322 | 23322 |
23323 return controller.stream; | 23323 return controller.stream; |
23324 } | 23324 } |
23325 | 23325 |
(...skipping 2351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
25677 /** The type of KeyEvent we are tracking (keyup, keydown, keypress). */ | 25677 /** The type of KeyEvent we are tracking (keyup, keydown, keypress). */ |
25678 final String _type; | 25678 final String _type; |
25679 | 25679 |
25680 /** The element we are watching for events to happen on. */ | 25680 /** The element we are watching for events to happen on. */ |
25681 final EventTarget _target; | 25681 final EventTarget _target; |
25682 | 25682 |
25683 // The distance to shift from upper case alphabet Roman letters to lower case. | 25683 // The distance to shift from upper case alphabet Roman letters to lower case. |
25684 static final int _ROMAN_ALPHABET_OFFSET = "a".codeUnits[0] - "A".codeUnits[0]; | 25684 static final int _ROMAN_ALPHABET_OFFSET = "a".codeUnits[0] - "A".codeUnits[0]; |
25685 | 25685 |
25686 /** Controller to produce KeyEvents for the stream. */ | 25686 /** Controller to produce KeyEvents for the stream. */ |
25687 final StreamController _controller = new StreamController(); | 25687 final StreamController _controller = new StreamController(sync: true); |
25688 | 25688 |
25689 static const _EVENT_TYPE = 'KeyEvent'; | 25689 static const _EVENT_TYPE = 'KeyEvent'; |
25690 | 25690 |
25691 /** | 25691 /** |
25692 * An enumeration of key identifiers currently part of the W3C draft for DOM3 | 25692 * An enumeration of key identifiers currently part of the W3C draft for DOM3 |
25693 * and their mappings to keyCodes. | 25693 * and their mappings to keyCodes. |
25694 * http://www.w3.org/TR/DOM-Level-3-Events/keyset.html#KeySet-Set | 25694 * http://www.w3.org/TR/DOM-Level-3-Events/keyset.html#KeySet-Set |
25695 */ | 25695 */ |
25696 static const Map<String, int> _keyIdentifier = const { | 25696 static const Map<String, int> _keyIdentifier = const { |
25697 'Up': KeyCode.UP, | 25697 'Up': KeyCode.UP, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
25746 * KeyboardEvent controller. | 25746 * KeyboardEvent controller. |
25747 */ | 25747 */ |
25748 _KeyboardEventHandler(this._type) : | 25748 _KeyboardEventHandler(this._type) : |
25749 _target = null, super(_EVENT_TYPE) { | 25749 _target = null, super(_EVENT_TYPE) { |
25750 } | 25750 } |
25751 | 25751 |
25752 /** | 25752 /** |
25753 * Hook up all event listeners under the covers so we can estimate keycodes | 25753 * Hook up all event listeners under the covers so we can estimate keycodes |
25754 * and charcodes when they are not provided. | 25754 * and charcodes when they are not provided. |
25755 */ | 25755 */ |
25756 _KeyboardEventHandler.initializeAllEventListeners(this._type, this._target) : | 25756 _KeyboardEventHandler.initializeAllEventListeners(this._type, this._target) : |
25757 super(_EVENT_TYPE) { | 25757 super(_EVENT_TYPE) { |
25758 Element.keyDownEvent.forTarget(_target, useCapture: true).listen( | 25758 Element.keyDownEvent.forTarget(_target, useCapture: true).listen( |
25759 processKeyDown); | 25759 processKeyDown); |
25760 Element.keyPressEvent.forTarget(_target, useCapture: true).listen( | 25760 Element.keyPressEvent.forTarget(_target, useCapture: true).listen( |
25761 processKeyPress); | 25761 processKeyPress); |
25762 Element.keyUpEvent.forTarget(_target, useCapture: true).listen( | 25762 Element.keyUpEvent.forTarget(_target, useCapture: true).listen( |
25763 processKeyUp); | 25763 processKeyUp); |
25764 } | 25764 } |
25765 | 25765 |
25766 /** | 25766 /** |
(...skipping 1124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
26891 * Observes [path] on [object] for changes. This returns an object that can be | 26891 * Observes [path] on [object] for changes. This returns an object that can be |
26892 * used to get the changes and get/set the value at this path. | 26892 * used to get the changes and get/set the value at this path. |
26893 * See [PathObserver.values] and [PathObserver.value]. | 26893 * See [PathObserver.values] and [PathObserver.value]. |
26894 */ | 26894 */ |
26895 PathObserver(this.object, String path) | 26895 PathObserver(this.object, String path) |
26896 : path = path, _isValid = _isPathValid(path) { | 26896 : path = path, _isValid = _isPathValid(path) { |
26897 | 26897 |
26898 // TODO(jmesserly): if the path is empty, or the object is! Observable, we | 26898 // TODO(jmesserly): if the path is empty, or the object is! Observable, we |
26899 // can optimize the PathObserver to be more lightweight. | 26899 // can optimize the PathObserver to be more lightweight. |
26900 | 26900 |
26901 _values = new StreamController.broadcast(onListen: _observe, | 26901 _values = new StreamController.broadcast(sync: true, |
| 26902 onListen: _observe, |
26902 onCancel: _unobserve); | 26903 onCancel: _unobserve); |
26903 | 26904 |
26904 if (_isValid) { | 26905 if (_isValid) { |
26905 var segments = []; | 26906 var segments = []; |
26906 for (var segment in path.trim().split('.')) { | 26907 for (var segment in path.trim().split('.')) { |
26907 if (segment == '') continue; | 26908 if (segment == '') continue; |
26908 var index = int.parse(segment, onError: (_) {}); | 26909 var index = int.parse(segment, onError: (_) {}); |
26909 segments.add(index != null ? index : new Symbol(segment)); | 26910 segments.add(index != null ? index : new Symbol(segment)); |
26910 } | 26911 } |
26911 | 26912 |
(...skipping 2436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
29348 _position = nextPosition; | 29349 _position = nextPosition; |
29349 return true; | 29350 return true; |
29350 } | 29351 } |
29351 _current = null; | 29352 _current = null; |
29352 _position = _array.length; | 29353 _position = _array.length; |
29353 return false; | 29354 return false; |
29354 } | 29355 } |
29355 | 29356 |
29356 T get current => _current; | 29357 T get current => _current; |
29357 } | 29358 } |
OLD | NEW |