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

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

Issue 12907019: KeyboardEventStream: lock it down (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: per antonm 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
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/dom/src/KeyboardEventStream.dart
diff --git a/tools/dom/src/KeyboardEventStream.dart b/tools/dom/src/KeyboardEventStream.dart
index b2917ba0e19522f54d4cfeea9c3829746d8a7f2a..d7fb9b0acf89e45530151331cd028642635fce49 100644
--- a/tools/dom/src/KeyboardEventStream.dart
+++ b/tools/dom/src/KeyboardEventStream.dart
@@ -8,7 +8,7 @@ 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> {
+class _KeyboardEventHandler extends EventStreamProvider<KeyEvent> {
// This code inspired by Closure's KeyHandling library.
// http://closure-library.googlecode.com/svn/docs/closure_goog_events_keyhandler.js.source.html
@@ -16,31 +16,28 @@ class _KeyboardEventHandler implements EventStreamProvider<KeyEvent> {
* 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;
+ List<KeyboardEvent> _keyDownList = <KeyboardEvent>[];
/** The type of KeyEvent we are tracking (keyup, keydown, keypress). */
- String _type;
+ final String _type;
/** The element we are watching for events to happen on. */
- EventTarget _target;
+ final 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];
+ static final int _ROMAN_ALPHABET_OFFSET = "a".codeUnits[0] - "A".codeUnits[0];
/** Controller to produce KeyEvents for the stream. */
- StreamController _controller;
+ final StreamController _controller = new StreamController.broadcast();
- String _eventType = 'KeyEvent';
+ static const _EVENT_TYPE = 'KeyEvent';
/**
* 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 = {
+ static const Map<String, int> _keyIdentifier = const {
'Up': KeyCode.UP,
'Down': KeyCode.DOWN,
'Left': KeyCode.LEFT,
@@ -66,12 +63,6 @@ class _KeyboardEventHandler implements EventStreamProvider<KeyEvent> {
'Insert': KeyCode.INSERT
};
- /**
- * Gets the type of the event which this would listen for on the specified
- * event target.
- */
- String getEventType(EventTarget target) => _eventType;
-
/** Return a stream for KeyEvents for the specified target. */
Stream<KeyEvent> forTarget(EventTarget e, {bool useCapture: false}) {
return new _KeyboardEventHandler.initializeAllEventListeners(
@@ -98,26 +89,17 @@ class _KeyboardEventHandler implements EventStreamProvider<KeyEvent> {
* General constructor, performs basic initialization for our improved
* KeyboardEvent controller.
*/
- _KeyboardEventHandler(String type) {
- _commonInit(type);
- }
-
- void _commonInit(String type) {
- _type = type;
- _controller = new StreamController.broadcast();
- _callbacks = [];
- _target = null;
+ _KeyboardEventHandler(this._type) :
+ _target = null, super(_EVENT_TYPE) {
}
/**
* Hook up all event listeners under the covers so we can estimate keycodes
* and charcodes when they are not provided.
*/
- _KeyboardEventHandler.initializeAllEventListeners(String type,
- EventTarget target) {
- _commonInit(type);
- _target = target;
- _keyDownList = [];
+ _KeyboardEventHandler.initializeAllEventListeners(this._type,
+ EventTarget target) :
+ _target = target, super(_EVENT_TYPE) {
Anton Muhin 2013/03/27 14:00:38 this._target.
kevmoo-old 2013/03/27 14:02:56 Yup!
Element.keyDownEvent.forTarget(_target, useCapture: true).listen(
processKeyDown);
Element.keyPressEvent.forTarget(_target, useCapture: true).listen(
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698