| OLD | NEW |
| (Empty) |
| 1 /** | |
| 2 * A custom KeyboardEvent that attempts to eliminate cross-browser | |
| 3 * inconsistencies, and also provide both keyCode and charCode information | |
| 4 * for all key events (when such information can be determined). | |
| 5 * | |
| 6 * 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 | |
| 8 * possible. Bugs welcome! | |
| 9 */ | |
| 10 class KeyEvent implements KeyboardEvent { | |
| 11 /** The parent KeyboardEvent that this KeyEvent is wrapping and "fixing". */ | |
| 12 KeyboardEvent _parent; | |
| 13 | |
| 14 /** The "fixed" value of whether the alt key is being pressed. */ | |
| 15 bool _shadowAltKey; | |
| 16 | |
| 17 /** Caculated value of what the estimated charCode is for this event. */ | |
| 18 int _shadowCharCode; | |
| 19 | |
| 20 /** Caculated value of what the estimated keyCode is for this event. */ | |
| 21 int _shadowKeyCode; | |
| 22 | |
| 23 /** Caculated value of what the estimated keyCode is for this event. */ | |
| 24 int get keyCode => _shadowKeyCode; | |
| 25 | |
| 26 /** Caculated value of what the estimated charCode is for this event. */ | |
| 27 int get charCode => this.type == 'keypress' ? _shadowCharCode : 0; | |
| 28 | |
| 29 /** Caculated value of whether the alt key is pressed is for this event. */ | |
| 30 bool get altKey => _shadowAltKey; | |
| 31 | |
| 32 /** Caculated value of what the estimated keyCode is for this event. */ | |
| 33 int get which => keyCode; | |
| 34 | |
| 35 /** Accessor to the underlying keyCode value is the parent event. */ | |
| 36 int get _realKeyCode => _parent.keyCode; | |
| 37 | |
| 38 /** Accessor to the underlying charCode value is the parent event. */ | |
| 39 int get _realCharCode => _parent.charCode; | |
| 40 | |
| 41 /** Accessor to the underlying altKey value is the parent event. */ | |
| 42 bool get _realAltKey => _parent.altKey; | |
| 43 | |
| 44 /** Construct a KeyEvent with [parent] as event we're emulating. */ | |
| 45 KeyEvent(KeyboardEvent parent) { | |
| 46 _parent = parent; | |
| 47 _shadowAltKey = _realAltKey; | |
| 48 _shadowCharCode = _realCharCode; | |
| 49 _shadowKeyCode = _realKeyCode; | |
| 50 } | |
| 51 | |
| 52 /** True if the altGraphKey is pressed during this event. */ | |
| 53 bool get altGraphKey => _parent.altGraphKey; | |
| 54 bool get bubbles => _parent.bubbles; | |
| 55 /** True if this event can be cancelled. */ | |
| 56 bool get cancelable => _parent.cancelable; | |
| 57 bool get cancelBubble => _parent.cancelBubble; | |
| 58 void set cancelBubble(bool cancel) { | |
| 59 _parent.cancelBubble = cancel; | |
| 60 } | |
| 61 /** Accessor to the clipboardData available for this event. */ | |
| 62 Clipboard get clipboardData => _parent.clipboardData; | |
| 63 /** True if the ctrl key is pressed during this event. */ | |
| 64 bool get ctrlKey => _parent.ctrlKey; | |
| 65 /** Accessor to the target this event is listening to for changes. */ | |
| 66 EventTarget get currentTarget => _parent.currentTarget; | |
| 67 bool get defaultPrevented => _parent.defaultPrevented; | |
| 68 int get detail => _parent.detail; | |
| 69 int get eventPhase => _parent.eventPhase; | |
| 70 /** | |
| 71 * Accessor to the part of the keyboard that the key was pressed from (one of | |
| 72 * KeyLocation.STANDARD, KeyLocation.RIGHT, KeyLocation.LEFT, | |
| 73 * KeyLocation.NUMPAD, KeyLocation.MOBILE, KeyLocation.JOYSTICK). | |
| 74 */ | |
| 75 int get keyLocation => _parent.keyLocation; | |
| 76 int get layerX => _parent.layerX; | |
| 77 int get layerY => _parent.layerY; | |
| 78 /** True if the Meta (or Mac command) key is pressed during this event. */ | |
| 79 bool get metaKey => _parent.metaKey; | |
| 80 int get pageX => _parent.pageX; | |
| 81 int get pageY => _parent.pageY; | |
| 82 bool get returnValue => _parent.returnValue; | |
| 83 void set returnValue(bool value) { | |
| 84 _parent.returnValue = value; | |
| 85 } | |
| 86 /** True if the shift key was pressed during this event. */ | |
| 87 bool get shiftKey => _parent.shiftKey; | |
| 88 int get timeStamp => _parent.timeStamp; | |
| 89 /** | |
| 90 * The type of key event that occurred. One of "keydown", "keyup", or | |
| 91 * "keypress". | |
| 92 */ | |
| 93 String get type => _parent.type; | |
| 94 Window get view => _parent.view; | |
| 95 void preventDefault() => _parent.preventDefault(); | |
| 96 void stopImmediatePropagation() => _parent.stopImmediatePropagation(); | |
| 97 void stopPropagation() => _parent.stopPropagation(); | |
| 98 void $dom_initUIEvent(String type, bool canBubble, bool cancelable, | |
| 99 Window view, int detail) { | |
| 100 throw new UnsupportedError("Cannot initialize a UI Event from a KeyEvent."); | |
| 101 } | |
| 102 void $dom_initEvent(String eventTypeArg, bool canBubbleArg, | |
| 103 bool cancelableArg) { | |
| 104 throw new UnsupportedError("Cannot initialize an Event from a KeyEvent."); | |
| 105 } | |
| 106 String get _shadowKeyIdentifier => _parent.$dom_keyIdentifier; | |
| 107 | |
| 108 int get $dom_charCode => charCode; | |
| 109 int get $dom_keyCode => keyCode; | |
| 110 EventTarget get target => _parent.target; | |
| 111 String get $dom_keyIdentifier { | |
| 112 throw new UnsupportedError("keyIdentifier is unsupported."); | |
| 113 } | |
| 114 void $dom_initKeyboardEvent(String type, bool canBubble, bool cancelable, | |
| 115 Window view, String keyIdentifier, int keyLocation, bool ctrlKey, | |
| 116 bool altKey, bool shiftKey, bool metaKey, | |
| 117 bool altGraphKey) { | |
| 118 throw new UnsupportedError( | |
| 119 "Cannot initialize a KeyboardEvent from a KeyEvent."); | |
| 120 } | |
| 121 } | |
| OLD | NEW |