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

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

Issue 1894713002: Strong html (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: ptal Created 4 years, 8 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
« no previous file with comments | « tools/dom/src/EventStreamProvider.dart ('k') | tools/dom/src/NodeValidatorBuilder.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 */
11 class _KeyboardEventHandler extends EventStreamProvider<KeyEvent> { 11 class _KeyboardEventHandler extends EventStreamProvider<KeyEvent> {
12 // This code inspired by Closure's KeyHandling library. 12 // This code inspired by Closure's KeyHandling library.
13 // http://closure-library.googlecode.com/svn/docs/closure_goog_events_keyhandl er.js.source.html 13 // http://closure-library.googlecode.com/svn/docs/closure_goog_events_keyhandl er.js.source.html
14 14
15 /** 15 /**
16 * The set of keys that have been pressed down without seeing their 16 * The set of keys that have been pressed down without seeing their
17 * corresponding keyup event. 17 * corresponding keyup event.
18 */ 18 */
19 final List<KeyboardEvent> _keyDownList = <KeyboardEvent>[]; 19 final List<KeyEvent> _keyDownList = <KeyEvent>[];
20 20
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
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 CustomStream<KeyEvent> forTarget(EventTarget e, {bool useCapture: false}) { 68 CustomStream<KeyEvent> forTarget(EventTarget e, {bool useCapture: false}) {
69 var handler = new _KeyboardEventHandler.initializeAllEventListeners( 69 var handler = new _KeyboardEventHandler.initializeAllEventListeners(
70 _type, e); 70 _type, e);
71 return handler._stream; 71 return handler._stream;
72 } 72 }
73 73
74 /** 74 /**
75 * General constructor, performs basic initialization for our improved 75 * General constructor, performs basic initialization for our improved
76 * KeyboardEvent controller. 76 * KeyboardEvent controller.
77 */ 77 */
78 _KeyboardEventHandler(this._type): super(_EVENT_TYPE), 78 _KeyboardEventHandler(this._type):
79 _stream = new _CustomKeyEventStreamImpl('event'), _target = null; 79 _stream = new _CustomKeyEventStreamImpl('event'), _target = null,
80 super(_EVENT_TYPE);
80 81
81 /** 82 /**
82 * Hook up all event listeners under the covers so we can estimate keycodes 83 * Hook up all event listeners under the covers so we can estimate keycodes
83 * and charcodes when they are not provided. 84 * and charcodes when they are not provided.
84 */ 85 */
85 _KeyboardEventHandler.initializeAllEventListeners(this._type, this._target) : 86 _KeyboardEventHandler.initializeAllEventListeners(this._type, this._target) :
86 super(_EVENT_TYPE) { 87 super(_EVENT_TYPE) {
87 Element.keyDownEvent.forTarget(_target, useCapture: true).listen( 88 Element.keyDownEvent.forTarget(_target, useCapture: true).listen(
88 processKeyDown); 89 processKeyDown);
89 Element.keyPressEvent.forTarget(_target, useCapture: true).listen( 90 Element.keyPressEvent.forTarget(_target, useCapture: true).listen(
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 new _KeyboardEventHandler('keypress').forTarget(target); 373 new _KeyboardEventHandler('keypress').forTarget(target);
373 374
374 /** Named constructor to produce a stream for onKeyUp events. */ 375 /** Named constructor to produce a stream for onKeyUp events. */
375 static CustomStream<KeyEvent> onKeyUp(EventTarget target) => 376 static CustomStream<KeyEvent> onKeyUp(EventTarget target) =>
376 new _KeyboardEventHandler('keyup').forTarget(target); 377 new _KeyboardEventHandler('keyup').forTarget(target);
377 378
378 /** Named constructor to produce a stream for onKeyDown events. */ 379 /** Named constructor to produce a stream for onKeyDown events. */
379 static CustomStream<KeyEvent> onKeyDown(EventTarget target) => 380 static CustomStream<KeyEvent> onKeyDown(EventTarget target) =>
380 new _KeyboardEventHandler('keydown').forTarget(target); 381 new _KeyboardEventHandler('keydown').forTarget(target);
381 } 382 }
OLDNEW
« no previous file with comments | « tools/dom/src/EventStreamProvider.dart ('k') | tools/dom/src/NodeValidatorBuilder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698