| 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 class KeyEvent implements KeyboardEvent { | 13 class KeyEvent extends _WrappedEvent implements KeyboardEvent { |
| 14 /** The parent KeyboardEvent that this KeyEvent is wrapping and "fixing". */ | 14 /** The parent KeyboardEvent that this KeyEvent is wrapping and "fixing". */ |
| 15 KeyboardEvent _parent; | 15 KeyboardEvent _parent; |
| 16 | 16 |
| 17 /** The "fixed" value of whether the alt key is being pressed. */ | 17 /** The "fixed" value of whether the alt key is being pressed. */ |
| 18 bool _shadowAltKey; | 18 bool _shadowAltKey; |
| 19 | 19 |
| 20 /** Caculated value of what the estimated charCode is for this event. */ | 20 /** Caculated value of what the estimated charCode is for this event. */ |
| 21 int _shadowCharCode; | 21 int _shadowCharCode; |
| 22 | 22 |
| 23 /** Caculated value of what the estimated keyCode is for this event. */ | 23 /** Caculated value of what the estimated keyCode is for this event. */ |
| (...skipping 14 matching lines...) Expand all Loading... |
| 38 /** Accessor to the underlying keyCode value is the parent event. */ | 38 /** Accessor to the underlying keyCode value is the parent event. */ |
| 39 int get _realKeyCode => JS('int', '#.keyCode', _parent); | 39 int get _realKeyCode => JS('int', '#.keyCode', _parent); |
| 40 | 40 |
| 41 /** Accessor to the underlying charCode value is the parent event. */ | 41 /** Accessor to the underlying charCode value is the parent event. */ |
| 42 int get _realCharCode => JS('int', '#.charCode', _parent); | 42 int get _realCharCode => JS('int', '#.charCode', _parent); |
| 43 | 43 |
| 44 /** Accessor to the underlying altKey value is the parent event. */ | 44 /** Accessor to the underlying altKey value is the parent event. */ |
| 45 bool get _realAltKey => JS('int', '#.altKey', _parent); | 45 bool get _realAltKey => JS('int', '#.altKey', _parent); |
| 46 | 46 |
| 47 /** Construct a KeyEvent with [parent] as the event we're emulating. */ | 47 /** Construct a KeyEvent with [parent] as the event we're emulating. */ |
| 48 KeyEvent(KeyboardEvent parent) { | 48 KeyEvent(KeyboardEvent parent): super(parent) { |
| 49 _parent = parent; | 49 _parent = parent; |
| 50 _shadowAltKey = _realAltKey; | 50 _shadowAltKey = _realAltKey; |
| 51 _shadowCharCode = _realCharCode; | 51 _shadowCharCode = _realCharCode; |
| 52 _shadowKeyCode = _realKeyCode; | 52 _shadowKeyCode = _realKeyCode; |
| 53 } | 53 } |
| 54 | 54 |
| 55 // TODO(efortuna): If KeyEvent is sufficiently successful that we want to make | 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. | 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. */ | 57 /** Accessor to provide a stream of KeyEvents on the desired target. */ |
| 58 static EventStreamProvider<KeyEvent> keyDownEvent = | 58 static EventStreamProvider<KeyEvent> keyDownEvent = |
| 59 new _KeyboardEventHandler('keydown'); | 59 new _KeyboardEventHandler('keydown'); |
| 60 /** Accessor to provide a stream of KeyEvents on the desired target. */ | 60 /** Accessor to provide a stream of KeyEvents on the desired target. */ |
| 61 static EventStreamProvider<KeyEvent> keyUpEvent = | 61 static EventStreamProvider<KeyEvent> keyUpEvent = |
| 62 new _KeyboardEventHandler('keyup'); | 62 new _KeyboardEventHandler('keyup'); |
| 63 /** Accessor to provide a stream of KeyEvents on the desired target. */ | 63 /** Accessor to provide a stream of KeyEvents on the desired target. */ |
| 64 static EventStreamProvider<KeyEvent> keyPressEvent = | 64 static EventStreamProvider<KeyEvent> keyPressEvent = |
| 65 new _KeyboardEventHandler('keypress'); | 65 new _KeyboardEventHandler('keypress'); |
| 66 | 66 |
| 67 /** True if the altGraphKey is pressed during this event. */ | 67 /** True if the altGraphKey is pressed during this event. */ |
| 68 bool get altGraphKey => _parent.altGraphKey; | 68 bool get altGraphKey => _parent.altGraphKey; |
| 69 bool get bubbles => _parent.bubbles; | |
| 70 /** True if this event can be cancelled. */ | |
| 71 bool get cancelable => _parent.cancelable; | |
| 72 bool get cancelBubble => _parent.cancelBubble; | |
| 73 void set cancelBubble(bool cancel) { | |
| 74 _parent.cancelBubble = cancel; | |
| 75 } | |
| 76 /** Accessor to the clipboardData available for this event. */ | 69 /** Accessor to the clipboardData available for this event. */ |
| 77 DataTransfer get clipboardData => _parent.clipboardData; | 70 DataTransfer get clipboardData => _parent.clipboardData; |
| 78 /** True if the ctrl key is pressed during this event. */ | 71 /** True if the ctrl key is pressed during this event. */ |
| 79 bool get ctrlKey => _parent.ctrlKey; | 72 bool get ctrlKey => _parent.ctrlKey; |
| 80 /** Accessor to the target this event is listening to for changes. */ | |
| 81 EventTarget get currentTarget => _parent.currentTarget; | |
| 82 bool get defaultPrevented => _parent.defaultPrevented; | |
| 83 int get detail => _parent.detail; | 73 int get detail => _parent.detail; |
| 84 int get eventPhase => _parent.eventPhase; | |
| 85 /** | 74 /** |
| 86 * 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 |
| 87 * KeyLocation.STANDARD, KeyLocation.RIGHT, KeyLocation.LEFT, | 76 * KeyLocation.STANDARD, KeyLocation.RIGHT, KeyLocation.LEFT, |
| 88 * KeyLocation.NUMPAD, KeyLocation.MOBILE, KeyLocation.JOYSTICK). | 77 * KeyLocation.NUMPAD, KeyLocation.MOBILE, KeyLocation.JOYSTICK). |
| 89 */ | 78 */ |
| 90 int get keyLocation => _parent.keyLocation; | 79 int get keyLocation => _parent.keyLocation; |
| 91 Point get layer => _parent.layer; | 80 Point get layer => _parent.layer; |
| 92 /** True if the Meta (or Mac command) key is pressed during this event. */ | 81 /** True if the Meta (or Mac command) key is pressed during this event. */ |
| 93 bool get metaKey => _parent.metaKey; | 82 bool get metaKey => _parent.metaKey; |
| 94 Point get page => _parent.page; | 83 Point get page => _parent.page; |
| 95 bool get returnValue => _parent.returnValue; | |
| 96 void set returnValue(bool value) { | |
| 97 _parent.returnValue = value; | |
| 98 } | |
| 99 /** True if the shift key was pressed during this event. */ | 84 /** True if the shift key was pressed during this event. */ |
| 100 bool get shiftKey => _parent.shiftKey; | 85 bool get shiftKey => _parent.shiftKey; |
| 101 int get timeStamp => _parent.timeStamp; | |
| 102 /** | |
| 103 * The type of key event that occurred. One of "keydown", "keyup", or | |
| 104 * "keypress". | |
| 105 */ | |
| 106 String get type => _parent.type; | |
| 107 Window get view => _parent.view; | 86 Window get view => _parent.view; |
| 108 void preventDefault() => _parent.preventDefault(); | |
| 109 void stopImmediatePropagation() => _parent.stopImmediatePropagation(); | |
| 110 void stopPropagation() => _parent.stopPropagation(); | |
| 111 void $dom_initUIEvent(String type, bool canBubble, bool cancelable, | 87 void $dom_initUIEvent(String type, bool canBubble, bool cancelable, |
| 112 Window view, int detail) { | 88 Window view, int detail) { |
| 113 throw new UnsupportedError("Cannot initialize a UI Event from a KeyEvent."); | 89 throw new UnsupportedError("Cannot initialize a UI Event from a KeyEvent."); |
| 114 } | 90 } |
| 115 void $dom_initEvent(String eventTypeArg, bool canBubbleArg, | |
| 116 bool cancelableArg) { | |
| 117 throw new UnsupportedError("Cannot initialize an Event from a KeyEvent."); | |
| 118 } | |
| 119 String get _shadowKeyIdentifier => JS('String', '#.keyIdentifier', _parent); | 91 String get _shadowKeyIdentifier => JS('String', '#.keyIdentifier', _parent); |
| 120 | 92 |
| 121 int get $dom_charCode => charCode; | 93 int get $dom_charCode => charCode; |
| 122 int get $dom_keyCode => keyCode; | 94 int get $dom_keyCode => keyCode; |
| 123 EventTarget get target => _parent.target; | |
| 124 String get $dom_keyIdentifier { | 95 String get $dom_keyIdentifier { |
| 125 throw new UnsupportedError("keyIdentifier is unsupported."); | 96 throw new UnsupportedError("keyIdentifier is unsupported."); |
| 126 } | 97 } |
| 127 void $dom_initKeyboardEvent(String type, bool canBubble, bool cancelable, | 98 void $dom_initKeyboardEvent(String type, bool canBubble, bool cancelable, |
| 128 Window view, String keyIdentifier, int keyLocation, bool ctrlKey, | 99 Window view, String keyIdentifier, int keyLocation, bool ctrlKey, |
| 129 bool altKey, bool shiftKey, bool metaKey, | 100 bool altKey, bool shiftKey, bool metaKey, |
| 130 bool altGraphKey) { | 101 bool altGraphKey) { |
| 131 throw new UnsupportedError( | 102 throw new UnsupportedError( |
| 132 "Cannot initialize a KeyboardEvent from a KeyEvent."); | 103 "Cannot initialize a KeyboardEvent from a KeyEvent."); |
| 133 } | 104 } |
| 134 } | 105 } |
| OLD | NEW |