| 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 14 matching lines...) Expand all Loading... |
| 25 */ | 25 */ |
| 26 List<KeyboardEvent> _keyDownList; | 26 List<KeyboardEvent> _keyDownList; |
| 27 | 27 |
| 28 /** The set of functions that wish to be notified when a KeyEvent happens. */ | 28 /** The set of functions that wish to be notified when a KeyEvent happens. */ |
| 29 List<Function> _callbacks; | 29 List<Function> _callbacks; |
| 30 | 30 |
| 31 /** The type of KeyEvent we are tracking (keyup, keydown, keypress). */ | 31 /** The type of KeyEvent we are tracking (keyup, keydown, keypress). */ |
| 32 String _type; | 32 String _type; |
| 33 | 33 |
| 34 /** The element we are watching for events to happen on. */ | 34 /** The element we are watching for events to happen on. */ |
| 35 EventTarget _target; | 35 Element _target; |
| 36 | 36 |
| 37 // The distance to shift from upper case alphabet Roman letters to lower case. | 37 // The distance to shift from upper case alphabet Roman letters to lower case. |
| 38 final int _ROMAN_ALPHABET_OFFSET = "a".charCodes[0] - "A".charCodes[0]; | 38 final int _ROMAN_ALPHABET_OFFSET = "a".charCodes[0] - "A".charCodes[0]; |
| 39 | 39 |
| 40 // Instance members referring to the internal event handlers because closures | 40 // Instance members referring to the internal event handlers because closures |
| 41 // are not hashable. | 41 // are not hashable. |
| 42 var _keyUp, _keyDown, _keyPress; | 42 var _keyUp, _keyDown, _keyPress; |
| 43 | 43 |
| 44 /** | 44 /** |
| 45 * An enumeration of key identifiers currently part of the W3C draft for DOM3 | 45 * An enumeration of key identifiers currently part of the W3C draft for DOM3 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 | 84 |
| 85 /** Named constructor to add an onKeyDown event listener to our handler. */ | 85 /** Named constructor to add an onKeyDown event listener to our handler. */ |
| 86 KeyboardEventController.keydown(EventTarget target) { | 86 KeyboardEventController.keydown(EventTarget target) { |
| 87 _KeyboardEventController(target, 'keydown'); | 87 _KeyboardEventController(target, 'keydown'); |
| 88 } | 88 } |
| 89 | 89 |
| 90 /** | 90 /** |
| 91 * General constructor, performs basic initialization for our improved | 91 * General constructor, performs basic initialization for our improved |
| 92 * KeyboardEvent controller. | 92 * KeyboardEvent controller. |
| 93 */ | 93 */ |
| 94 _KeyboardEventController(EventTarget target, String type) { | 94 _KeyboardEventController(Element target, String type) { |
| 95 _callbacks = []; | 95 _callbacks = []; |
| 96 _type = type; | 96 _type = type; |
| 97 _target = target; | 97 _target = target; |
| 98 _keyDown = processKeyDown; | 98 _keyDown = processKeyDown; |
| 99 _keyUp = processKeyUp; | 99 _keyUp = processKeyUp; |
| 100 _keyPress = processKeyPress; | 100 _keyPress = processKeyPress; |
| 101 } | 101 } |
| 102 | 102 |
| 103 /** | 103 /** |
| 104 * Hook up all event listeners under the covers so we can estimate keycodes | 104 * Hook up all event listeners under the covers so we can estimate keycodes |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 _keyDownList = _keyDownList.filter((element) => element != toRemove); | 396 _keyDownList = _keyDownList.filter((element) => element != toRemove); |
| 397 } else if (_keyDownList.length > 0) { | 397 } else if (_keyDownList.length > 0) { |
| 398 // This happens when we've reached some international keyboard case we | 398 // This happens when we've reached some international keyboard case we |
| 399 // haven't accounted for or we haven't correctly eliminated all browser | 399 // haven't accounted for or we haven't correctly eliminated all browser |
| 400 // inconsistencies. Filing bugs on when this is reached is welcome! | 400 // inconsistencies. Filing bugs on when this is reached is welcome! |
| 401 _keyDownList.removeLast(); | 401 _keyDownList.removeLast(); |
| 402 } | 402 } |
| 403 _dispatch(e); | 403 _dispatch(e); |
| 404 } | 404 } |
| 405 } | 405 } |
| OLD | NEW |