| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 * A factory to expose DOM events as Streams. | 110 * A factory to expose DOM events as Streams. |
| 111 */ | 111 */ |
| 112 class EventStreamProvider<T extends Event> { | 112 class EventStreamProvider<T extends Event> { |
| 113 final String _eventType; | 113 final String _eventType; |
| 114 | 114 |
| 115 const EventStreamProvider(this._eventType); | 115 const EventStreamProvider(this._eventType); |
| 116 | 116 |
| 117 /** | 117 /** |
| 118 * Gets a [Stream] for this event type, on the specified target. | 118 * Gets a [Stream] for this event type, on the specified target. |
| 119 * | 119 * |
| 120 * This will always return a broadcast stream so multiple listeners can be |
| 121 * used simultaneously. |
| 122 * |
| 120 * This may be used to capture DOM events: | 123 * This may be used to capture DOM events: |
| 121 * | 124 * |
| 122 * Element.keyDownEvent.forTarget(element, useCapture: true).listen(...); | 125 * Element.keyDownEvent.forTarget(element, useCapture: true).listen(...); |
| 123 * | 126 * |
| 124 * Or for listening to an event which will bubble through the DOM tree: | 127 * Or for listening to an event which will bubble through the DOM tree: |
| 125 * | 128 * |
| 126 * MediaElement.pauseEvent.forTarget(document.body).listen(...); | 129 * MediaElement.pauseEvent.forTarget(document.body).listen(...); |
| 127 * | 130 * |
| 128 * See also: | 131 * See also: |
| 129 * | 132 * |
| (...skipping 26 matching lines...) Expand all Loading... |
| 156 const _CustomEventStreamProvider(this._eventTypeGetter); | 159 const _CustomEventStreamProvider(this._eventTypeGetter); |
| 157 | 160 |
| 158 Stream<T> forTarget(EventTarget e, {bool useCapture: false}) { | 161 Stream<T> forTarget(EventTarget e, {bool useCapture: false}) { |
| 159 return new _EventStream(e, _eventTypeGetter(e), useCapture); | 162 return new _EventStream(e, _eventTypeGetter(e), useCapture); |
| 160 } | 163 } |
| 161 | 164 |
| 162 String getEventType(EventTarget target) { | 165 String getEventType(EventTarget target) { |
| 163 return _eventTypeGetter(target); | 166 return _eventTypeGetter(target); |
| 164 } | 167 } |
| 165 } | 168 } |
| OLD | NEW |