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..bf359241afe8f070457c57d679ce562ac71542f6 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; |
|
Emily Fortuna
2013/03/27 17:26:41
thank you!
|
| + final 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,16 @@ 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, this._target) : |
|
Emily Fortuna
2013/03/27 17:26:41
this._type (d'oh!)
|
| + super(_EVENT_TYPE) { |
|
Emily Fortuna
2013/03/27 17:26:41
tab alert! convert this to spaces, please.
|
| Element.keyDownEvent.forTarget(_target, useCapture: true).listen( |
| processKeyDown); |
| Element.keyPressEvent.forTarget(_target, useCapture: true).listen( |
| @@ -320,7 +301,7 @@ class _KeyboardEventHandler implements EventStreamProvider<KeyEvent> { |
| _keyDownList.last.keyCode == KeyCode.ALT && !e.altKey || |
| Device.userAgent.contains('Mac') && |
| _keyDownList.last.keyCode == KeyCode.META && !e.metaKey)) { |
| - _keyDownList = []; |
| + _keyDownList.clear(); |
| } |
| var event = new KeyEvent(e); |
| @@ -380,8 +361,7 @@ class _KeyboardEventHandler implements EventStreamProvider<KeyEvent> { |
| } |
| } |
| if (toRemove != null) { |
| - _keyDownList = |
| - _keyDownList.where((element) => element != toRemove).toList(); |
| + _keyDownList.removeWhere((element) => element == toRemove); |
| } 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 |