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

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, 2 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 14 matching lines...) Expand all
39 40
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
50 /** Shadows on top of the parent's currentTarget. */
51 EventTarget _currentTarget;
52
49 /** Construct a KeyEvent with [parent] as the event we're emulating. */ 53 /** Construct a KeyEvent with [parent] as the event we're emulating. */
50 KeyEvent(KeyboardEvent parent): super(parent) { 54 KeyEvent.wrap(KeyboardEvent parent): super(parent) {
51 _parent = parent; 55 _parent = parent;
52 _shadowAltKey = _realAltKey; 56 _shadowAltKey = _realAltKey;
53 _shadowCharCode = _realCharCode; 57 _shadowCharCode = _realCharCode;
54 _shadowKeyCode = _realKeyCode; 58 _shadowKeyCode = _realKeyCode;
59 _currentTarget = _parent.currentTarget == null? window :
60 _parent.currentTarget;
55 } 61 }
56 62
63 /** Programmatically create a new KeyEvent (and KeyboardEvent). */
64 KeyEvent(String type,
65 {Window view, bool canBubble: true, bool cancelable: true, int keyCode: 0,
66 int charCode: 0, int keyLocation: 1, bool ctrlKey: false,
67 bool altKey: false, bool shiftKey: false, bool metaKey: false,
68 bool altGraphKey: false, EventTarget currentTarget}) {
69 _parent = new KeyboardEvent(type, view: view, canBubble: canBubble,
70 cancelable: cancelable, keyLocation: keyLocation, ctrlKey: ctrlKey,
71 altKey: altKey, shiftKey: shiftKey, metaKey: metaKey, altGraphKey:
72 altGraphKey);
73 _shadowAltKey = altKey;
74 _shadowCharCode = charCode;
75 _shadowKeyCode = keyCode;
76 _currentTarget = currentTarget == null ? window : currentTarget;
77 }
78
57 /** Accessor to provide a stream of KeyEvents on the desired target. */ 79 /** Accessor to provide a stream of KeyEvents on the desired target. */
58 static EventStreamProvider<KeyEvent> keyDownEvent = 80 static EventStreamProvider<KeyEvent> keyDownEvent =
59 new _KeyboardEventHandler('keydown'); 81 new _KeyboardEventHandler('keydown');
60 /** Accessor to provide a stream of KeyEvents on the desired target. */ 82 /** Accessor to provide a stream of KeyEvents on the desired target. */
61 static EventStreamProvider<KeyEvent> keyUpEvent = 83 static EventStreamProvider<KeyEvent> keyUpEvent =
62 new _KeyboardEventHandler('keyup'); 84 new _KeyboardEventHandler('keyup');
63 /** Accessor to provide a stream of KeyEvents on the desired target. */ 85 /** Accessor to provide a stream of KeyEvents on the desired target. */
64 static EventStreamProvider<KeyEvent> keyPressEvent = 86 static EventStreamProvider<KeyEvent> keyPressEvent =
65 new _KeyboardEventHandler('keypress'); 87 new _KeyboardEventHandler('keypress');
66 88
89 /** The currently registered target for this event. */
90 EventTarget get currentTarget => _currentTarget;
91
67 /** True if the altGraphKey is pressed during this event. */ 92 /** True if the altGraphKey is pressed during this event. */
68 bool get altGraphKey => _parent.altGraphKey; 93 bool get altGraphKey => _parent.altGraphKey;
69 /** Accessor to the clipboardData available for this event. */ 94 /** Accessor to the clipboardData available for this event. */
70 DataTransfer get clipboardData => _parent.clipboardData; 95 DataTransfer get clipboardData => _parent.clipboardData;
71 /** True if the ctrl key is pressed during this event. */ 96 /** True if the ctrl key is pressed during this event. */
72 bool get ctrlKey => _parent.ctrlKey; 97 bool get ctrlKey => _parent.ctrlKey;
73 int get detail => _parent.detail; 98 int get detail => _parent.detail;
74 /** 99 /**
75 * Accessor to the part of the keyboard that the key was pressed from (one of 100 * Accessor to the part of the keyboard that the key was pressed from (one of
76 * KeyLocation.STANDARD, KeyLocation.RIGHT, KeyLocation.LEFT, 101 * KeyLocation.STANDARD, KeyLocation.RIGHT, KeyLocation.LEFT,
(...skipping 19 matching lines...) Expand all
96 throw new UnsupportedError("keyIdentifier is unsupported."); 121 throw new UnsupportedError("keyIdentifier is unsupported.");
97 } 122 }
98 void _initKeyboardEvent(String type, bool canBubble, bool cancelable, 123 void _initKeyboardEvent(String type, bool canBubble, bool cancelable,
99 Window view, String keyIdentifier, int keyLocation, bool ctrlKey, 124 Window view, String keyIdentifier, int keyLocation, bool ctrlKey,
100 bool altKey, bool shiftKey, bool metaKey, 125 bool altKey, bool shiftKey, bool metaKey,
101 bool altGraphKey) { 126 bool altGraphKey) {
102 throw new UnsupportedError( 127 throw new UnsupportedError(
103 "Cannot initialize a KeyboardEvent from a KeyEvent."); 128 "Cannot initialize a KeyboardEvent from a KeyEvent.");
104 } 129 }
105 } 130 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698