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 /** 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; | |
blois
2012/11/29 17:06:34
I believe that this should have a setter as well.
Emily Fortuna
2012/11/29 19:19:50
oops, good catch!
| |
58 /** Accessor to the clipboardData available for this event. */ | |
59 Clipboard get clipboardData => _parent.clipboardData; | |
60 /** True if the ctrl key is pressed during this event. */ | |
61 bool get ctrlKey => _parent.ctrlKey; | |
62 /** Accessor to the target this event is listening to for changes. */ | |
63 EventTarget get currentTarget => _parent.currentTarget; | |
64 bool get defaultPrevented => _parent.defaultPrevented; | |
65 int get detail => _parent.detail; | |
66 int get eventPhase => _parent.eventPhase; | |
67 /** | |
68 * Accessor to the part of the keyboard that the key was pressed from (one of | |
69 * KeyLocation.STANDARD, KeyLocation.RIGHT, KeyLocation.LEFT, | |
70 * KeyLocation.NUMPAD, KeyLocation.MOBILE, KeyLocation.JOYSTICK). | |
71 */ | |
72 int get keyLocation => _parent.keyLocation; | |
73 int get layerX => _parent.layerX; | |
74 int get layerY => _parent.layerY; | |
75 /** True if the Meta (or Mac command) key is pressed during this event. */ | |
76 bool get metaKey => _parent.metaKey; | |
77 int get pageX => _parent.pageX; | |
78 int get pageY => _parent.pageY; | |
79 bool get returnValue => _parent.returnValue; | |
blois
2012/11/29 17:06:34
Should have a setter too.
Emily Fortuna
2012/11/29 19:19:50
Done.
| |
80 /** True if the shift key was pressed during this event. */ | |
81 bool get shiftKey => _parent.shiftKey; | |
82 int get timeStamp => _parent.timeStamp; | |
83 /** | |
84 * The type of key event that occurred. One of "keydown", "keyup", or | |
85 * "keypress". | |
86 */ | |
87 String get type => _parent.type; | |
88 Window get view => _parent.view; | |
89 void preventDefault() => _parent.preventDefault(); | |
90 void stopImmediatePropagation() => _parent.stopImmediatePropagation(); | |
91 void stopPropagation() => _parent.stopPropagation(); | |
92 void $dom_initUIEvent(String type, bool canBubble, bool cancelable, | |
blois
2012/11/29 17:06:34
Probably just throw an exception from these $dom m
Emily Fortuna
2012/11/29 19:19:50
Done.
| |
93 LocalWindow view, int detail) { | |
94 _parent.$dom_initUIEvent(type, canBubble, cancelable, view, detail); | |
95 } | |
96 void $dom_initEvent(String eventTypeArg, bool canBubbleArg, | |
97 bool cancelableArg) { | |
98 _parent.$dom_initEvent(eventTypeArg, canBubbleArg, cancelableArg); | |
99 } | |
100 String get _shadowKeyIdentifier => JS('String', '#.keyIdentifier', _parent); | |
101 } | |
OLD | NEW |