| 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 |
| 7 * information on top of the "raw" [KeyboardEvent]. |
| 8 * |
| 6 * 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 |
| 7 * 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 |
| 8 * possible. Bugs welcome! | 11 * possible. Bugs welcome! |
| 9 */ | 12 */ |
| 10 class KeyEvent implements KeyboardEvent { | 13 class KeyEvent implements KeyboardEvent { |
| 11 /** The parent KeyboardEvent that this KeyEvent is wrapping and "fixing". */ | 14 /** The parent KeyboardEvent that this KeyEvent is wrapping and "fixing". */ |
| 12 KeyboardEvent _parent; | 15 KeyboardEvent _parent; |
| 13 | 16 |
| 14 /** The "fixed" value of whether the alt key is being pressed. */ | 17 /** The "fixed" value of whether the alt key is being pressed. */ |
| 15 bool _shadowAltKey; | 18 bool _shadowAltKey; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 34 | 37 |
| 35 /** Accessor to the underlying keyCode value is the parent event. */ | 38 /** Accessor to the underlying keyCode value is the parent event. */ |
| 36 int get _realKeyCode => JS('int', '#.keyCode', _parent); | 39 int get _realKeyCode => JS('int', '#.keyCode', _parent); |
| 37 | 40 |
| 38 /** Accessor to the underlying charCode value is the parent event. */ | 41 /** Accessor to the underlying charCode value is the parent event. */ |
| 39 int get _realCharCode => JS('int', '#.charCode', _parent); | 42 int get _realCharCode => JS('int', '#.charCode', _parent); |
| 40 | 43 |
| 41 /** Accessor to the underlying altKey value is the parent event. */ | 44 /** Accessor to the underlying altKey value is the parent event. */ |
| 42 bool get _realAltKey => JS('int', '#.altKey', _parent); | 45 bool get _realAltKey => JS('int', '#.altKey', _parent); |
| 43 | 46 |
| 44 /** Construct a KeyEvent with [parent] as event we're emulating. */ | 47 /** Construct a KeyEvent with [parent] as the event we're emulating. */ |
| 45 KeyEvent(KeyboardEvent parent) { | 48 KeyEvent(KeyboardEvent parent) { |
| 46 _parent = parent; | 49 _parent = parent; |
| 47 _shadowAltKey = _realAltKey; | 50 _shadowAltKey = _realAltKey; |
| 48 _shadowCharCode = _realCharCode; | 51 _shadowCharCode = _realCharCode; |
| 49 _shadowKeyCode = _realKeyCode; | 52 _shadowKeyCode = _realKeyCode; |
| 50 } | 53 } |
| 51 | 54 |
| 55 // TODO(efortuna): If KeyEvent is sufficiently successful that we want to make |
| 56 // it the default keyboard event handling, move these methods over to Element. |
| 57 /** Accessor to provide a stream of KeyEvents on the desired target. */ |
| 58 static EventStreamProvider<KeyEvent> keyDownEvent = |
| 59 new _KeyboardEventHandler('keydown'); |
| 60 /** Accessor to provide a stream of KeyEvents on the desired target. */ |
| 61 static EventStreamProvider<KeyEvent> keyUpEvent = |
| 62 new _KeyboardEventHandler('keyup'); |
| 63 /** Accessor to provide a stream of KeyEvents on the desired target. */ |
| 64 static EventStreamProvider<KeyEvent> keyPressEvent = |
| 65 new _KeyboardEventHandler('keypress'); |
| 66 |
| 52 /** True if the altGraphKey is pressed during this event. */ | 67 /** True if the altGraphKey is pressed during this event. */ |
| 53 bool get altGraphKey => _parent.altGraphKey; | 68 bool get altGraphKey => _parent.altGraphKey; |
| 54 bool get bubbles => _parent.bubbles; | 69 bool get bubbles => _parent.bubbles; |
| 55 /** True if this event can be cancelled. */ | 70 /** True if this event can be cancelled. */ |
| 56 bool get cancelable => _parent.cancelable; | 71 bool get cancelable => _parent.cancelable; |
| 57 bool get cancelBubble => _parent.cancelBubble; | 72 bool get cancelBubble => _parent.cancelBubble; |
| 58 void set cancelBubble(bool cancel) { | 73 void set cancelBubble(bool cancel) { |
| 59 _parent.cancelBubble = cancel; | 74 _parent.cancelBubble = cancel; |
| 60 } | 75 } |
| 61 /** Accessor to the clipboardData available for this event. */ | 76 /** Accessor to the clipboardData available for this event. */ |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 throw new UnsupportedError("keyIdentifier is unsupported."); | 125 throw new UnsupportedError("keyIdentifier is unsupported."); |
| 111 } | 126 } |
| 112 void $dom_initKeyboardEvent(String type, bool canBubble, bool cancelable, | 127 void $dom_initKeyboardEvent(String type, bool canBubble, bool cancelable, |
| 113 Window view, String keyIdentifier, int keyLocation, bool ctrlKey, | 128 Window view, String keyIdentifier, int keyLocation, bool ctrlKey, |
| 114 bool altKey, bool shiftKey, bool metaKey, | 129 bool altKey, bool shiftKey, bool metaKey, |
| 115 bool altGraphKey) { | 130 bool altGraphKey) { |
| 116 throw new UnsupportedError( | 131 throw new UnsupportedError( |
| 117 "Cannot initialize a KeyboardEvent from a KeyEvent."); | 132 "Cannot initialize a KeyboardEvent from a KeyEvent."); |
| 118 } | 133 } |
| 119 } | 134 } |
| OLD | NEW |