| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 part of html; | 5 part of html; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Adapter for exposing DOM events as Dart streams. | 8 * Adapter for exposing DOM events as Dart streams. |
| 9 */ | 9 */ |
| 10 class _EventStream<T extends Event> extends Stream<T> { | 10 class _EventStream<T extends Event> extends Stream<T> { |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 EventTarget _target; | 213 EventTarget _target; |
| 214 final String _eventType; | 214 final String _eventType; |
| 215 var _onData; | 215 var _onData; |
| 216 final bool _useCapture; | 216 final bool _useCapture; |
| 217 | 217 |
| 218 _EventStreamSubscription(this._target, this._eventType, onData, | 218 _EventStreamSubscription(this._target, this._eventType, onData, |
| 219 this._useCapture) : _onData = _wrapZone(onData) { | 219 this._useCapture) : _onData = _wrapZone(onData) { |
| 220 _tryResume(); | 220 _tryResume(); |
| 221 } | 221 } |
| 222 | 222 |
| 223 static _wrapZone(callback) { |
| 224 // For performance reasons avoid wrapping if we are in the root zone. |
| 225 if (Zone.current == Zone.ROOT) return callback; |
| 226 return Zone.current.bindUnaryCallback(callback, runGuarded: true); |
| 227 } |
| 228 |
| 223 void cancel() { | 229 void cancel() { |
| 224 if (_canceled) return; | 230 if (_canceled) return; |
| 225 | 231 |
| 226 _unlisten(); | 232 _unlisten(); |
| 227 // Clear out the target to indicate this is complete. | 233 // Clear out the target to indicate this is complete. |
| 228 _target = null; | 234 _target = null; |
| 229 _onData = null; | 235 _onData = null; |
| 230 } | 236 } |
| 231 | 237 |
| 232 bool get _canceled => _target == null; | 238 bool get _canceled => _target == null; |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 | 388 |
| 383 ElementStream<T> _forElementList(ElementList e, | 389 ElementStream<T> _forElementList(ElementList e, |
| 384 {bool useCapture: false}) { | 390 {bool useCapture: false}) { |
| 385 return new _ElementListEventStreamImpl(e, _eventTypeGetter(e), useCapture); | 391 return new _ElementListEventStreamImpl(e, _eventTypeGetter(e), useCapture); |
| 386 } | 392 } |
| 387 | 393 |
| 388 String getEventType(EventTarget target) { | 394 String getEventType(EventTarget target) { |
| 389 return _eventTypeGetter(target); | 395 return _eventTypeGetter(target); |
| 390 } | 396 } |
| 391 } | 397 } |
| OLD | NEW |