| OLD | NEW |
| 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 * Works with KeyboardEvent and KeyEvent to determine how to expose information | 8 * Works with KeyboardEvent and KeyEvent to determine how to expose information |
| 9 * about Key(board)Events. This class functions like an EventListenerList, and | 9 * about Key(board)Events. This class functions like an EventListenerList, and |
| 10 * provides a consistent interface for the Dart | 10 * provides a consistent interface for the Dart |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 if (_callbacks.length == 0) { | 143 if (_callbacks.length == 0) { |
| 144 // If we have no listeners, don't bother keeping track of keypresses. | 144 // If we have no listeners, don't bother keeping track of keypresses. |
| 145 _target.on.keyDown.remove(_keyDown); | 145 _target.on.keyDown.remove(_keyDown); |
| 146 _target.on.keyPress.remove(_keyPress); | 146 _target.on.keyPress.remove(_keyPress); |
| 147 _target.on.keyUp.remove(_keyUp); | 147 _target.on.keyUp.remove(_keyUp); |
| 148 } | 148 } |
| 149 } | 149 } |
| 150 | 150 |
| 151 /** Determine if caps lock is one of the currently depressed keys. */ | 151 /** Determine if caps lock is one of the currently depressed keys. */ |
| 152 bool get _capsLockOn => | 152 bool get _capsLockOn => |
| 153 _keyDownList.some((var element) => element.keyCode == KeyCode.CAPS_LOCK); | 153 _keyDownList.any((var element) => element.keyCode == KeyCode.CAPS_LOCK); |
| 154 | 154 |
| 155 /** | 155 /** |
| 156 * Given the previously recorded keydown key codes, see if we can determine | 156 * Given the previously recorded keydown key codes, see if we can determine |
| 157 * the keycode of this keypress [event]. (Generally browsers only provide | 157 * the keycode of this keypress [event]. (Generally browsers only provide |
| 158 * charCode information for keypress events, but with a little | 158 * charCode information for keypress events, but with a little |
| 159 * reverse-engineering, we can also determine the keyCode.) Returns | 159 * reverse-engineering, we can also determine the keyCode.) Returns |
| 160 * KeyCode.UNKNOWN if the keycode could not be determined. | 160 * KeyCode.UNKNOWN if the keycode could not be determined. |
| 161 */ | 161 */ |
| 162 int _determineKeyCodeForKeypress(KeyboardEvent event) { | 162 int _determineKeyCodeForKeypress(KeyboardEvent event) { |
| 163 // Note: This function is a work in progress. We'll expand this function | 163 // Note: This function is a work in progress. We'll expand this function |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 // pressed, given previous keydown information. | 372 // pressed, given previous keydown information. |
| 373 e._shadowKeyCode = _determineKeyCodeForKeypress(e); | 373 e._shadowKeyCode = _determineKeyCodeForKeypress(e); |
| 374 | 374 |
| 375 // Correct the key value for certain browser-specific quirks. | 375 // Correct the key value for certain browser-specific quirks. |
| 376 if (e._shadowKeyIdentifier != null && | 376 if (e._shadowKeyIdentifier != null && |
| 377 _keyIdentifier.containsKey(e._shadowKeyIdentifier)) { | 377 _keyIdentifier.containsKey(e._shadowKeyIdentifier)) { |
| 378 // This is needed for Safari Windows because it currently doesn't give a | 378 // This is needed for Safari Windows because it currently doesn't give a |
| 379 // keyCode/which for non printable keys. | 379 // keyCode/which for non printable keys. |
| 380 e._shadowKeyCode = _keyIdentifier[e._shadowKeyIdentifier]; | 380 e._shadowKeyCode = _keyIdentifier[e._shadowKeyIdentifier]; |
| 381 } | 381 } |
| 382 e._shadowAltKey = _keyDownList.some((var element) => element.altKey); | 382 e._shadowAltKey = _keyDownList.any((var element) => element.altKey); |
| 383 _dispatch(e); | 383 _dispatch(e); |
| 384 } | 384 } |
| 385 | 385 |
| 386 /** Handle keyup events. */ | 386 /** Handle keyup events. */ |
| 387 void processKeyUp(KeyboardEvent event) { | 387 void processKeyUp(KeyboardEvent event) { |
| 388 var e = new KeyEvent(event); | 388 var e = new KeyEvent(event); |
| 389 KeyboardEvent toRemove = null; | 389 KeyboardEvent toRemove = null; |
| 390 for (var key in _keyDownList) { | 390 for (var key in _keyDownList) { |
| 391 if (key.keyCode == e.keyCode) { | 391 if (key.keyCode == e.keyCode) { |
| 392 toRemove = key; | 392 toRemove = key; |
| 393 } | 393 } |
| 394 } | 394 } |
| 395 if (toRemove != null) { | 395 if (toRemove != null) { |
| 396 _keyDownList = _keyDownList.filter((element) => element != toRemove); | 396 _keyDownList = |
| 397 _keyDownList.where((element) => element != toRemove).toList(); |
| 397 } else if (_keyDownList.length > 0) { | 398 } else if (_keyDownList.length > 0) { |
| 398 // This happens when we've reached some international keyboard case we | 399 // This happens when we've reached some international keyboard case we |
| 399 // haven't accounted for or we haven't correctly eliminated all browser | 400 // haven't accounted for or we haven't correctly eliminated all browser |
| 400 // inconsistencies. Filing bugs on when this is reached is welcome! | 401 // inconsistencies. Filing bugs on when this is reached is welcome! |
| 401 _keyDownList.removeLast(); | 402 _keyDownList.removeLast(); |
| 402 } | 403 } |
| 403 _dispatch(e); | 404 _dispatch(e); |
| 404 } | 405 } |
| 405 } | 406 } |
| OLD | NEW |