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

Unified Diff: tools/dom/src/KeyboardEventStream.dart

Issue 12419011: Modern-ify KeyEvent handling. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: tools/dom/src/KeyboardEventStream.dart
diff --git a/tools/dom/src/KeyboardEventStream.dart b/tools/dom/src/KeyboardEventStream.dart
new file mode 100644
index 0000000000000000000000000000000000000000..5cb13247511405d9ec468261119552d8909f646c
--- /dev/null
+++ b/tools/dom/src/KeyboardEventStream.dart
@@ -0,0 +1,725 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+part of html;
+
+/**
+ * Internal class that does the actual calculations to determine keyCode and
+ * charCode for keydown, keypress, and keyup events for all browsers.
+ */
+class _KeyboardEventHandler implements EventStreamProvider<KeyEvent> {
+ // This code inspired by Closure's KeyHandling library.
+ // http://closure-library.googlecode.com/svn/docs/closure_goog_events_keyhandler.js.source.html
+
+ /**
+ * The set of keys that have been pressed down without seeing their
+ * corresponding keyup event.
+ */
+ List<KeyboardEvent> _keyDownList;
+
+ /** The set of functions that wish to be notified when a KeyEvent happens. */
+ List<Function> _callbacks;
+
+ /** The type of KeyEvent we are tracking (keyup, keydown, keypress). */
+ String _type;
+
+ /** The element we are watching for events to happen on. */
+ EventTarget _target;
+
+ // The distance to shift from upper case alphabet Roman letters to lower case.
+ final int _ROMAN_ALPHABET_OFFSET = "a".codeUnits[0] - "A".codeUnits[0];
+
+ /** Controller to produce KeyEvents for the stream. */
+ StreamController _controller;
+
+ /**
+ * An enumeration of key identifiers currently part of the W3C draft for DOM3
+ * and their mappings to keyCodes.
+ * http://www.w3.org/TR/DOM-Level-3-Events/keyset.html#KeySet-Set
+ */
+ static Map<String, int> _keyIdentifier = {
+ 'Up': KeyCode.UP,
+ 'Down': KeyCode.DOWN,
+ 'Left': KeyCode.LEFT,
+ 'Right': KeyCode.RIGHT,
+ 'Enter': KeyCode.ENTER,
+ 'F1': KeyCode.F1,
+ 'F2': KeyCode.F2,
+ 'F3': KeyCode.F3,
+ 'F4': KeyCode.F4,
+ 'F5': KeyCode.F5,
+ 'F6': KeyCode.F6,
+ 'F7': KeyCode.F7,
+ 'F8': KeyCode.F8,
+ 'F9': KeyCode.F9,
+ 'F10': KeyCode.F10,
+ 'F11': KeyCode.F11,
+ 'F12': KeyCode.F12,
+ 'U+007F': KeyCode.DELETE,
+ 'Home': KeyCode.HOME,
+ 'End': KeyCode.END,
+ 'PageUp': KeyCode.PAGE_UP,
+ 'PageDown': KeyCode.PAGE_DOWN,
+ 'Insert': KeyCode.INSERT
+ };
+
+ /**
+ * Gets the type of the event which this would listen for on the specified
+ * event target.
+ */
+ String getEventType(EventTarget target) => 'KeyEvent';
+
+ /** Return a stream for KeyEvents for the specified target. */
+ Stream<KeyEvent> forTarget(EventTarget e, {bool useCapture: false}) {
+ _initializeAllEventListeners(e);
+ return _controller.stream;
+ }
+
+ /**
+ * General constructor, performs basic initialization for our improved
+ * KeyboardEvent controller.
+ */
+ _KeyboardEventHandler(String type) {
+ _type = type;
+ _controller = new StreamController.broadcast();
+ _callbacks = [];
+ }
+
+ /**
+ * Hook up all event listeners under the covers so we can estimate keycodes
+ * and charcodes when they are not provided.
+ */
+ _initializeAllEventListeners(EventTarget target) {
+ _target = target;
+ _keyDownList = [];
+ Element.keyDownEvent.forTarget(_target, useCapture: true).listen(
+ processKeyDown);
+ Element.keyPressEvent.forTarget(_target, useCapture: true).listen(
+ processKeyPress);
+ Element.keyUpEvent.forTarget(_target, useCapture: true).listen(
+ processKeyUp);
+ }
+
+ /**
+ * Notify all callback listeners that a KeyEvent of the relevant type has
+ * occurred.
+ */
+ bool _dispatch(KeyEvent event) {
+ if (event.type == _type)
+ _controller.add(event);
+ }
+
+ /** Determine if caps lock is one of the currently depressed keys. */
+ bool get _capsLockOn =>
+ _keyDownList.any((var element) => element.keyCode == KeyCode.CAPS_LOCK);
+
+ /**
+ * Given the previously recorded keydown key codes, see if we can determine
+ * the keycode of this keypress [event]. (Generally browsers only provide
+ * charCode information for keypress events, but with a little
+ * reverse-engineering, we can also determine the keyCode.) Returns
+ * KeyCode.UNKNOWN if the keycode could not be determined.
+ */
+ int _determineKeyCodeForKeypress(KeyboardEvent event) {
+ // Note: This function is a work in progress. We'll expand this function
+ // once we get more information about other keyboards.
+ for (var prevEvent in _keyDownList) {
+ if (prevEvent._shadowCharCode == event.charCode) {
+ return prevEvent.keyCode;
+ }
+ if ((event.shiftKey || _capsLockOn) && event.charCode >= "A".codeUnits[0]
+ && event.charCode <= "Z".codeUnits[0] && event.charCode +
+ _ROMAN_ALPHABET_OFFSET == prevEvent._shadowCharCode) {
+ return prevEvent.keyCode;
+ }
+ }
+ return KeyCode.UNKNOWN;
+ }
+
+ /**
+ * Given the charater code returned from a keyDown [event], try to ascertain
+ * and return the corresponding charCode for the character that was pressed.
+ * This information is not shown to the user, but used to help polyfill
+ * keypress events.
+ */
+ int _findCharCodeKeyDown(KeyboardEvent event) {
+ if (event.keyLocation == 3) { // Numpad keys.
+ switch (event.keyCode) {
+ case KeyCode.NUM_ZERO:
+ // Even though this function returns _charCodes_, for some cases the
+ // KeyCode == the charCode we want, in which case we use the keycode
+ // constant for readability.
+ return KeyCode.ZERO;
+ case KeyCode.NUM_ONE:
+ return KeyCode.ONE;
+ case KeyCode.NUM_TWO:
+ return KeyCode.TWO;
+ case KeyCode.NUM_THREE:
+ return KeyCode.THREE;
+ case KeyCode.NUM_FOUR:
+ return KeyCode.FOUR;
+ case KeyCode.NUM_FIVE:
+ return KeyCode.FIVE;
+ case KeyCode.NUM_SIX:
+ return KeyCode.SIX;
+ case KeyCode.NUM_SEVEN:
+ return KeyCode.SEVEN;
+ case KeyCode.NUM_EIGHT:
+ return KeyCode.EIGHT;
+ case KeyCode.NUM_NINE:
+ return KeyCode.NINE;
+ case KeyCode.NUM_MULTIPLY:
+ return 42; // Char code for *
+ case KeyCode.NUM_PLUS:
+ return 43; // +
+ case KeyCode.NUM_MINUS:
+ return 45; // -
+ case KeyCode.NUM_PERIOD:
+ return 46; // .
+ case KeyCode.NUM_DIVISION:
+ return 47; // /
+ }
+ } else if (event.keyCode >= 65 && event.keyCode <= 90) {
+ // Set the "char code" for key down as the lower case letter. Again, this
+ // will not show up for the user, but will be helpful in estimating
+ // keyCode locations and other information during the keyPress event.
+ return event.keyCode + _ROMAN_ALPHABET_OFFSET;
+ }
+ switch(event.keyCode) {
+ case KeyCode.SEMICOLON:
+ return KeyCode.FF_SEMICOLON;
+ case KeyCode.EQUALS:
+ return KeyCode.FF_EQUALS;
+ case KeyCode.COMMA:
+ return 44; // Ascii value for ,
+ case KeyCode.DASH:
+ return 45; // -
+ case KeyCode.PERIOD:
+ return 46; // .
+ case KeyCode.SLASH:
+ return 47; // /
+ case KeyCode.APOSTROPHE:
+ return 96; // `
+ case KeyCode.OPEN_SQUARE_BRACKET:
+ return 91; // [
+ case KeyCode.BACKSLASH:
+ return 92; // \
+ case KeyCode.CLOSE_SQUARE_BRACKET:
+ return 93; // ]
+ case KeyCode.SINGLE_QUOTE:
+ return 39; // '
+ }
+ return event.keyCode;
+ }
+
+ /**
+ * Returns true if the key fires a keypress event in the current browser.
+ */
+ bool _firesKeyPressEvent(KeyEvent event) {
+ if (!Device.isIE && !Device.isWebKit) {
+ return true;
+ }
+
+ if (Device.userAgent.contains('Mac') && event.altKey) {
+ return KeyCode.isCharacterKey(event.keyCode);
+ }
+
+ // Alt but not AltGr which is represented as Alt+Ctrl.
+ if (event.altKey && !event.ctrlKey) {
+ return false;
+ }
+
+ // Saves Ctrl or Alt + key for IE and WebKit, which won't fire keypress.
+ if (!event.shiftKey &&
+ (_keyDownList.last.keyCode == KeyCode.CTRL ||
+ _keyDownList.last.keyCode == KeyCode.ALT ||
+ Device.userAgent.contains('Mac') &&
+ _keyDownList.last.keyCode == KeyCode.META)) {
+ return false;
+ }
+
+ // Some keys with Ctrl/Shift do not issue keypress in WebKit.
+ if (Device.isWebKit && event.ctrlKey && event.shiftKey && (
+ event.keyCode == KeyCode.BACKSLASH ||
+ event.keyCode == KeyCode.OPEN_SQUARE_BRACKET ||
+ event.keyCode == KeyCode.CLOSE_SQUARE_BRACKET ||
+ event.keyCode == KeyCode.TILDE ||
+ event.keyCode == KeyCode.SEMICOLON || event.keyCode == KeyCode.DASH ||
+ event.keyCode == KeyCode.EQUALS || event.keyCode == KeyCode.COMMA ||
+ event.keyCode == KeyCode.PERIOD || event.keyCode == KeyCode.SLASH ||
+ event.keyCode == KeyCode.APOSTROPHE ||
+ event.keyCode == KeyCode.SINGLE_QUOTE)) {
+ return false;
+ }
+
+ switch (event.keyCode) {
+ case KeyCode.ENTER:
+ // IE9 does not fire keypress on ENTER.
+ return !Device.isIE;
+ case KeyCode.ESC:
+ return !Device.isWebKit;
+ }
+
+ return KeyCode.isCharacterKey(event.keyCode);
+ }
+
+ /**
+ * Normalize the keycodes to the IE KeyCodes (this is what Chrome, IE, and
+ * Opera all use).
+ */
+ int _normalizeKeyCodes(KeyboardEvent event) {
+ // Note: This may change once we get input about non-US keyboards.
+ if (Device.isFirefox) {
+ switch(event.keyCode) {
+ case KeyCode.FF_EQUALS:
+ return KeyCode.EQUALS;
+ case KeyCode.FF_SEMICOLON:
+ return KeyCode.SEMICOLON;
+ case KeyCode.MAC_FF_META:
+ return KeyCode.META;
+ case KeyCode.WIN_KEY_FF_LINUX:
+ return KeyCode.WIN_KEY;
+ }
+ }
+ return event.keyCode;
+ }
+
+ /** Handle keydown events. */
+ void processKeyDown(KeyboardEvent e) {
+ // Ctrl-Tab and Alt-Tab can cause the focus to be moved to another window
+ // before we've caught a key-up event. If the last-key was one of these
+ // we reset the state.
+ if (_keyDownList.length > 0 &&
+ (_keyDownList.last.keyCode == KeyCode.CTRL && !e.ctrlKey ||
+ _keyDownList.last.keyCode == KeyCode.ALT && !e.altKey ||
+ Device.userAgent.contains('Mac') &&
+ _keyDownList.last.keyCode == KeyCode.META && !e.metaKey)) {
+ _keyDownList = [];
+ }
+
+ var event = new KeyEvent(e);
+ event._shadowKeyCode = _normalizeKeyCodes(event);
+ // Technically a "keydown" event doesn't have a charCode. This is
+ // calculated nonetheless to provide us with more information in giving
+ // as much information as possible on keypress about keycode and also
+ // charCode.
+ event._shadowCharCode = _findCharCodeKeyDown(event);
+ if (_keyDownList.length > 0 && event.keyCode != _keyDownList.last.keyCode &&
+ !_firesKeyPressEvent(event)) {
+ // Some browsers have quirks not firing keypress events where all other
+ // browsers do. This makes them more consistent.
+ processKeyPress(event);
+ }
+ _keyDownList.add(event);
+ _dispatch(event);
+ }
+
+ /** Handle keypress events. */
+ void processKeyPress(KeyboardEvent event) {
+ var e = new KeyEvent(event);
+ // IE reports the character code in the keyCode field for keypress events.
+ // There are two exceptions however, Enter and Escape.
+ if (Device.isIE) {
+ if (e.keyCode == KeyCode.ENTER || e.keyCode == KeyCode.ESC) {
+ e._shadowCharCode = 0;
+ } else {
+ e._shadowCharCode = e.keyCode;
+ }
+ } else if (Device.isOpera) {
+ // Opera reports the character code in the keyCode field.
+ e._shadowCharCode = KeyCode.isCharacterKey(e.keyCode) ? e.keyCode : 0;
+ }
+ // Now we guestimate about what the keycode is that was actually
+ // pressed, given previous keydown information.
+ e._shadowKeyCode = _determineKeyCodeForKeypress(e);
+
+ // Correct the key value for certain browser-specific quirks.
+ if (e._shadowKeyIdentifier != null &&
+ _keyIdentifier.containsKey(e._shadowKeyIdentifier)) {
+ // This is needed for Safari Windows because it currently doesn't give a
+ // keyCode/which for non printable keys.
+ e._shadowKeyCode = _keyIdentifier[e._shadowKeyIdentifier];
+ }
+ e._shadowAltKey = _keyDownList.any((var element) => element.altKey);
+ _dispatch(e);
+ }
+
+ /** Handle keyup events. */
+ void processKeyUp(KeyboardEvent event) {
+ var e = new KeyEvent(event);
+ KeyboardEvent toRemove = null;
+ for (var key in _keyDownList) {
+ if (key.keyCode == e.keyCode) {
+ toRemove = key;
+ }
+ }
+ if (toRemove != null) {
+ _keyDownList =
+ _keyDownList.where((element) => element != toRemove).toList();
+ } else if (_keyDownList.length > 0) {
+ // This happens when we've reached some international keyboard case we
+ // haven't accounted for or we haven't correctly eliminated all browser
+ // inconsistencies. Filing bugs on when this is reached is welcome!
+ _keyDownList.removeLast();
+ }
+ _dispatch(e);
+ }
+}
+
+
+/**
+ * Records KeyboardEvents that occur on a particular element, and provides a
+ * stream of outgoing KeyEvents with cross-browser consistent keyCode and
+ * charCode values despite the fact that a multitude of browsers that have
+ * varying keyboard default behavior.
+ *
+ * Example usage:
+ *
+ * new KeyboardEventStream.onKeyDown(document.body).listen(
+ * keydownHandlerTest);
+ *
+ * This class is very much a work in progress, and we'd love to get information
+ * on how we can make this class work with as many international keyboards as
+ * possible. Bugs welcome!
+ */
+class KeyboardEventStream implements Stream<KeyEvent> {
+ _KeyboardEventHandler _handler;
+ Stream<KeyEvent> _stream;
+
+ /** Named constructor to produce a stream for onKeyPress events. */
+ KeyboardEventStream.onKeyPress(EventTarget target) {
+ _handler = new _KeyboardEventHandler('keypress');
+ _stream = _handler.forTarget(target);
+ }
+
+ /** Named constructor to produce a stream for onKeyUp events. */
+ KeyboardEventStream.onKeyUp(EventTarget target) {
+ _handler = new _KeyboardEventHandler('keyup');
+ _stream = _handler.forTarget(target);
+ }
+
+ /** Named constructor to produce a stream for onKeyDown events. */
+ KeyboardEventStream.onKeyDown(EventTarget target) {
+ _handler = new _KeyboardEventHandler('keydown');
+ _stream = _handler.forTarget(target);
+ }
+
+ /**
+ * Unlike regular KeyboardEvents, you can programmatically add KeyEvents to
+ * this stream. Be careful, though! If you add a keyDown event without a
+ * corresponding keyUp event later, the stream may have difficulty estimating
+ * future key codes.
+ */
+ void addKeyDown(KeyEvent e) {
+ _handler.processKeyDown(e);
+ }
+
+ /**
+ * Unlike regular KeyboardEvents, you can programmatically add KeyEvents to
+ * this stream. Be careful, though! If you add a keyUp event without a
+ * corresponding keyDown event previously, the stream may have difficulty
+ * estimating future key codes.
+ */
+ void addKeyUp(KeyEvent e) {
+ _handler.processKeyUp(e);
+ }
+
+ /**
+ * Unlike regular KeyboardEvents, you can programmatically add KeyEvents to
+ * this stream.
+ */
+ void addKeyPress(KeyEvent e) {
+ _handler.processKeyPress(e);
+ }
+
+ // ---------------- Stream implementation methods: ---------------
+ /**
+ * Adds a subscription to this stream.
+ *
+ * On each data event from this stream, the subscriber's [onData] handler
+ * is called. If [onData] is null, nothing happens.
+ *
+ * On errors from this stream, the [onError] handler is given a
+ * [AsyncError] object describing the error.
+ *
+ * If this stream closes, the [onDone] handler is called.
+ *
+ * If [unsubscribeOnError] is true, the subscription is ended when
+ * the first error is reported. The default is false.
+ */
+ StreamSubscription<KeyEvent> listen(void onData(KeyEvent event),
+ {void onError(AsyncError error), void onDone(),
+ bool unsubscribeOnError}) => _stream.listen(onData, onError:
+ onError, onDone: onDone, unsubscribeOnError: unsubscribeOnError);
+
+ /**
+ * Reports whether this stream is a broadcast stream.
+ */
+ bool get isBroadcast => _stream.isBroadcast;
+
+ /** Counts the elements in the stream. */
+ Future<int> get length => _stream.length;
+
+ /** Reports whether this stream contains any elements. */
+ Future<bool> get isEmpty => _stream.isEmpty;
+
+ /**
+ * Returns the first element.
+ *
+ * If [this] is empty throws a [StateError]. Otherwise this method is
+ * equivalent to [:this.elementAt(0):]
+ */
+ Future<KeyEvent> get first => _stream.first;
+
+ /**
+ * Returns the last element.
+ *
+ * If [this] is empty throws a [StateError].
+ */
+ Future<KeyEvent> get last => _stream.last;
+
+ /**
+ * Returns the single element.
+ *
+ * If [this] is empty or has more than one element throws a [StateError].
+ */
+ Future<KeyEvent> get single => _stream.single;
+
+ /**
+ * Creates a new stream from this stream that converts each element
+ * into zero or more events.
+ *
+ * Each incoming event is converted to an [Iterable] of new events,
+ * and each of these new events are then sent by the returned stream
+ * in order.
+ */
+ Stream<dynamic> expand(Iterable convert(KeyEvent value)) =>
+ _stream.expand(convert);
+
+ /**
+ * Chains this stream as the input of the provided [StreamTransformer].
+ *
+ * Returns the result of [:streamTransformer.bind:] itself.
+ */
+ Stream<dynamic> transform(StreamTransformer<KeyEvent, dynamic>
+ streamTransformer) => _stream.transform(streamTransformer);
+
+ /**
+ * Checks whether [test] accepts any element provided by this stream.
+ *
+ * Completes the [Future] when the answer is known.
+ * If this stream reports an error, the [Future] will report that error.
+ */
+ Future<bool> any(bool test(KeyEvent element)) => _stream.any(test);
+
+ /**
+ * Returns a multi-subscription stream that produces the same events as this.
+ *
+ * If this stream is single-subscription, return a new stream that allows
+ * multiple subscribers. It will subscribe to this stream when its first
+ * subscriber is added, and unsubscribe again when the last subscription is
+ * cancelled.
+ *
+ * If this stream is already a broadcast stream, it is returned unmodified.
+ */
+ Stream<KeyEvent> asBroadcastStream() => _stream;
+
+ /**
+ * Checks whether [match] occurs in the elements provided by this stream.
+ *
+ * Completes the [Future] when the answer is known.
+ * If this stream reports an error, the [Future] will report that error.
+ */
+ Future<bool> contains(KeyEvent match) => _stream.contains(match);
+
+ /**
+ * Skips data events if they are equal to the previous data event.
+ *
+ * The returned stream provides the same events as this stream, except
+ * that it never provides two consequtive data events that are equal.
+ *
+ * Equality is determined by the provided [equals] method. If that is
+ * omitted, the '==' operator on the last provided data element is used.
+ */
+ Stream<KeyEvent> distinct([bool equals(KeyEvent previous, KeyEvent next)]) =>
+ _stream.distinct(equals);
+
+ /**
+ * Returns the value of the [index]th data event of this stream.
+ *
+ * If an error event occurs, the future will end with this error.
+ *
+ * If this stream provides fewer than [index] elements before closing,
+ * an error is reported.
+ */
+ Future<KeyEvent> elementAt(int index) => _stream.elementAt(index);
+
+ /**
+ * Checks whether [test] accepts all elements provided by this stream.
+ *
+ * Completes the [Future] when the answer is known.
+ * If this stream reports an error, the [Future] will report that error.
+ */
+ Future<bool> every(bool test(KeyEvent element)) =>
+ _stream.every(test);
+
+ /**
+ * Finds the first element of this stream matching [test].
+ *
+ * Returns a future that is filled with the first element of this stream
+ * that [test] returns true for.
+ *
+ * If no such element is found before this stream is done, and a
+ * [defaultValue] function is provided, the result of calling [defaultValue]
+ * becomes the value of the future.
+ *
+ * If an error occurs, or if this stream ends without finding a match and
+ * with no [defaultValue] function provided, the future will receive an
+ * error.
+ */
+ Future<KeyEvent> firstWhere(bool test(KeyEvent value),
+ {KeyEvent defaultValue()}) => _stream.firstWhere(test);
+
+ /**
+ * Creates a wrapper Stream that intercepts some errors from this stream.
+ *
+ * If this stream sends an error that matches [test], then it is intercepted
+ * by the [handle] function.
+ *
+ * An [AsyncError] [:e:] is matched by a test function if [:test(e):] returns
+ * true. If [test] is omitted, every error is considered matching.
+ *
+ * If the error is intercepted, the [handle] function can decide what to do
+ * with it. It can throw if it wants to raise a new (or the same) error,
+ * or simply return to make the stream forget the error.
+ *
+ * If you need to transform an error into a data event, use the more generic
+ * [Stream.transformEvent] to handle the event by writing a data event to
+ * the output sink
+ */
+ Stream<KeyEvent> handleError(void handle(AsyncError error),
+ {bool test(error)}) => _stream.handleError(handle);
+
+ /**
+ * Finds the last element in this stream matching [test].
+ *
+ * As [firstWhere], except that the last matching element is found.
+ * That means that the result cannot be provided before this stream
+ * is done.
+ */
+ Future<KeyEvent> lastWhere(bool test(KeyEvent value),
+ {KeyEvent defaultValue()}) => _stream.lastWhere(test);
+
+ /**
+ * Creates a new stream that converts each element of this stream
+ * to a new value using the [convert] function.
+ */
+ Stream map(convert(KeyEvent event)) => _stream.map(convert);
+
+ /**
+ * Finds the largest element in the stream.
+ *
+ * If the stream is empty, the result is [:null:].
+ * Otherwise the result is an value from the stream that is not smaller
+ * than any other value from the stream (according to [compare], which must
+ * be a [Comparator]).
+ *
+ * If [compare] is omitted, it defaults to [Comparable.compare].
+ *
+ * *Deprecated*. Use [reduce] with a binary max method if needed.
+ */
+ Future<KeyEvent> max([int compare(KeyEvent a, KeyEvent b)]) =>
+ _stream.max(compare);
+
+ /**
+ * Finds the least element in the stream.
+ *
+ * If the stream is empty, the result is [:null:].
+ * Otherwise the result is a value from the stream that is not greater
+ * than any other value from the stream (according to [compare], which must
+ * be a [Comparator]).
+ *
+ * If [compare] is omitted, it defaults to [Comparable.compare].
+ *
+ * *Deprecated*. Use [reduce] with a binary min method if needed.
+ */
+ Future<KeyEvent> min([int compare(KeyEvent a, KeyEvent b)]) =>
+ _stream.min(compare);
+
+ /**
+ * Binds this stream as the input of the provided [StreamConsumer].
+ */
+ Future pipe(StreamConsumer<KeyEvent, dynamic> streamConsumer) =>
+ _stream.pipe(streamConsumer);
+
+ Future pipeInto(EventSink<KeyEvent> sink, {void onError(AsyncError error),
+ bool unsubscribeOnError}) => _stream.pipeInto(sink, onError:
+ onError, unsubscribeOnError: unsubscribeOnError);
+
+ /** Reduces a sequence of values by repeatedly applying [combine]. */
+ Future reduce(initialValue, combine(previous, KeyEvent element)) =>
+ _stream.reduce(initialValue, combine);
+
+ /**
+ * Finds the single element in this stream matching [test].
+ *
+ * Like [lastMatch], except that it is an error if more than one
+ * matching element occurs in the stream.
+ */
+ Future<KeyEvent> singleWhere(bool test(KeyEvent value)) =>
+ _stream.singleWhere(test);
+
+ /**
+ * Skips the first [count] data events from this stream.
+ */
+ Stream<KeyEvent> skip(int count) => _stream.skip(count);
+
+ /**
+ * Skip data events from this stream while they are matched by [test].
+ *
+ * Error and done events are provided by the returned stream unmodified.
+ *
+ * Starting with the first data event where [test] returns true for the
+ * event data, the returned stream will have the same events as this stream.
+ */
+ Stream<KeyEvent> skipWhile(bool test(KeyEvent value)) =>
+ _stream.skipWhile(test);
+
+ /**
+ * Provides at most the first [n] values of this stream.
+ *
+ * Forwards the first [n] data events of this stream, and all error
+ * events, to the returned stream, and ends with a done event.
+ *
+ * If this stream produces fewer than [count] values before it's done,
+ * so will the returned stream.
+ */
+ Stream<KeyEvent> take(int count) => _stream.take(count);
+
+ /**
+ * Forwards data events while [test] is successful.
+ *
+ * The returned stream provides the same events as this stream as long
+ * as [test] returns [:true:] for the event data. The stream is done
+ * when either this stream is done, or when this stream first provides
+ * a value that [test] doesn't accept.
+ */
+ Stream<KeyEvent> takeWhile(bool test(KeyEvent value)) =>
+ _stream.takeWhile(test);
+
+ /** Collects the data of this stream in a [List]. */
+ Future<List<KeyEvent>> toList() => _stream.toList();
+
+ /** Collects the data of this stream in a [Set]. */
+ Future<Set<KeyEvent>> toSet() => _stream.toSet();
+
+ /**
+ * Creates a new stream from this stream that discards some data events.
+ *
+ * The new stream sends the same error and done events as this stream,
+ * but it only sends the data events that satisfy the [test].
+ */
+ Stream<KeyEvent> where(bool test(KeyEvent event)) =>
+ _stream.where(test);
+}

Powered by Google App Engine
This is Rietveld 408576698