Chromium Code Reviews| 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 => JS('int', '#.keyCode', _parent); | |
| 37 | |
| 38 /** Accessor to the underlying charCode value is the parent event. */ | |
| 39 int get _realCharCode => JS('int', '#.charCode', _parent); | |
| 40 | |
| 41 /** Accessor to the underlying altKey value is the parent event. */ | |
| 42 bool get _realAltKey => JS('int', '#.altKey', _parent); | |
| 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 /** | |
| 53 * Catch-all to behave for all other methods not defined here just like the | |
| 54 * _parent. | |
| 55 */ | |
| 56 void noSuchMethod(InvocationMirror invocation) { | |
|
blois
2012/11/29 00:03:12
Are there performance implications of this? Might
Emily Fortuna
2012/11/29 01:10:37
Yep. Removed.
| |
| 57 invocation.invokeOn(_parent); | |
| 58 } | |
| 59 | |
| 60 // ----------------------------------------------------------------------- | |
| 61 // This code duplication is unfortunate... It's like this because dart2js | |
| 62 // generates code accessing fields like KeyEvent.bubbles as | |
| 63 // KeyEvent.get$bubbles, which without these getters, would hit noSuchMethod, | |
| 64 // and try to call get$bubbles on KeyBoardEvent, which just has a bubbles | |
| 65 // field, not a get$bubbles. | |
| 66 /** True if the altGraphKey is pressed during this event. */ | |
| 67 bool get altGraphKey => _parent.altGraphKey; | |
| 68 bool get bubbles => _parent.bubbles; | |
| 69 /** True if this event can be cancelled. */ | |
| 70 bool get cancelable => _parent.cancelable; | |
| 71 bool get cancelBubble => _parent.cancelBubble; | |
| 72 /** Accessor to the clipboardData available for this event. */ | |
| 73 Clipboard get clipboardData => _parent.clipboardData; | |
| 74 /** True if the ctrl key is pressed during this event. */ | |
| 75 bool get ctrlKey => _parent.ctrlKey; | |
| 76 /** Accessor to the target this event is listening to for changes. */ | |
| 77 EventTarget get currentTarget => _parent.currentTarget; | |
| 78 bool get defaultPrevented => _parent.defaultPrevented; | |
| 79 int get detail => _parent.detail; | |
| 80 int get eventPhase => _parent.eventPhase; | |
| 81 /** | |
| 82 * Accessor to the part of the keyboard that the key was pressed from (one of | |
| 83 * KeyLocation.STANDARD, KeyLocation.RIGHT, KeyLocation.LEFT, | |
| 84 * KeyLocation.NUMPAD, KeyLocation.MOBILE, KeyLocation.JOYSTICK). | |
| 85 */ | |
| 86 int get keyLocation => _parent.keyLocation; | |
| 87 int get layerX => _parent.layerX; | |
| 88 int get layerY => _parent.layerY; | |
| 89 /** True if the Meta (or Mac command) key is pressed during this event. */ | |
| 90 bool get metaKey => _parent.metaKey; | |
| 91 int get pageX => _parent.pageX; | |
| 92 int get pageY => _parent.pageY; | |
| 93 bool get returnValue => _parent.returnValue; | |
| 94 /** True if the shift key was pressed during this event. */ | |
| 95 bool get shiftKey => _parent.shiftKey; | |
| 96 int get timeStamp => _parent.timeStamp; | |
| 97 /** | |
| 98 * The type of key event that occurred. One of "keydown", "keyup", or | |
| 99 * "keypress". | |
| 100 */ | |
| 101 String get type => _parent.type; | |
| 102 Window get view => _parent.view; | |
| 103 String get _shadowKeyIdentifier => JS('String', '#.keyIdentifier', _parent); | |
| 104 } | |
| OLD | NEW |