| OLD | NEW |
| 1 /** | 1 /** |
| 2 * A custom KeyboardEvent that attempts to eliminate cross-browser | 2 * A custom KeyboardEvent that attempts to eliminate cross-browser |
| 3 * inconsistencies, and also provide both keyCode and charCode information | 3 * inconsistencies, and also provide both keyCode and charCode information |
| 4 * for all key events (when such information can be determined). | 4 * for all key events (when such information can be determined). |
| 5 * | 5 * |
| 6 * KeyEvent tries to provide a higher level, more polished keyboard event | 6 * KeyEvent tries to provide a higher level, more polished keyboard event |
| 7 * information on top of the "raw" [KeyboardEvent]. | 7 * information on top of the "raw" [KeyboardEvent]. |
| 8 * | 8 * |
| 9 * This class is very much a work in progress, and we'd love to get information | 9 * This class is very much a work in progress, and we'd love to get information |
| 10 * on how we can make this class work with as many international keyboards as | 10 * on how we can make this class work with as many international keyboards as |
| 11 * possible. Bugs welcome! | 11 * possible. Bugs welcome! |
| 12 */ | 12 */ |
| 13 part of html; | 13 part of html; |
| 14 | 14 |
| 15 @Experimental() | |
| 16 class KeyEvent extends _WrappedEvent implements KeyboardEvent { | 15 class KeyEvent extends _WrappedEvent implements KeyboardEvent { |
| 17 /** The parent KeyboardEvent that this KeyEvent is wrapping and "fixing". */ | 16 /** The parent KeyboardEvent that this KeyEvent is wrapping and "fixing". */ |
| 18 KeyboardEvent _parent; | 17 KeyboardEvent _parent; |
| 19 | 18 |
| 20 /** The "fixed" value of whether the alt key is being pressed. */ | 19 /** The "fixed" value of whether the alt key is being pressed. */ |
| 21 bool _shadowAltKey; | 20 bool _shadowAltKey; |
| 22 | 21 |
| 23 /** Caculated value of what the estimated charCode is for this event. */ | 22 /** Caculated value of what the estimated charCode is for this event. */ |
| 24 int _shadowCharCode; | 23 int _shadowCharCode; |
| 25 | 24 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 40 | 39 |
| 41 /** Accessor to the underlying keyCode value is the parent event. */ | 40 /** Accessor to the underlying keyCode value is the parent event. */ |
| 42 int get _realKeyCode => _parent.keyCode; | 41 int get _realKeyCode => _parent.keyCode; |
| 43 | 42 |
| 44 /** Accessor to the underlying charCode value is the parent event. */ | 43 /** Accessor to the underlying charCode value is the parent event. */ |
| 45 int get _realCharCode => _parent.charCode; | 44 int get _realCharCode => _parent.charCode; |
| 46 | 45 |
| 47 /** Accessor to the underlying altKey value is the parent event. */ | 46 /** Accessor to the underlying altKey value is the parent event. */ |
| 48 bool get _realAltKey => _parent.altKey; | 47 bool get _realAltKey => _parent.altKey; |
| 49 | 48 |
| 50 /** Shadows on top of the parent's currentTarget. */ | |
| 51 EventTarget _currentTarget; | |
| 52 | |
| 53 /** Construct a KeyEvent with [parent] as the event we're emulating. */ | 49 /** Construct a KeyEvent with [parent] as the event we're emulating. */ |
| 54 KeyEvent.wrap(KeyboardEvent parent): super(parent) { | 50 KeyEvent(KeyboardEvent parent): super(parent) { |
| 55 _parent = parent; | 51 _parent = parent; |
| 56 _shadowAltKey = _realAltKey; | 52 _shadowAltKey = _realAltKey; |
| 57 _shadowCharCode = _realCharCode; | 53 _shadowCharCode = _realCharCode; |
| 58 _shadowKeyCode = _realKeyCode; | 54 _shadowKeyCode = _realKeyCode; |
| 59 _currentTarget = _parent.currentTarget == null? window : | |
| 60 _parent.currentTarget; | |
| 61 } | 55 } |
| 62 | 56 |
| 63 /** Programmatically create a new KeyEvent (and KeyboardEvent). */ | |
| 64 KeyEvent(String type, | |
| 65 {Window view, bool canBubble: true, bool cancelable: true, int keyCode: 0, | |
| 66 int charCode: 0, int keyLocation: 1, bool ctrlKey: false, | |
| 67 bool altKey: false, bool shiftKey: false, bool metaKey: false, | |
| 68 bool altGraphKey: false, EventTarget currentTarget}) { | |
| 69 _parent = new KeyboardEvent(type, view: view, canBubble: canBubble, | |
| 70 cancelable: cancelable, keyLocation: keyLocation, ctrlKey: ctrlKey, | |
| 71 altKey: altKey, shiftKey: shiftKey, metaKey: metaKey, altGraphKey: | |
| 72 altGraphKey); | |
| 73 _shadowAltKey = altKey; | |
| 74 _shadowCharCode = charCode; | |
| 75 _shadowKeyCode = keyCode; | |
| 76 _currentTarget = currentTarget == null ? window : currentTarget; | |
| 77 } | |
| 78 | |
| 79 /** Accessor to provide a stream of KeyEvents on the desired target. */ | 57 /** Accessor to provide a stream of KeyEvents on the desired target. */ |
| 80 static EventStreamProvider<KeyEvent> keyDownEvent = | 58 static EventStreamProvider<KeyEvent> keyDownEvent = |
| 81 new _KeyboardEventHandler('keydown'); | 59 new _KeyboardEventHandler('keydown'); |
| 82 /** Accessor to provide a stream of KeyEvents on the desired target. */ | 60 /** Accessor to provide a stream of KeyEvents on the desired target. */ |
| 83 static EventStreamProvider<KeyEvent> keyUpEvent = | 61 static EventStreamProvider<KeyEvent> keyUpEvent = |
| 84 new _KeyboardEventHandler('keyup'); | 62 new _KeyboardEventHandler('keyup'); |
| 85 /** Accessor to provide a stream of KeyEvents on the desired target. */ | 63 /** Accessor to provide a stream of KeyEvents on the desired target. */ |
| 86 static EventStreamProvider<KeyEvent> keyPressEvent = | 64 static EventStreamProvider<KeyEvent> keyPressEvent = |
| 87 new _KeyboardEventHandler('keypress'); | 65 new _KeyboardEventHandler('keypress'); |
| 88 | 66 |
| 89 /** The currently registered target for this event. */ | |
| 90 EventTarget get currentTarget => _currentTarget; | |
| 91 | |
| 92 /** True if the altGraphKey is pressed during this event. */ | 67 /** True if the altGraphKey is pressed during this event. */ |
| 93 bool get altGraphKey => _parent.altGraphKey; | 68 bool get altGraphKey => _parent.altGraphKey; |
| 94 /** Accessor to the clipboardData available for this event. */ | 69 /** Accessor to the clipboardData available for this event. */ |
| 95 DataTransfer get clipboardData => _parent.clipboardData; | 70 DataTransfer get clipboardData => _parent.clipboardData; |
| 96 /** True if the ctrl key is pressed during this event. */ | 71 /** True if the ctrl key is pressed during this event. */ |
| 97 bool get ctrlKey => _parent.ctrlKey; | 72 bool get ctrlKey => _parent.ctrlKey; |
| 98 int get detail => _parent.detail; | 73 int get detail => _parent.detail; |
| 99 /** | 74 /** |
| 100 * Accessor to the part of the keyboard that the key was pressed from (one of | 75 * Accessor to the part of the keyboard that the key was pressed from (one of |
| 101 * KeyLocation.STANDARD, KeyLocation.RIGHT, KeyLocation.LEFT, | 76 * KeyLocation.STANDARD, KeyLocation.RIGHT, KeyLocation.LEFT, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 121 throw new UnsupportedError("keyIdentifier is unsupported."); | 96 throw new UnsupportedError("keyIdentifier is unsupported."); |
| 122 } | 97 } |
| 123 void _initKeyboardEvent(String type, bool canBubble, bool cancelable, | 98 void _initKeyboardEvent(String type, bool canBubble, bool cancelable, |
| 124 Window view, String keyIdentifier, int keyLocation, bool ctrlKey, | 99 Window view, String keyIdentifier, int keyLocation, bool ctrlKey, |
| 125 bool altKey, bool shiftKey, bool metaKey, | 100 bool altKey, bool shiftKey, bool metaKey, |
| 126 bool altGraphKey) { | 101 bool altGraphKey) { |
| 127 throw new UnsupportedError( | 102 throw new UnsupportedError( |
| 128 "Cannot initialize a KeyboardEvent from a KeyEvent."); | 103 "Cannot initialize a KeyboardEvent from a KeyEvent."); |
| 129 } | 104 } |
| 130 } | 105 } |
| OLD | NEW |