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

Side by Side Diff: tools/dom/src/KeyboardEventStream.dart

Issue 16125005: Make new StreamController be async by default. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 * Internal class that does the actual calculations to determine keyCode and 8 * Internal class that does the actual calculations to determine keyCode and
9 * charCode for keydown, keypress, and keyup events for all browsers. 9 * charCode for keydown, keypress, and keyup events for all browsers.
10 */ 10 */
(...skipping 10 matching lines...) Expand all
21 /** The type of KeyEvent we are tracking (keyup, keydown, keypress). */ 21 /** The type of KeyEvent we are tracking (keyup, keydown, keypress). */
22 final String _type; 22 final String _type;
23 23
24 /** The element we are watching for events to happen on. */ 24 /** The element we are watching for events to happen on. */
25 final EventTarget _target; 25 final EventTarget _target;
26 26
27 // The distance to shift from upper case alphabet Roman letters to lower case. 27 // The distance to shift from upper case alphabet Roman letters to lower case.
28 static final int _ROMAN_ALPHABET_OFFSET = "a".codeUnits[0] - "A".codeUnits[0]; 28 static final int _ROMAN_ALPHABET_OFFSET = "a".codeUnits[0] - "A".codeUnits[0];
29 29
30 /** Controller to produce KeyEvents for the stream. */ 30 /** Controller to produce KeyEvents for the stream. */
31 final StreamController _controller = new StreamController(); 31 final StreamController _controller = new StreamController(sync: true);
32 32
33 static const _EVENT_TYPE = 'KeyEvent'; 33 static const _EVENT_TYPE = 'KeyEvent';
34 34
35 /** 35 /**
36 * An enumeration of key identifiers currently part of the W3C draft for DOM3 36 * An enumeration of key identifiers currently part of the W3C draft for DOM3
37 * and their mappings to keyCodes. 37 * and their mappings to keyCodes.
38 * http://www.w3.org/TR/DOM-Level-3-Events/keyset.html#KeySet-Set 38 * http://www.w3.org/TR/DOM-Level-3-Events/keyset.html#KeySet-Set
39 */ 39 */
40 static const Map<String, int> _keyIdentifier = const { 40 static const Map<String, int> _keyIdentifier = const {
41 'Up': KeyCode.UP, 41 'Up': KeyCode.UP,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 * KeyboardEvent controller. 90 * KeyboardEvent controller.
91 */ 91 */
92 _KeyboardEventHandler(this._type) : 92 _KeyboardEventHandler(this._type) :
93 _target = null, super(_EVENT_TYPE) { 93 _target = null, super(_EVENT_TYPE) {
94 } 94 }
95 95
96 /** 96 /**
97 * Hook up all event listeners under the covers so we can estimate keycodes 97 * Hook up all event listeners under the covers so we can estimate keycodes
98 * and charcodes when they are not provided. 98 * and charcodes when they are not provided.
99 */ 99 */
100 _KeyboardEventHandler.initializeAllEventListeners(this._type, this._target) : 100 _KeyboardEventHandler.initializeAllEventListeners(this._type, this._target) :
101 super(_EVENT_TYPE) { 101 super(_EVENT_TYPE) {
102 Element.keyDownEvent.forTarget(_target, useCapture: true).listen( 102 Element.keyDownEvent.forTarget(_target, useCapture: true).listen(
103 processKeyDown); 103 processKeyDown);
104 Element.keyPressEvent.forTarget(_target, useCapture: true).listen( 104 Element.keyPressEvent.forTarget(_target, useCapture: true).listen(
105 processKeyPress); 105 processKeyPress);
106 Element.keyUpEvent.forTarget(_target, useCapture: true).listen( 106 Element.keyUpEvent.forTarget(_target, useCapture: true).listen(
107 processKeyUp); 107 processKeyUp);
108 } 108 }
109 109
110 /** 110 /**
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 new _KeyboardEventHandler('keypress').forTarget(target); 395 new _KeyboardEventHandler('keypress').forTarget(target);
396 396
397 /** Named constructor to produce a stream for onKeyUp events. */ 397 /** Named constructor to produce a stream for onKeyUp events. */
398 static Stream<KeyEvent> onKeyUp(EventTarget target) => 398 static Stream<KeyEvent> onKeyUp(EventTarget target) =>
399 new _KeyboardEventHandler('keyup').forTarget(target); 399 new _KeyboardEventHandler('keyup').forTarget(target);
400 400
401 /** Named constructor to produce a stream for onKeyDown events. */ 401 /** Named constructor to produce a stream for onKeyDown events. */
402 static Stream<KeyEvent> onKeyDown(EventTarget target) => 402 static Stream<KeyEvent> onKeyDown(EventTarget target) =>
403 new _KeyboardEventHandler('keydown').forTarget(target); 403 new _KeyboardEventHandler('keydown').forTarget(target);
404 } 404 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698