-
Notifications
You must be signed in to change notification settings - Fork 1
/
render_handler_key.c
625 lines (611 loc) · 17.2 KB
/
render_handler_key.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
#include "ecef.h"
#define XK_3270 // for XK_3270_BackTab
#include <Evas.h>
#include <Ecore_X.h>
#include <X11/keysym.h>
#include <X11/XF86keysym.h>
// From ui/events/keycodes/keyboard_code_conversion_x.cc.
// Gdk key codes (e.g. GDK_BackSpace) and X keysyms (e.g. XK_BackSpace) share
// the same values.
KeyboardCode KeyboardCodeFromXKeysym(unsigned int keysym) {
switch (keysym) {
case XK_BackSpace:
return VKEY_BACK;
case XK_Delete:
case XK_KP_Delete:
return VKEY_DELETE;
case XK_Tab:
case XK_KP_Tab:
case XK_ISO_Left_Tab:
case XK_3270_BackTab:
return VKEY_TAB;
case XK_Linefeed:
case XK_Return:
case XK_KP_Enter:
case XK_ISO_Enter:
return VKEY_RETURN;
case XK_Clear:
case XK_KP_Begin: // NumPad 5 without Num Lock, for crosbug.com/29169.
return VKEY_CLEAR;
case XK_KP_Space:
case XK_space:
return VKEY_SPACE;
case XK_Home:
case XK_KP_Home:
return VKEY_HOME;
case XK_End:
case XK_KP_End:
return VKEY_END;
case XK_Page_Up:
case XK_KP_Page_Up: // aka XK_KP_Prior
return VKEY_PRIOR;
case XK_Page_Down:
case XK_KP_Page_Down: // aka XK_KP_Next
return VKEY_NEXT;
case XK_Left:
case XK_KP_Left:
return VKEY_LEFT;
case XK_Right:
case XK_KP_Right:
return VKEY_RIGHT;
case XK_Down:
case XK_KP_Down:
return VKEY_DOWN;
case XK_Up:
case XK_KP_Up:
return VKEY_UP;
case XK_Escape:
return VKEY_ESCAPE;
case XK_Kana_Lock:
case XK_Kana_Shift:
return VKEY_KANA;
case XK_Hangul:
return VKEY_HANGUL;
case XK_Hangul_Hanja:
return VKEY_HANJA;
case XK_Kanji:
return VKEY_KANJI;
case XK_Henkan:
return VKEY_CONVERT;
case XK_Muhenkan:
return VKEY_NONCONVERT;
case XK_Zenkaku_Hankaku:
return VKEY_DBE_DBCSCHAR;
case XK_A:
case XK_a:
return VKEY_A;
case XK_B:
case XK_b:
return VKEY_B;
case XK_C:
case XK_c:
return VKEY_C;
case XK_D:
case XK_d:
return VKEY_D;
case XK_E:
case XK_e:
return VKEY_E;
case XK_F:
case XK_f:
return VKEY_F;
case XK_G:
case XK_g:
return VKEY_G;
case XK_H:
case XK_h:
return VKEY_H;
case XK_I:
case XK_i:
return VKEY_I;
case XK_J:
case XK_j:
return VKEY_J;
case XK_K:
case XK_k:
return VKEY_K;
case XK_L:
case XK_l:
return VKEY_L;
case XK_M:
case XK_m:
return VKEY_M;
case XK_N:
case XK_n:
return VKEY_N;
case XK_O:
case XK_o:
return VKEY_O;
case XK_P:
case XK_p:
return VKEY_P;
case XK_Q:
case XK_q:
return VKEY_Q;
case XK_R:
case XK_r:
return VKEY_R;
case XK_S:
case XK_s:
return VKEY_S;
case XK_T:
case XK_t:
return VKEY_T;
case XK_U:
case XK_u:
return VKEY_U;
case XK_V:
case XK_v:
return VKEY_V;
case XK_W:
case XK_w:
return VKEY_W;
case XK_X:
case XK_x:
return VKEY_X;
case XK_Y:
case XK_y:
return VKEY_Y;
case XK_Z:
case XK_z:
return VKEY_Z;
case XK_0:
case XK_1:
case XK_2:
case XK_3:
case XK_4:
case XK_5:
case XK_6:
case XK_7:
case XK_8:
case XK_9:
return VKEY_0 + (keysym - XK_0);
case XK_parenright:
return VKEY_0;
case XK_exclam:
return VKEY_1;
case XK_at:
return VKEY_2;
case XK_numbersign:
return VKEY_3;
case XK_dollar:
return VKEY_4;
case XK_percent:
return VKEY_5;
case XK_asciicircum:
return VKEY_6;
case XK_ampersand:
return VKEY_7;
case XK_asterisk:
return VKEY_8;
case XK_parenleft:
return VKEY_9;
case XK_KP_0:
case XK_KP_1:
case XK_KP_2:
case XK_KP_3:
case XK_KP_4:
case XK_KP_5:
case XK_KP_6:
case XK_KP_7:
case XK_KP_8:
case XK_KP_9:
return VKEY_NUMPAD0 + (keysym - XK_KP_0);
case XK_multiply:
case XK_KP_Multiply:
return VKEY_MULTIPLY;
case XK_KP_Add:
return VKEY_ADD;
case XK_KP_Separator:
return VKEY_SEPARATOR;
case XK_KP_Subtract:
return VKEY_SUBTRACT;
case XK_KP_Decimal:
return VKEY_DECIMAL;
case XK_KP_Divide:
return VKEY_DIVIDE;
case XK_KP_Equal:
case XK_equal:
case XK_plus:
return VKEY_OEM_PLUS;
case XK_comma:
case XK_less:
return VKEY_OEM_COMMA;
case XK_minus:
case XK_underscore:
return VKEY_OEM_MINUS;
case XK_greater:
case XK_period:
return VKEY_OEM_PERIOD;
case XK_colon:
case XK_semicolon:
return VKEY_OEM_1;
case XK_question:
case XK_slash:
return VKEY_OEM_2;
case XK_asciitilde:
case XK_quoteleft:
return VKEY_OEM_3;
case XK_bracketleft:
case XK_braceleft:
return VKEY_OEM_4;
case XK_backslash:
case XK_bar:
return VKEY_OEM_5;
case XK_bracketright:
case XK_braceright:
return VKEY_OEM_6;
case XK_quoteright:
case XK_quotedbl:
return VKEY_OEM_7;
case XK_ISO_Level5_Shift:
return VKEY_OEM_8;
case XK_Shift_L:
case XK_Shift_R:
return VKEY_SHIFT;
case XK_Control_L:
case XK_Control_R:
return VKEY_CONTROL;
case XK_Meta_L:
case XK_Meta_R:
case XK_Alt_L:
case XK_Alt_R:
return VKEY_MENU;
case XK_ISO_Level3_Shift:
return VKEY_ALTGR;
case XK_Multi_key:
return VKEY_COMPOSE;
case XK_Pause:
return VKEY_PAUSE;
case XK_Caps_Lock:
return VKEY_CAPITAL;
case XK_Num_Lock:
return VKEY_NUMLOCK;
case XK_Scroll_Lock:
return VKEY_SCROLL;
case XK_Select:
return VKEY_SELECT;
case XK_Print:
return VKEY_PRINT;
case XK_Execute:
return VKEY_EXECUTE;
case XK_Insert:
case XK_KP_Insert:
return VKEY_INSERT;
case XK_Help:
return VKEY_HELP;
case XK_Super_L:
return VKEY_LWIN;
case XK_Super_R:
return VKEY_RWIN;
case XK_Menu:
return VKEY_APPS;
case XK_F1:
case XK_F2:
case XK_F3:
case XK_F4:
case XK_F5:
case XK_F6:
case XK_F7:
case XK_F8:
case XK_F9:
case XK_F10:
case XK_F11:
case XK_F12:
case XK_F13:
case XK_F14:
case XK_F15:
case XK_F16:
case XK_F17:
case XK_F18:
case XK_F19:
case XK_F20:
case XK_F21:
case XK_F22:
case XK_F23:
case XK_F24:
return VKEY_F1 + (keysym - XK_F1);
case XK_KP_F1:
case XK_KP_F2:
case XK_KP_F3:
case XK_KP_F4:
return VKEY_F1 + (keysym - XK_KP_F1);
case XK_guillemotleft:
case XK_guillemotright:
case XK_degree:
// In the case of canadian multilingual keyboard layout, VKEY_OEM_102 is
// assigned to ugrave key.
case XK_ugrave:
case XK_Ugrave:
case XK_brokenbar:
return VKEY_OEM_102; // international backslash key in 102 keyboard.
// When evdev is in use, /usr/share/X11/xkb/symbols/inet maps F13-18 keys
// to the special XF86XK symbols to support Microsoft Ergonomic keyboards:
// https://bugs.freedesktop.org/show_bug.cgi?id=5783
// In Chrome, we map these X key symbols back to F13-18 since we don't have
// VKEYs for these XF86XK symbols.
case XF86XK_Tools:
return VKEY_F13;
case XF86XK_Launch5:
return VKEY_F14;
case XF86XK_Launch6:
return VKEY_F15;
case XF86XK_Launch7:
return VKEY_F16;
case XF86XK_Launch8:
return VKEY_F17;
case XF86XK_Launch9:
return VKEY_F18;
case XF86XK_Refresh:
case XF86XK_History:
case XF86XK_OpenURL:
case XF86XK_AddFavorite:
case XF86XK_Go:
case XF86XK_ZoomIn:
case XF86XK_ZoomOut:
// ui::AcceleratorGtk tries to convert the XF86XK_ keysyms on Chrome
// startup. It's safe to return VKEY_UNKNOWN here since ui::AcceleratorGtk
// also checks a Gdk keysym. http://crbug.com/109843
return VKEY_UNKNOWN;
// For supporting multimedia buttons on a USB keyboard.
case XF86XK_Back:
return VKEY_BROWSER_BACK;
case XF86XK_Forward:
return VKEY_BROWSER_FORWARD;
case XF86XK_Reload:
return VKEY_BROWSER_REFRESH;
case XF86XK_Stop:
return VKEY_BROWSER_STOP;
case XF86XK_Search:
return VKEY_BROWSER_SEARCH;
case XF86XK_Favorites:
return VKEY_BROWSER_FAVORITES;
case XF86XK_HomePage:
return VKEY_BROWSER_HOME;
case XF86XK_AudioMute:
return VKEY_VOLUME_MUTE;
case XF86XK_AudioLowerVolume:
return VKEY_VOLUME_DOWN;
case XF86XK_AudioRaiseVolume:
return VKEY_VOLUME_UP;
case XF86XK_AudioNext:
return VKEY_MEDIA_NEXT_TRACK;
case XF86XK_AudioPrev:
return VKEY_MEDIA_PREV_TRACK;
case XF86XK_AudioStop:
return VKEY_MEDIA_STOP;
case XF86XK_AudioPlay:
return VKEY_MEDIA_PLAY_PAUSE;
case XF86XK_Mail:
return VKEY_MEDIA_LAUNCH_MAIL;
case XF86XK_LaunchA: // F3 on an Apple keyboard.
return VKEY_MEDIA_LAUNCH_APP1;
case XF86XK_LaunchB: // F4 on an Apple keyboard.
case XF86XK_Calculator:
return VKEY_MEDIA_LAUNCH_APP2;
case XF86XK_WLAN:
return VKEY_WLAN;
case XF86XK_PowerOff:
return VKEY_POWER;
case XF86XK_MonBrightnessDown:
return VKEY_BRIGHTNESS_DOWN;
case XF86XK_MonBrightnessUp:
return VKEY_BRIGHTNESS_UP;
case XF86XK_KbdBrightnessDown:
return VKEY_KBD_BRIGHTNESS_DOWN;
case XF86XK_KbdBrightnessUp:
return VKEY_KBD_BRIGHTNESS_UP;
// TODO(sad): some keycodes are still missing.
}
return VKEY_UNKNOWN;
}
// From content/browser/renderer_host/input/web_input_event_util_posix.cc.
KeyboardCode GdkEventToWindowsKeyCode(const Evas_Event_Key_Down* event) {
static const unsigned int kHardwareCodeToGDKKeyval[] = {
0, // 0x00:
0, // 0x01:
0, // 0x02:
0, // 0x03:
0, // 0x04:
0, // 0x05:
0, // 0x06:
0, // 0x07:
0, // 0x08:
0, // 0x09: XK_Escape
XK_1, // 0x0A: XK_1
XK_2, // 0x0B: XK_2
XK_3, // 0x0C: XK_3
XK_4, // 0x0D: XK_4
XK_5, // 0x0E: XK_5
XK_6, // 0x0F: XK_6
XK_7, // 0x10: XK_7
XK_8, // 0x11: XK_8
XK_9, // 0x12: XK_9
XK_0, // 0x13: XK_0
XK_minus, // 0x14: XK_minus
XK_equal, // 0x15: XK_equal
0, // 0x16: XK_BackSpace
0, // 0x17: XK_Tab
XK_q, // 0x18: XK_q
XK_w, // 0x19: XK_w
XK_e, // 0x1A: XK_e
XK_r, // 0x1B: XK_r
XK_t, // 0x1C: XK_t
XK_y, // 0x1D: XK_y
XK_u, // 0x1E: XK_u
XK_i, // 0x1F: XK_i
XK_o, // 0x20: XK_o
XK_p, // 0x21: XK_p
XK_bracketleft, // 0x22: XK_bracketleft
XK_bracketright, // 0x23: XK_bracketright
0, // 0x24: XK_Return
0, // 0x25: XK_Control_L
XK_a, // 0x26: XK_a
XK_s, // 0x27: XK_s
XK_d, // 0x28: XK_d
XK_f, // 0x29: XK_f
XK_g, // 0x2A: XK_g
XK_h, // 0x2B: XK_h
XK_j, // 0x2C: XK_j
XK_k, // 0x2D: XK_k
XK_l, // 0x2E: XK_l
XK_semicolon, // 0x2F: XK_semicolon
XK_apostrophe, // 0x30: XK_apostrophe
XK_grave, // 0x31: XK_grave
0, // 0x32: XK_Shift_L
XK_backslash, // 0x33: XK_backslash
XK_z, // 0x34: XK_z
XK_x, // 0x35: XK_x
XK_c, // 0x36: XK_c
XK_v, // 0x37: XK_v
XK_b, // 0x38: XK_b
XK_n, // 0x39: XK_n
XK_m, // 0x3A: XK_m
XK_comma, // 0x3B: XK_comma
XK_period, // 0x3C: XK_period
XK_slash, // 0x3D: XK_slash
0, // 0x3E: XK_Shift_R
0, // 0x3F:
0, // 0x40:
0, // 0x41:
0, // 0x42:
0, // 0x43:
0, // 0x44:
0, // 0x45:
0, // 0x46:
0, // 0x47:
0, // 0x48:
0, // 0x49:
0, // 0x4A:
0, // 0x4B:
0, // 0x4C:
0, // 0x4D:
0, // 0x4E:
0, // 0x4F:
0, // 0x50:
0, // 0x51:
0, // 0x52:
0, // 0x53:
0, // 0x54:
0, // 0x55:
0, // 0x56:
0, // 0x57:
0, // 0x58:
0, // 0x59:
0, // 0x5A:
0, // 0x5B:
0, // 0x5C:
0, // 0x5D:
0, // 0x5E:
0, // 0x5F:
0, // 0x60:
0, // 0x61:
0, // 0x62:
0, // 0x63:
0, // 0x64:
0, // 0x65:
0, // 0x66:
0, // 0x67:
0, // 0x68:
0, // 0x69:
0, // 0x6A:
0, // 0x6B:
0, // 0x6C:
0, // 0x6D:
0, // 0x6E:
0, // 0x6F:
0, // 0x70:
0, // 0x71:
0, // 0x72:
XK_Super_L, // 0x73: XK_Super_L
XK_Super_R, // 0x74: XK_Super_R
};
// |windows_key_code| has to include a valid virtual-key code even when we
// use non-US layouts, e.g. even when we type an 'A' key of a US keyboard
// on the Hebrew layout, |windows_key_code| should be VK_A.
// On the other hand, |event->keyval| value depends on the current
// GdkKeymap object, i.e. when we type an 'A' key of a US keyboard on
// the Hebrew layout, |event->keyval| becomes XK_hebrew_shin and this
// KeyboardCodeFromXKeysym() call returns 0.
// To improve compatibilty with Windows, we use |event->hardware_keycode|
// for retrieving its Windows key-code for the keys when the
// WebCore::windows_key_codeForEvent() call returns 0.
// We shouldn't use |event->hardware_keycode| for keys that GdkKeymap
// objects cannot change because |event->hardware_keycode| doesn't change
// even when we change the layout options, e.g. when we swap a control
// key and a caps-lock key, GTK doesn't swap their
// |event->hardware_keycode| values but swap their |event->keyval| values.
KeyboardCode windows_key_code =
KeyboardCodeFromXKeysym(ecore_x_keysym_get(event->key));
if (windows_key_code)
return windows_key_code;
if (event->keycode < EINA_C_ARRAY_LENGTH(kHardwareCodeToGDKKeyval)) {
int keyval = kHardwareCodeToGDKKeyval[event->keycode];
if (keyval)
return KeyboardCodeFromXKeysym(keyval);
}
// This key is one that keyboard-layout drivers cannot change.
// Use |event->keyval| to retrieve its |windows_key_code| value.
return KeyboardCodeFromXKeysym(ecore_x_keysym_get(event->key));
}
// From content/browser/renderer_host/input/web_input_event_util_posix.cc.
KeyboardCode GetWindowsKeyCodeWithoutLocation(KeyboardCode key_code) {
switch (key_code) {
case VKEY_LCONTROL:
case VKEY_RCONTROL:
return VKEY_CONTROL;
case VKEY_LSHIFT:
case VKEY_RSHIFT:
return VKEY_SHIFT;
case VKEY_LMENU:
case VKEY_RMENU:
return VKEY_MENU;
default:
return key_code;
}
}
// From content/browser/renderer_host/input/web_input_event_builders_gtk.cc.
// Gets the corresponding control character of a specified key code. See:
// http://en.wikipedia.org/wiki/Control_characters
// We emulate Windows behavior here.
int GetControlCharacter(KeyboardCode windows_key_code, int shift) {
if (windows_key_code >= VKEY_A && windows_key_code <= VKEY_Z) {
// ctrl-A ~ ctrl-Z map to \x01 ~ \x1A
return windows_key_code - VKEY_A + 1;
}
if (shift) {
// following graphics chars require shift key to input.
switch (windows_key_code) {
// ctrl-@ maps to \x00 (Null byte)
case VKEY_2:
return 0;
// ctrl-^ maps to \x1E (Record separator, Information separator two)
case VKEY_6:
return 0x1E;
// ctrl-_ maps to \x1F (Unit separator, Information separator one)
case VKEY_OEM_MINUS:
return 0x1F;
// Returns 0 for all other keys to avoid inputting unexpected chars.
default:
return 0;
}
} else {
switch (windows_key_code) {
// ctrl-[ maps to \x1B (Escape)
case VKEY_OEM_4:
return 0x1B;
// ctrl-\ maps to \x1C (File separator, Information separator four)
case VKEY_OEM_5:
return 0x1C;
// ctrl-] maps to \x1D (Group separator, Information separator three)
case VKEY_OEM_6:
return 0x1D;
// ctrl-Enter maps to \x0A (Line feed)
case VKEY_RETURN:
return 0x0A;
// Returns 0 for all other keys to avoid inputting unexpected chars.
default:
return 0;
}
}
}