Chromium Code Reviews| Index: tools/dom/src/KeyboardEventStream.dart |
| diff --git a/tools/dom/src/KeyboardEventStream.dart b/tools/dom/src/KeyboardEventStream.dart |
| index b2917ba0e19522f54d4cfeea9c3829746d8a7f2a..f41ca3d47b1ba3c3ceaa224defe9bb25edb2f97c 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 = []; |
|
Anton Muhin
2013/03/27 13:49:55
that's not quite safe: it should be <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,15 +89,8 @@ 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(String type) : |
| + _type = type, _target = null, super(_EVENT_TYPE) { |
|
Anton Muhin
2013/03/27 13:49:55
do you need explicit initliasation to null? and w
|
| } |
| /** |
| @@ -114,10 +98,8 @@ class _KeyboardEventHandler implements EventStreamProvider<KeyEvent> { |
| * and charcodes when they are not provided. |
| */ |
| _KeyboardEventHandler.initializeAllEventListeners(String type, |
| - EventTarget target) { |
| - _commonInit(type); |
| - _target = target; |
| - _keyDownList = []; |
| + EventTarget target) : |
| + _type = type, _target = target, super(_EVENT_TYPE) { |
|
Anton Muhin
2013/03/27 13:49:55
ditto, this._type, this._target
|
| Element.keyDownEvent.forTarget(_target, useCapture: true).listen( |
| processKeyDown); |
| Element.keyPressEvent.forTarget(_target, useCapture: true).listen( |