Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: tools/dom/src/dartium_KeyEvent.dart

Issue 23455033: Fully polyfill KeyEvent so that you can programmatically create your own "keyboard" events. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 part of html; 13 part of html;
14 14
15 @Experimental()
15 class KeyEvent extends _WrappedEvent implements KeyboardEvent { 16 class KeyEvent extends _WrappedEvent implements KeyboardEvent {
16 /** The parent KeyboardEvent that this KeyEvent is wrapping and "fixing". */ 17 /** The parent KeyboardEvent that this KeyEvent is wrapping and "fixing". */
17 KeyboardEvent _parent; 18 KeyboardEvent _parent;
18 19
19 /** The "fixed" value of whether the alt key is being pressed. */ 20 /** The "fixed" value of whether the alt key is being pressed. */
20 bool _shadowAltKey; 21 bool _shadowAltKey;
21 22
22 /** Caculated value of what the estimated charCode is for this event. */ 23 /** Caculated value of what the estimated charCode is for this event. */
23 int _shadowCharCode; 24 int _shadowCharCode;
24 25
(...skipping 15 matching lines...) Expand all
40 /** Accessor to the underlying keyCode value is the parent event. */ 41 /** Accessor to the underlying keyCode value is the parent event. */
41 int get _realKeyCode => _parent.keyCode; 42 int get _realKeyCode => _parent.keyCode;
42 43
43 /** Accessor to the underlying charCode value is the parent event. */ 44 /** Accessor to the underlying charCode value is the parent event. */
44 int get _realCharCode => _parent.charCode; 45 int get _realCharCode => _parent.charCode;
45 46
46 /** Accessor to the underlying altKey value is the parent event. */ 47 /** Accessor to the underlying altKey value is the parent event. */
47 bool get _realAltKey => _parent.altKey; 48 bool get _realAltKey => _parent.altKey;
48 49
49 /** Construct a KeyEvent with [parent] as the event we're emulating. */ 50 /** Construct a KeyEvent with [parent] as the event we're emulating. */
50 KeyEvent(KeyboardEvent parent): super(parent) { 51 KeyEvent.wrap(KeyboardEvent parent): super(parent) {
51 _parent = parent; 52 _parent = parent;
52 _shadowAltKey = _realAltKey; 53 _shadowAltKey = _realAltKey;
53 _shadowCharCode = _realCharCode; 54 _shadowCharCode = _realCharCode;
54 _shadowKeyCode = _realKeyCode; 55 _shadowKeyCode = _realKeyCode;
55 } 56 }
56 57
58 /** Programmatically create a new KeyEvent (and KeyboardEvent). */
59 KeyEvent(String type,
60 {Window view, bool canBubble: true, bool cancelable: true, int keyCode: 0,
61 int charCode: 0, int keyLocation: 1, bool ctrlKey: false,
62 bool altKey: false, bool shiftKey: false, bool metaKey: false,
63 bool altGraphKey: false}) {
64 _parent = new KeyboardEvent(type, view: view, canBubble: canBubble,
65 cancelable: cancelable, keyLocation: keyLocation, ctrlKey: ctrlKey,
66 altKey: altKey, shiftKey: shiftKey, metaKey: metaKey, altGraphKey:
67 altGraphKey);
68 _shadowAltKey = altKey;
69 _shadowCharCode = charCode;
70 _shadowKeyCode = keyCode;
71 }
72
57 /** Accessor to provide a stream of KeyEvents on the desired target. */ 73 /** Accessor to provide a stream of KeyEvents on the desired target. */
58 static EventStreamProvider<KeyEvent> keyDownEvent = 74 static EventStreamProvider<KeyEvent> keyDownEvent =
59 new _KeyboardEventHandler('keydown'); 75 new _KeyboardEventHandler('keydown');
60 /** Accessor to provide a stream of KeyEvents on the desired target. */ 76 /** Accessor to provide a stream of KeyEvents on the desired target. */
61 static EventStreamProvider<KeyEvent> keyUpEvent = 77 static EventStreamProvider<KeyEvent> keyUpEvent =
62 new _KeyboardEventHandler('keyup'); 78 new _KeyboardEventHandler('keyup');
63 /** Accessor to provide a stream of KeyEvents on the desired target. */ 79 /** Accessor to provide a stream of KeyEvents on the desired target. */
64 static EventStreamProvider<KeyEvent> keyPressEvent = 80 static EventStreamProvider<KeyEvent> keyPressEvent =
65 new _KeyboardEventHandler('keypress'); 81 new _KeyboardEventHandler('keypress');
66 82
(...skipping 29 matching lines...) Expand all
96 throw new UnsupportedError("keyIdentifier is unsupported."); 112 throw new UnsupportedError("keyIdentifier is unsupported.");
97 } 113 }
98 void _initKeyboardEvent(String type, bool canBubble, bool cancelable, 114 void _initKeyboardEvent(String type, bool canBubble, bool cancelable,
99 Window view, String keyIdentifier, int keyLocation, bool ctrlKey, 115 Window view, String keyIdentifier, int keyLocation, bool ctrlKey,
100 bool altKey, bool shiftKey, bool metaKey, 116 bool altKey, bool shiftKey, bool metaKey,
101 bool altGraphKey) { 117 bool altGraphKey) {
102 throw new UnsupportedError( 118 throw new UnsupportedError(
103 "Cannot initialize a KeyboardEvent from a KeyEvent."); 119 "Cannot initialize a KeyboardEvent from a KeyEvent.");
104 } 120 }
105 } 121 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698