• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
3  *
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #include "config.h"
29 #include "PlatformKeyboardEvent.h"
30 
31 #include "NotImplemented.h"
32 #include "WindowsKeyboardCodes.h"
33 
34 #include <QKeyEvent>
35 #include <ctype.h>
36 
37 namespace WebCore {
38 
keyIdentifierForQtKeyCode(int keyCode)39 String keyIdentifierForQtKeyCode(int keyCode)
40 {
41     switch (keyCode) {
42     case Qt::Key_Menu:
43     case Qt::Key_Alt:
44         return "Alt";
45     case Qt::Key_Clear:
46         return "Clear";
47     case Qt::Key_Down:
48         return "Down";
49     case Qt::Key_End:
50         return "End";
51     case Qt::Key_Return:
52     case Qt::Key_Enter:
53         return "Enter";
54     case Qt::Key_Execute:
55         return "Execute";
56     case Qt::Key_F1:
57         return "F1";
58     case Qt::Key_F2:
59         return "F2";
60     case Qt::Key_F3:
61         return "F3";
62     case Qt::Key_F4:
63         return "F4";
64     case Qt::Key_F5:
65         return "F5";
66     case Qt::Key_F6:
67         return "F6";
68     case Qt::Key_F7:
69         return "F7";
70     case Qt::Key_F8:
71         return "F8";
72     case Qt::Key_F9:
73         return "F9";
74     case Qt::Key_F10:
75         return "F10";
76     case Qt::Key_F11:
77         return "F11";
78     case Qt::Key_F12:
79         return "F12";
80     case Qt::Key_F13:
81         return "F13";
82     case Qt::Key_F14:
83         return "F14";
84     case Qt::Key_F15:
85         return "F15";
86     case Qt::Key_F16:
87         return "F16";
88     case Qt::Key_F17:
89         return "F17";
90     case Qt::Key_F18:
91         return "F18";
92     case Qt::Key_F19:
93         return "F19";
94     case Qt::Key_F20:
95         return "F20";
96     case Qt::Key_F21:
97         return "F21";
98     case Qt::Key_F22:
99         return "F22";
100     case Qt::Key_F23:
101         return "F23";
102     case Qt::Key_F24:
103         return "F24";
104     case Qt::Key_Help:
105         return "Help";
106     case Qt::Key_Home:
107         return "Home";
108     case Qt::Key_Insert:
109         return "Insert";
110     case Qt::Key_Left:
111         return "Left";
112     case Qt::Key_PageDown:
113         return "PageDown";
114     case Qt::Key_PageUp:
115         return "PageUp";
116     case Qt::Key_Pause:
117         return "Pause";
118     case Qt::Key_Print:
119         return "PrintScreen";
120     case Qt::Key_Right:
121         return "Right";
122     case Qt::Key_Select:
123         return "Select";
124     case Qt::Key_Up:
125         return "Up";
126         // Standard says that DEL becomes U+007F.
127     case Qt::Key_Delete:
128         return "U+007F";
129     case Qt::Key_Backspace:
130         return "U+0008";
131     case Qt::Key_Tab:
132         return "U+0009";
133     case Qt::Key_Backtab:
134         return "U+0009";
135     default:
136         return String::format("U+%04X", toupper(keyCode));
137     }
138 }
139 
windowsKeyCodeForKeyEvent(unsigned int keycode,bool isKeypad)140 int windowsKeyCodeForKeyEvent(unsigned int keycode, bool isKeypad)
141 {
142     // Determine wheter the event comes from the keypad
143     if (isKeypad) {
144         switch (keycode) {
145         case Qt::Key_0:
146             return VK_NUMPAD0; // (60) Numeric keypad 0 key
147         case Qt::Key_1:
148             return VK_NUMPAD1; // (61) Numeric keypad 1 key
149         case Qt::Key_2:
150             return  VK_NUMPAD2; // (62) Numeric keypad 2 key
151         case Qt::Key_3:
152             return VK_NUMPAD3; // (63) Numeric keypad 3 key
153         case Qt::Key_4:
154             return VK_NUMPAD4; // (64) Numeric keypad 4 key
155         case Qt::Key_5:
156             return VK_NUMPAD5; // (65) Numeric keypad 5 key
157         case Qt::Key_6:
158             return VK_NUMPAD6; // (66) Numeric keypad 6 key
159         case Qt::Key_7:
160             return VK_NUMPAD7; // (67) Numeric keypad 7 key
161         case Qt::Key_8:
162             return VK_NUMPAD8; // (68) Numeric keypad 8 key
163         case Qt::Key_9:
164             return VK_NUMPAD9; // (69) Numeric keypad 9 key
165         case Qt::Key_Asterisk:
166             return VK_MULTIPLY; // (6A) Multiply key
167         case Qt::Key_Plus:
168             return VK_ADD; // (6B) Add key
169         case Qt::Key_Minus:
170             return VK_SUBTRACT; // (6D) Subtract key
171         case Qt::Key_Period:
172             return VK_DECIMAL; // (6E) Decimal key
173         case Qt::Key_Slash:
174             return VK_DIVIDE; // (6F) Divide key
175         case Qt::Key_PageUp:
176             return VK_PRIOR; // (21) PAGE UP key
177         case Qt::Key_PageDown:
178             return VK_NEXT; // (22) PAGE DOWN key
179         case Qt::Key_End:
180             return VK_END; // (23) END key
181         case Qt::Key_Home:
182             return VK_HOME; // (24) HOME key
183         case Qt::Key_Left:
184             return VK_LEFT; // (25) LEFT ARROW key
185         case Qt::Key_Up:
186             return VK_UP; // (26) UP ARROW key
187         case Qt::Key_Right:
188             return VK_RIGHT; // (27) RIGHT ARROW key
189         case Qt::Key_Down:
190             return VK_DOWN; // (28) DOWN ARROW key
191         case Qt::Key_Enter:
192         case Qt::Key_Return:
193             return VK_RETURN; // (0D) Return key
194         case Qt::Key_Insert:
195             return VK_INSERT; // (2D) INS key
196         case Qt::Key_Delete:
197             return VK_DELETE; // (2E) DEL key
198         default:
199             return 0;
200         }
201 
202     } else
203 
204     switch (keycode) {
205     case Qt::Key_Backspace:
206         return VK_BACK; // (08) BACKSPACE key
207     case Qt::Key_Backtab:
208     case Qt::Key_Tab:
209         return VK_TAB; // (09) TAB key
210     case Qt::Key_Clear:
211         return VK_CLEAR; // (0C) CLEAR key
212     case Qt::Key_Enter:
213     case Qt::Key_Return:
214         return VK_RETURN; // (0D) Return key
215     case Qt::Key_Shift:
216         return VK_SHIFT; // (10) SHIFT key
217     case Qt::Key_Control:
218         return VK_CONTROL; // (11) CTRL key
219     case Qt::Key_Menu:
220     case Qt::Key_Alt:
221         return VK_MENU; // (12) ALT key
222 
223     case Qt::Key_F1:
224         return VK_F1;
225     case Qt::Key_F2:
226         return VK_F2;
227     case Qt::Key_F3:
228         return VK_F3;
229     case Qt::Key_F4:
230         return VK_F4;
231     case Qt::Key_F5:
232         return VK_F5;
233     case Qt::Key_F6:
234         return VK_F6;
235     case Qt::Key_F7:
236         return VK_F7;
237     case Qt::Key_F8:
238         return VK_F8;
239     case Qt::Key_F9:
240         return VK_F9;
241     case Qt::Key_F10:
242         return VK_F10;
243     case Qt::Key_F11:
244         return VK_F11;
245     case Qt::Key_F12:
246         return VK_F12;
247     case Qt::Key_F13:
248         return VK_F13;
249     case Qt::Key_F14:
250         return VK_F14;
251     case Qt::Key_F15:
252         return VK_F15;
253     case Qt::Key_F16:
254         return VK_F16;
255     case Qt::Key_F17:
256         return VK_F17;
257     case Qt::Key_F18:
258         return VK_F18;
259     case Qt::Key_F19:
260         return VK_F19;
261     case Qt::Key_F20:
262         return VK_F20;
263     case Qt::Key_F21:
264         return VK_F21;
265     case Qt::Key_F22:
266         return VK_F22;
267     case Qt::Key_F23:
268         return VK_F23;
269     case Qt::Key_F24:
270         return VK_F24;
271 
272     case Qt::Key_Pause:
273         return VK_PAUSE; // (13) PAUSE key
274     case Qt::Key_CapsLock:
275         return VK_CAPITAL; // (14) CAPS LOCK key
276     case Qt::Key_Kana_Lock:
277     case Qt::Key_Kana_Shift:
278         return VK_KANA; // (15) Input Method Editor (IME) Kana mode
279     case Qt::Key_Hangul:
280         return VK_HANGUL; // VK_HANGUL (15) IME Hangul mode
281         // VK_JUNJA (17) IME Junja mode
282         // VK_FINAL (18) IME final mode
283     case Qt::Key_Hangul_Hanja:
284         return VK_HANJA; // (19) IME Hanja mode
285     case Qt::Key_Kanji:
286         return VK_KANJI; // (19) IME Kanji mode
287     case Qt::Key_Escape:
288         return VK_ESCAPE; // (1B) ESC key
289         // VK_CONVERT (1C) IME convert
290         // VK_NONCONVERT (1D) IME nonconvert
291         // VK_ACCEPT (1E) IME accept
292         // VK_MODECHANGE (1F) IME mode change request
293     case Qt::Key_Space:
294         return VK_SPACE; // (20) SPACEBAR
295     case Qt::Key_PageUp:
296         return VK_PRIOR; // (21) PAGE UP key
297     case Qt::Key_PageDown:
298         return VK_NEXT; // (22) PAGE DOWN key
299     case Qt::Key_End:
300         return VK_END; // (23) END key
301     case Qt::Key_Home:
302         return VK_HOME; // (24) HOME key
303     case Qt::Key_Left:
304         return VK_LEFT; // (25) LEFT ARROW key
305     case Qt::Key_Up:
306         return VK_UP; // (26) UP ARROW key
307     case Qt::Key_Right:
308         return VK_RIGHT; // (27) RIGHT ARROW key
309     case Qt::Key_Down:
310         return VK_DOWN; // (28) DOWN ARROW key
311     case Qt::Key_Select:
312         return VK_SELECT; // (29) SELECT key
313     case Qt::Key_Print:
314         return VK_SNAPSHOT; // (2A) PRINT key
315     case Qt::Key_Execute:
316         return VK_EXECUTE; // (2B) EXECUTE key
317     case Qt::Key_Insert:
318         return VK_INSERT; // (2D) INS key
319     case Qt::Key_Delete:
320         return VK_DELETE; // (2E) DEL key
321     case Qt::Key_Help:
322         return VK_HELP; // (2F) HELP key
323     case Qt::Key_0:
324     case Qt::Key_ParenLeft:
325         return VK_0; // (30) 0) key
326     case Qt::Key_1:
327         return VK_1; // (31) 1 ! key
328     case Qt::Key_2:
329     case Qt::Key_At:
330         return VK_2; // (32) 2 & key
331     case Qt::Key_3:
332     case Qt::Key_NumberSign:
333         return VK_3; // case '3': case '#';
334     case Qt::Key_4:
335     case Qt::Key_Dollar: // (34) 4 key '$';
336         return VK_4;
337     case Qt::Key_5:
338     case Qt::Key_Percent:
339         return VK_5; // (35) 5 key  '%'
340     case Qt::Key_6:
341     case Qt::Key_AsciiCircum:
342         return VK_6; // (36) 6 key  '^'
343     case Qt::Key_7:
344     case Qt::Key_Ampersand:
345         return VK_7; // (37) 7 key  case '&'
346     case Qt::Key_8:
347     case Qt::Key_Asterisk:
348         return VK_8; // (38) 8 key  '*'
349     case Qt::Key_9:
350     case Qt::Key_ParenRight:
351         return VK_9; // (39) 9 key '('
352     case Qt::Key_A:
353         return VK_A; // (41) A key case 'a': case 'A': return 0x41;
354     case Qt::Key_B:
355         return VK_B; // (42) B key case 'b': case 'B': return 0x42;
356     case Qt::Key_C:
357         return VK_C; // (43) C key case 'c': case 'C': return 0x43;
358     case Qt::Key_D:
359         return VK_D; // (44) D key case 'd': case 'D': return 0x44;
360     case Qt::Key_E:
361         return VK_E; // (45) E key case 'e': case 'E': return 0x45;
362     case Qt::Key_F:
363         return VK_F; // (46) F key case 'f': case 'F': return 0x46;
364     case Qt::Key_G:
365         return VK_G; // (47) G key case 'g': case 'G': return 0x47;
366     case Qt::Key_H:
367         return VK_H; // (48) H key case 'h': case 'H': return 0x48;
368     case Qt::Key_I:
369         return VK_I; // (49) I key case 'i': case 'I': return 0x49;
370     case Qt::Key_J:
371         return VK_J; // (4A) J key case 'j': case 'J': return 0x4A;
372     case Qt::Key_K:
373         return VK_K; // (4B) K key case 'k': case 'K': return 0x4B;
374     case Qt::Key_L:
375         return VK_L; // (4C) L key case 'l': case 'L': return 0x4C;
376     case Qt::Key_M:
377         return VK_M; // (4D) M key case 'm': case 'M': return 0x4D;
378     case Qt::Key_N:
379         return VK_N; // (4E) N key case 'n': case 'N': return 0x4E;
380     case Qt::Key_O:
381         return VK_O; // (4F) O key case 'o': case 'O': return 0x4F;
382     case Qt::Key_P:
383         return VK_P; // (50) P key case 'p': case 'P': return 0x50;
384     case Qt::Key_Q:
385         return VK_Q; // (51) Q key case 'q': case 'Q': return 0x51;
386     case Qt::Key_R:
387         return VK_R; // (52) R key case 'r': case 'R': return 0x52;
388     case Qt::Key_S:
389         return VK_S; // (53) S key case 's': case 'S': return 0x53;
390     case Qt::Key_T:
391         return VK_T; // (54) T key case 't': case 'T': return 0x54;
392     case Qt::Key_U:
393         return VK_U; // (55) U key case 'u': case 'U': return 0x55;
394     case Qt::Key_V:
395         return VK_V; // (56) V key case 'v': case 'V': return 0x56;
396     case Qt::Key_W:
397         return VK_W; // (57) W key case 'w': case 'W': return 0x57;
398     case Qt::Key_X:
399         return VK_X; // (58) X key case 'x': case 'X': return 0x58;
400     case Qt::Key_Y:
401         return VK_Y; // (59) Y key case 'y': case 'Y': return 0x59;
402     case Qt::Key_Z:
403         return VK_Z; // (5A) Z key case 'z': case 'Z': return 0x5A;
404     case Qt::Key_Meta:
405         return VK_LWIN; // (5B) Left Windows key (Microsoft Natural keyboard)
406         // case Qt::Key_Meta_R: FIXME: What to do here?
407         //    return VK_RWIN; // (5C) Right Windows key (Natural keyboard)
408         // VK_APPS (5D) Applications key (Natural keyboard)
409         // VK_SLEEP (5F) Computer Sleep key
410         // VK_SEPARATOR (6C) Separator key
411         // VK_SUBTRACT (6D) Subtract key
412         // VK_DECIMAL (6E) Decimal key
413         // VK_DIVIDE (6F) Divide key
414         // handled by key code above
415 
416     case Qt::Key_NumLock:
417         return VK_NUMLOCK; // (90) NUM LOCK key
418 
419     case Qt::Key_ScrollLock:
420         return VK_SCROLL; // (91) SCROLL LOCK key
421 
422         // VK_LSHIFT (A0) Left SHIFT key
423         // VK_RSHIFT (A1) Right SHIFT key
424         // VK_LCONTROL (A2) Left CONTROL key
425         // VK_RCONTROL (A3) Right CONTROL key
426         // VK_LMENU (A4) Left MENU key
427         // VK_RMENU (A5) Right MENU key
428         // VK_BROWSER_BACK (A6) Windows 2000/XP: Browser Back key
429         // VK_BROWSER_FORWARD (A7) Windows 2000/XP: Browser Forward key
430         // VK_BROWSER_REFRESH (A8) Windows 2000/XP: Browser Refresh key
431         // VK_BROWSER_STOP (A9) Windows 2000/XP: Browser Stop key
432         // VK_BROWSER_SEARCH (AA) Windows 2000/XP: Browser Search key
433         // VK_BROWSER_FAVORITES (AB) Windows 2000/XP: Browser Favorites key
434         // VK_BROWSER_HOME (AC) Windows 2000/XP: Browser Start and Home key
435         // VK_VOLUME_MUTE (AD) Windows 2000/XP: Volume Mute key
436         // VK_VOLUME_DOWN (AE) Windows 2000/XP: Volume Down key
437         // VK_VOLUME_UP (AF) Windows 2000/XP: Volume Up key
438         // VK_MEDIA_NEXT_TRACK (B0) Windows 2000/XP: Next Track key
439         // VK_MEDIA_PREV_TRACK (B1) Windows 2000/XP: Previous Track key
440         // VK_MEDIA_STOP (B2) Windows 2000/XP: Stop Media key
441         // VK_MEDIA_PLAY_PAUSE (B3) Windows 2000/XP: Play/Pause Media key
442         // VK_LAUNCH_MAIL (B4) Windows 2000/XP: Start Mail key
443         // VK_LAUNCH_MEDIA_SELECT (B5) Windows 2000/XP: Select Media key
444         // VK_LAUNCH_APP1 (B6) Windows 2000/XP: Start Application 1 key
445         // VK_LAUNCH_APP2 (B7) Windows 2000/XP: Start Application 2 key
446 
447         // VK_OEM_1 (BA) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the ';:' key
448     case Qt::Key_Semicolon:
449     case Qt::Key_Colon:
450         return VK_OEM_1; // case ';': case ':': return 0xBA;
451         // VK_OEM_PLUS (BB) Windows 2000/XP: For any country/region, the '+' key
452     case Qt::Key_Plus:
453     case Qt::Key_Equal:
454         return VK_OEM_PLUS; // case '=': case '+': return 0xBB;
455         // VK_OEM_COMMA (BC) Windows 2000/XP: For any country/region, the ',' key
456     case Qt::Key_Comma:
457     case Qt::Key_Less:
458         return VK_OEM_COMMA; // case ',': case '<': return 0xBC;
459         // VK_OEM_MINUS (BD) Windows 2000/XP: For any country/region, the '-' key
460     case Qt::Key_Minus:
461     case Qt::Key_Underscore:
462         return VK_OEM_MINUS; // case '-': case '_': return 0xBD;
463         // VK_OEM_PERIOD (BE) Windows 2000/XP: For any country/region, the '.' key
464     case Qt::Key_Period:
465     case Qt::Key_Greater:
466         return VK_OEM_PERIOD; // case '.': case '>': return 0xBE;
467         // VK_OEM_2 (BF) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '/?' key
468     case Qt::Key_Slash:
469     case Qt::Key_Question:
470         return VK_OEM_2; // case '/': case '?': return 0xBF;
471         // VK_OEM_3 (C0) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '`~' key
472     case Qt::Key_AsciiTilde:
473     case Qt::Key_QuoteLeft:
474         return VK_OEM_3; // case '`': case '~': return 0xC0;
475         // VK_OEM_4 (DB) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '[{' key
476     case Qt::Key_BracketLeft:
477     case Qt::Key_BraceLeft:
478         return VK_OEM_4; // case '[': case '{': return 0xDB;
479         // VK_OEM_5 (DC) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '\|' key
480     case Qt::Key_Backslash:
481     case Qt::Key_Bar:
482         return VK_OEM_5; // case '\\': case '|': return 0xDC;
483         // VK_OEM_6 (DD) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the ']}' key
484     case Qt::Key_BracketRight:
485     case Qt::Key_BraceRight:
486         return VK_OEM_6; // case ']': case '}': return 0xDD;
487         // VK_OEM_7 (DE) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the 'single-quote/double-quote' key
488     case Qt::Key_QuoteDbl:
489         return VK_OEM_7; // case '\'': case '"': return 0xDE;
490         // VK_OEM_8 (DF) Used for miscellaneous characters; it can vary by keyboard.
491         // VK_OEM_102 (E2) Windows 2000/XP: Either the angle bracket key or the backslash key on the RT 102-key keyboard
492         // VK_PROCESSKEY (E5) Windows 95/98/Me, Windows NT 4.0, Windows 2000/XP: IME PROCESS key
493         // VK_PACKET (E7) Windows 2000/XP: Used to pass Unicode characters as if they were keystrokes. The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT,SendInput, WM_KEYDOWN, and WM_KEYUP
494         // VK_ATTN (F6) Attn key
495         // VK_CRSEL (F7) CrSel key
496         // VK_EXSEL (F8) ExSel key
497         // VK_EREOF (F9) Erase EOF key
498         // VK_PLAY (FA) Play key
499         // VK_ZOOM (FB) Zoom key
500         // VK_NONAME (FC) Reserved for future use
501         // VK_PA1 (FD) PA1 key
502         // VK_OEM_CLEAR (FE) Clear key
503     default:
504         return 0;
505     }
506 }
507 
isVirtualKeyCodeRepresentingCharacter(int code)508 static bool isVirtualKeyCodeRepresentingCharacter(int code)
509 {
510     switch (code) {
511     case VK_SPACE:
512     case VK_0:
513     case VK_1:
514     case VK_2:
515     case VK_3:
516     case VK_4:
517     case VK_5:
518     case VK_6:
519     case VK_7:
520     case VK_8:
521     case VK_9:
522     case VK_A:
523     case VK_B:
524     case VK_C:
525     case VK_D:
526     case VK_E:
527     case VK_F:
528     case VK_G:
529     case VK_H:
530     case VK_I:
531     case VK_J:
532     case VK_K:
533     case VK_L:
534     case VK_M:
535     case VK_N:
536     case VK_O:
537     case VK_P:
538     case VK_Q:
539     case VK_R:
540     case VK_S:
541     case VK_T:
542     case VK_U:
543     case VK_V:
544     case VK_W:
545     case VK_X:
546     case VK_Y:
547     case VK_Z:
548     case VK_NUMPAD0:
549     case VK_NUMPAD1:
550     case VK_NUMPAD2:
551     case VK_NUMPAD3:
552     case VK_NUMPAD4:
553     case VK_NUMPAD5:
554     case VK_NUMPAD6:
555     case VK_NUMPAD7:
556     case VK_NUMPAD8:
557     case VK_NUMPAD9:
558     case VK_MULTIPLY:
559     case VK_ADD:
560     case VK_SEPARATOR:
561     case VK_SUBTRACT:
562     case VK_DECIMAL:
563     case VK_DIVIDE:
564     case VK_OEM_1:
565     case VK_OEM_PLUS:
566     case VK_OEM_COMMA:
567     case VK_OEM_MINUS:
568     case VK_OEM_PERIOD:
569     case VK_OEM_2:
570     case VK_OEM_3:
571     case VK_OEM_4:
572     case VK_OEM_5:
573     case VK_OEM_6:
574     case VK_OEM_7:
575         return true;
576     default:
577         return false;
578     }
579 }
580 
PlatformKeyboardEvent(QKeyEvent * event)581 PlatformKeyboardEvent::PlatformKeyboardEvent(QKeyEvent* event)
582 {
583     const int state = event->modifiers();
584     m_type = (event->type() == QEvent::KeyRelease) ? KeyUp : KeyDown;
585     m_text = event->text();
586     m_unmodifiedText = event->text(); // FIXME: not correct
587     m_keyIdentifier = keyIdentifierForQtKeyCode(event->key());
588     m_autoRepeat = event->isAutoRepeat();
589     m_ctrlKey = (state & Qt::ControlModifier);
590     m_altKey = (state & Qt::AltModifier);
591     m_metaKey = (state & Qt::MetaModifier);
592     m_isKeypad = (state & Qt::KeypadModifier);
593     m_windowsVirtualKeyCode = windowsKeyCodeForKeyEvent(event->key(), m_isKeypad);
594     m_nativeVirtualKeyCode = event->nativeVirtualKey();
595     m_shiftKey = (state & Qt::ShiftModifier) || event->key() == Qt::Key_Backtab; // Simulate Shift+Tab with Key_Backtab
596     m_qtEvent = event;
597 }
598 
disambiguateKeyDownEvent(Type type,bool)599 void PlatformKeyboardEvent::disambiguateKeyDownEvent(Type type, bool)
600 {
601     // Can only change type from KeyDown to RawKeyDown or Char, as we lack information for other conversions.
602     ASSERT(m_type == KeyDown);
603     m_type = type;
604 
605     if (type == RawKeyDown) {
606         m_text = String();
607         m_unmodifiedText = String();
608     } else {
609         /*
610             When we receive shortcut events like Ctrl+V then the text in the QKeyEvent is
611             empty. If we're asked to disambiguate the event into a Char keyboard event,
612             we try to detect this situation and still set the text, to ensure that the
613             general event handling sends a key press event after this disambiguation.
614         */
615         if (m_text.isEmpty() && m_windowsVirtualKeyCode && isVirtualKeyCodeRepresentingCharacter(m_windowsVirtualKeyCode))
616             m_text.append(UChar(m_windowsVirtualKeyCode));
617 
618         m_keyIdentifier = String();
619         m_windowsVirtualKeyCode = 0;
620     }
621 }
622 
currentCapsLockState()623 bool PlatformKeyboardEvent::currentCapsLockState()
624 {
625     notImplemented();
626     return false;
627 }
628 
getCurrentModifierState(bool & shiftKey,bool & ctrlKey,bool & altKey,bool & metaKey)629 void PlatformKeyboardEvent::getCurrentModifierState(bool& shiftKey, bool& ctrlKey, bool& altKey, bool& metaKey)
630 {
631     notImplemented();
632     shiftKey = false;
633     ctrlKey = false;
634     altKey = false;
635     metaKey = false;
636 }
637 
nativeModifiers() const638 uint32_t PlatformKeyboardEvent::nativeModifiers() const
639 {
640     ASSERT(m_qtEvent);
641     return m_qtEvent->nativeModifiers();
642 }
643 
nativeScanCode() const644 uint32_t PlatformKeyboardEvent::nativeScanCode() const
645 {
646     ASSERT(m_qtEvent);
647     return m_qtEvent->nativeScanCode();
648 }
649 
650 }
651 
652 // vim: ts=4 sw=4 et
653