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

Side by Side Diff: ui/base/keycodes/keyboard_code_conversion_gtk.cc

Issue 8803004: Consolidate two very similar functions; ui::WindowsKeyCodeForGdkKeyCode and ui::KeyboardCodeFromXKey (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 9 years 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
« no previous file with comments | « no previous file | ui/base/keycodes/keyboard_code_conversion_x.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /* 5 /*
6 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. 6 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
7 * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com 7 * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com
8 * Copyright (C) 2007 Holger Hans Peter Freyther 8 * Copyright (C) 2007 Holger Hans Peter Freyther
9 * Copyright (C) 2008 Collabora, Ltd. All rights reserved. 9 * Copyright (C) 2008 Collabora, Ltd. All rights reserved.
10 * Copyright (C) 2008, 2009 Google Inc. 10 * Copyright (C) 2008, 2009 Google Inc.
(...skipping 29 matching lines...) Expand all
40 #include <X11/keysym.h> 40 #include <X11/keysym.h>
41 41
42 #include "base/basictypes.h" 42 #include "base/basictypes.h"
43 #include "build/build_config.h" 43 #include "build/build_config.h"
44 #include "ui/base/keycodes/keyboard_code_conversion_x.h" 44 #include "ui/base/keycodes/keyboard_code_conversion_x.h"
45 #include "ui/base/keycodes/keyboard_codes_posix.h" 45 #include "ui/base/keycodes/keyboard_codes_posix.h"
46 46
47 namespace ui { 47 namespace ui {
48 48
49 KeyboardCode WindowsKeyCodeForGdkKeyCode(int keycode) { 49 KeyboardCode WindowsKeyCodeForGdkKeyCode(int keycode) {
50 switch (keycode) { 50 // Gdk key codes (e.g. GDK_BackSpace) and X keysyms (e.g. XK_BackSpace) share
51 case GDK_KP_0: 51 // the same values.
52 return VKEY_NUMPAD0; // (60) Numeric keypad 0 key 52 return KeyboardCodeFromXKeysym(keycode);
53 case GDK_KP_1:
54 return VKEY_NUMPAD1; // (61) Numeric keypad 1 key
55 case GDK_KP_2:
56 return VKEY_NUMPAD2; // (62) Numeric keypad 2 key
57 case GDK_KP_3:
58 return VKEY_NUMPAD3; // (63) Numeric keypad 3 key
59 case GDK_KP_4:
60 return VKEY_NUMPAD4; // (64) Numeric keypad 4 key
61 case GDK_KP_5:
62 return VKEY_NUMPAD5; // (65) Numeric keypad 5 key
63 case GDK_KP_6:
64 return VKEY_NUMPAD6; // (66) Numeric keypad 6 key
65 case GDK_KP_7:
66 return VKEY_NUMPAD7; // (67) Numeric keypad 7 key
67 case GDK_KP_8:
68 return VKEY_NUMPAD8; // (68) Numeric keypad 8 key
69 case GDK_KP_9:
70 return VKEY_NUMPAD9; // (69) Numeric keypad 9 key
71 case GDK_KP_Multiply:
72 return VKEY_MULTIPLY; // (6A) Multiply key
73 case GDK_KP_Add:
74 return VKEY_ADD; // (6B) Add key
75 case GDK_KP_Subtract:
76 return VKEY_SUBTRACT; // (6D) Subtract key
77 case GDK_KP_Decimal:
78 return VKEY_DECIMAL; // (6E) Decimal key
79 case GDK_KP_Divide:
80 return VKEY_DIVIDE; // (6F) Divide key
81
82 case GDK_BackSpace:
83 return VKEY_BACK; // (08) BACKSPACE key
84 case GDK_ISO_Left_Tab:
85 case GDK_3270_BackTab:
86 case GDK_Tab:
87 return VKEY_TAB; // (09) TAB key
88 case GDK_Clear:
89 return VKEY_CLEAR; // (0C) CLEAR key
90 case GDK_ISO_Enter:
91 case GDK_KP_Enter:
92 case GDK_Return:
93 return VKEY_RETURN; // (0D) Return key
94 case GDK_Shift_L:
95 case GDK_Shift_R:
96 return VKEY_SHIFT; // (10) SHIFT key
97 case GDK_Control_L:
98 case GDK_Control_R:
99 return VKEY_CONTROL; // (11) CTRL key
100 case GDK_Menu:
101 return VKEY_APPS; // (5D) Applications key (Natural keyboard)
102 case GDK_Alt_L:
103 case GDK_Alt_R:
104 return VKEY_MENU; // (12) ALT key
105
106 case GDK_Pause:
107 return VKEY_PAUSE; // (13) PAUSE key
108 case GDK_Caps_Lock:
109 return VKEY_CAPITAL; // (14) CAPS LOCK key
110 case GDK_Kana_Lock:
111 case GDK_Kana_Shift:
112 return VKEY_KANA; // (15) Input Method Editor (IME) Kana mode
113 case GDK_Hangul:
114 return VKEY_HANGUL; // VKEY_HANGUL (15) IME Hangul mode
115 // VKEY_JUNJA (17) IME Junja mode
116 // VKEY_FINAL (18) IME final mode
117 case GDK_Hangul_Hanja:
118 return VKEY_HANJA; // (19) IME Hanja mode
119 case GDK_Kanji:
120 return VKEY_KANJI; // (19) IME Kanji mode
121 case GDK_Escape:
122 return VKEY_ESCAPE; // (1B) ESC key
123 // VKEY_CONVERT (1C) IME convert
124 // VKEY_NONCONVERT (1D) IME nonconvert
125 // VKEY_ACCEPT (1E) IME accept
126 // VKEY_MODECHANGE (1F) IME mode change request
127 case GDK_space:
128 return VKEY_SPACE; // (20) SPACEBAR
129 case GDK_Page_Up:
130 return VKEY_PRIOR; // (21) PAGE UP key
131 case GDK_Page_Down:
132 return VKEY_NEXT; // (22) PAGE DOWN key
133 case GDK_End:
134 return VKEY_END; // (23) END key
135 case GDK_Home:
136 return VKEY_HOME; // (24) HOME key
137 case GDK_Left:
138 return VKEY_LEFT; // (25) LEFT ARROW key
139 case GDK_Up:
140 return VKEY_UP; // (26) UP ARROW key
141 case GDK_Right:
142 return VKEY_RIGHT; // (27) RIGHT ARROW key
143 case GDK_Down:
144 return VKEY_DOWN; // (28) DOWN ARROW key
145 case GDK_Select:
146 return VKEY_SELECT; // (29) SELECT key
147 case GDK_Print:
148 return VKEY_PRINT; // (2A) PRINT key
149 case GDK_Execute:
150 return VKEY_EXECUTE; // (2B) EXECUTE key
151 // dunno on this
152 // case GDK_PrintScreen:
153 // return VKEY_SNAPSHOT; // (2C) PRINT SCREEN key
154 case GDK_Insert:
155 return VKEY_INSERT; // (2D) INS key
156 case GDK_Delete:
157 case GDK_KP_Delete:
158 return VKEY_DELETE; // (2E) DEL key
159 case GDK_Help:
160 return VKEY_HELP; // (2F) HELP key
161 case GDK_0:
162 case GDK_parenright:
163 return VKEY_0; // (30) 0) key
164 case GDK_1:
165 case GDK_exclam:
166 return VKEY_1; // (31) 1 ! key
167 case GDK_2:
168 case GDK_at:
169 return VKEY_2; // (32) 2 & key
170 case GDK_3:
171 case GDK_numbersign:
172 return VKEY_3; // case '3': case '#';
173 case GDK_4:
174 case GDK_dollar: // (34) 4 key '$';
175 return VKEY_4;
176 case GDK_5:
177 case GDK_percent:
178 return VKEY_5; // (35) 5 key '%'
179 case GDK_6:
180 case GDK_asciicircum:
181 return VKEY_6; // (36) 6 key '^'
182 case GDK_7:
183 case GDK_ampersand:
184 return VKEY_7; // (37) 7 key case '&'
185 case GDK_8:
186 case GDK_asterisk:
187 return VKEY_8; // (38) 8 key '*'
188 case GDK_9:
189 case GDK_parenleft:
190 return VKEY_9; // (39) 9 key '('
191 case GDK_a:
192 case GDK_A:
193 return VKEY_A; // (41) A key case 'a': case 'A': return 0x41;
194 case GDK_b:
195 case GDK_B:
196 return VKEY_B; // (42) B key case 'b': case 'B': return 0x42;
197 case GDK_c:
198 case GDK_C:
199 return VKEY_C; // (43) C key case 'c': case 'C': return 0x43;
200 case GDK_d:
201 case GDK_D:
202 return VKEY_D; // (44) D key case 'd': case 'D': return 0x44;
203 case GDK_e:
204 case GDK_E:
205 return VKEY_E; // (45) E key case 'e': case 'E': return 0x45;
206 case GDK_f:
207 case GDK_F:
208 return VKEY_F; // (46) F key case 'f': case 'F': return 0x46;
209 case GDK_g:
210 case GDK_G:
211 return VKEY_G; // (47) G key case 'g': case 'G': return 0x47;
212 case GDK_h:
213 case GDK_H:
214 return VKEY_H; // (48) H key case 'h': case 'H': return 0x48;
215 case GDK_i:
216 case GDK_I:
217 return VKEY_I; // (49) I key case 'i': case 'I': return 0x49;
218 case GDK_j:
219 case GDK_J:
220 return VKEY_J; // (4A) J key case 'j': case 'J': return 0x4A;
221 case GDK_k:
222 case GDK_K:
223 return VKEY_K; // (4B) K key case 'k': case 'K': return 0x4B;
224 case GDK_l:
225 case GDK_L:
226 return VKEY_L; // (4C) L key case 'l': case 'L': return 0x4C;
227 case GDK_m:
228 case GDK_M:
229 return VKEY_M; // (4D) M key case 'm': case 'M': return 0x4D;
230 case GDK_n:
231 case GDK_N:
232 return VKEY_N; // (4E) N key case 'n': case 'N': return 0x4E;
233 case GDK_o:
234 case GDK_O:
235 return VKEY_O; // (4F) O key case 'o': case 'O': return 0x4F;
236 case GDK_p:
237 case GDK_P:
238 return VKEY_P; // (50) P key case 'p': case 'P': return 0x50;
239 case GDK_q:
240 case GDK_Q:
241 return VKEY_Q; // (51) Q key case 'q': case 'Q': return 0x51;
242 case GDK_r:
243 case GDK_R:
244 return VKEY_R; // (52) R key case 'r': case 'R': return 0x52;
245 case GDK_s:
246 case GDK_S:
247 return VKEY_S; // (53) S key case 's': case 'S': return 0x53;
248 case GDK_t:
249 case GDK_T:
250 return VKEY_T; // (54) T key case 't': case 'T': return 0x54;
251 case GDK_u:
252 case GDK_U:
253 return VKEY_U; // (55) U key case 'u': case 'U': return 0x55;
254 case GDK_v:
255 case GDK_V:
256 return VKEY_V; // (56) V key case 'v': case 'V': return 0x56;
257 case GDK_w:
258 case GDK_W:
259 return VKEY_W; // (57) W key case 'w': case 'W': return 0x57;
260 case GDK_x:
261 case GDK_X:
262 return VKEY_X; // (58) X key case 'x': case 'X': return 0x58;
263 case GDK_y:
264 case GDK_Y:
265 return VKEY_Y; // (59) Y key case 'y': case 'Y': return 0x59;
266 case GDK_z:
267 case GDK_Z:
268 return VKEY_Z; // (5A) Z key case 'z': case 'Z': return 0x5A;
269 case GDK_Meta_L:
270 case GDK_Super_L:
271 return VKEY_LWIN; // (5B) Left Windows key (Microsoft Natural keyboard)
272 case GDK_Meta_R:
273 case GDK_Super_R:
274 return VKEY_RWIN; // (5C) Right Windows key (Natural keyboard)
275 // VKEY_SLEEP (5F) Computer Sleep key
276 // VKEY_SEPARATOR (6C) Separator key
277 // VKEY_SUBTRACT (6D) Subtract key
278 // VKEY_DECIMAL (6E) Decimal key
279 // VKEY_DIVIDE (6F) Divide key
280 // handled by key code above
281
282 case GDK_Num_Lock:
283 return VKEY_NUMLOCK; // (90) NUM LOCK key
284
285 case GDK_Scroll_Lock:
286 return VKEY_SCROLL; // (91) SCROLL LOCK key
287
288 // VKEY_LSHIFT (A0) Left SHIFT key
289 // VKEY_RSHIFT (A1) Right SHIFT key
290 // VKEY_LCONTROL (A2) Left CONTROL key
291 // VKEY_RCONTROL (A3) Right CONTROL key
292 // VKEY_LMENU (A4) Left MENU key
293 // VKEY_RMENU (A5) Right MENU key
294 // VKEY_BROWSER_BACK (A6) Windows 2000/XP: Browser Back key
295 // VKEY_BROWSER_FORWARD (A7) Windows 2000/XP: Browser Forward key
296 // VKEY_BROWSER_REFRESH (A8) Windows 2000/XP: Browser Refresh key
297 // VKEY_BROWSER_STOP (A9) Windows 2000/XP: Browser Stop key
298 // VKEY_BROWSER_SEARCH (AA) Windows 2000/XP: Browser Search key
299 // VKEY_BROWSER_FAVORITES (AB) Windows 2000/XP: Browser Favorites key
300 // VKEY_BROWSER_HOME (AC) Windows 2000/XP: Browser Start and Home key
301 // VKEY_VOLUME_MUTE (AD) Windows 2000/XP: Volume Mute key
302 // VKEY_VOLUME_DOWN (AE) Windows 2000/XP: Volume Down key
303 // VKEY_VOLUME_UP (AF) Windows 2000/XP: Volume Up key
304 // VKEY_MEDIA_NEXT_TRACK (B0) Windows 2000/XP: Next Track key
305 // VKEY_MEDIA_PREV_TRACK (B1) Windows 2000/XP: Previous Track key
306 // VKEY_MEDIA_STOP (B2) Windows 2000/XP: Stop Media key
307 // VKEY_MEDIA_PLAY_PAUSE (B3) Windows 2000/XP: Play/Pause Media key
308 // VKEY_LAUNCH_MAIL (B4) Windows 2000/XP: Start Mail key
309 // VKEY_LAUNCH_MEDIA_SELECT (B5) Windows 2000/XP: Select Media key
310 // VKEY_LAUNCH_APP1 (B6) Windows 2000/XP: Start Application 1 key
311 // VKEY_LAUNCH_APP2 (B7) Windows 2000/XP: Start Application 2 key
312
313 // VKEY_OEM_1 (BA) Used for miscellaneous characters; it can vary by
314 // keyboard. Windows 2000/XP: For the US standard keyboard, the ';:' key
315 case GDK_semicolon:
316 case GDK_colon:
317 return VKEY_OEM_1; // case ';': case ':': return 0xBA;
318 // VKEY_OEM_PLUS (BB) Windows 2000/XP: For any country/region, the '+' key
319 case GDK_plus:
320 case GDK_equal:
321 return VKEY_OEM_PLUS; // case '=': case '+': return 0xBB;
322 // VKEY_OEM_COMMA (BC) Windows 2000/XP: For any country/region, the ','
323 // key
324 case GDK_comma:
325 case GDK_less:
326 return VKEY_OEM_COMMA; // case ',': case '<': return 0xBC;
327 // VKEY_OEM_MINUS (BD) Windows 2000/XP: For any country/region, the '-'
328 // key
329 case GDK_minus:
330 case GDK_underscore:
331 return VKEY_OEM_MINUS; // case '-': case '_': return 0xBD;
332 // VKEY_OEM_PERIOD (BE) Windows 2000/XP: For any country/region, the '.'
333 // key
334 case GDK_period:
335 case GDK_greater:
336 return VKEY_OEM_PERIOD; // case '.': case '>': return 0xBE;
337 // VKEY_OEM_2 (BF) Used for miscellaneous characters; it can vary by
338 // keyboard. Windows 2000/XP: For the US standard keyboard, the '/?' key
339 case GDK_slash:
340 case GDK_question:
341 return VKEY_OEM_2; // case '/': case '?': return 0xBF;
342 // VKEY_OEM_3 (C0) Used for miscellaneous characters; it can vary by
343 // keyboard. Windows 2000/XP: For the US standard keyboard, the '`~' key
344 case GDK_asciitilde:
345 case GDK_quoteleft:
346 return VKEY_OEM_3; // case '`': case '~': return 0xC0;
347 // VKEY_OEM_4 (DB) Used for miscellaneous characters; it can vary by
348 // keyboard. Windows 2000/XP: For the US standard keyboard, the '[{' key
349 case GDK_bracketleft:
350 case GDK_braceleft:
351 return VKEY_OEM_4; // case '[': case '{': return 0xDB;
352 // VKEY_OEM_5 (DC) Used for miscellaneous characters; it can vary by
353 // keyboard. Windows 2000/XP: For the US standard keyboard, the '\|' key
354 case GDK_backslash:
355 case GDK_bar:
356 return VKEY_OEM_5; // case '\\': case '|': return 0xDC;
357 // VKEY_OEM_6 (DD) Used for miscellaneous characters; it can vary by
358 // keyboard. Windows 2000/XP: For the US standard keyboard, the ']}' key
359 case GDK_bracketright:
360 case GDK_braceright:
361 return VKEY_OEM_6; // case ']': case '}': return 0xDD;
362 // VKEY_OEM_7 (DE) Used for miscellaneous characters; it can vary by
363 // keyboard. Windows 2000/XP: For the US standard keyboard, the
364 // 'single-quote/double-quote' key
365 case GDK_quoteright:
366 case GDK_quotedbl:
367 return VKEY_OEM_7; // case '\'': case '"': return 0xDE;
368 // VKEY_OEM_8 (DF) Used for miscellaneous characters; it can vary by
369 // keyboard.
370 // VKEY_OEM_102 (E2) Windows 2000/XP: Either the angle bracket key or the
371 // backslash key on the RT 102-key keyboard
372 // VKEY_PROCESSKEY (E5) Windows 95/98/Me, Windows NT 4.0, Windows 2000/XP:
373 // IME PROCESS key
374 // VKEY_PACKET (E7) Windows 2000/XP: Used to pass Unicode characters as if
375 // they were keystrokes. The VKEY_PACKET key is the low word of a 32-bit
376 // Virtual Key value used for non-keyboard input methods. For more
377 // information, see Remark in KEYBDINPUT,SendInput, WM_KEYDOWN, and
378 // WM_KEYUP
379 // VKEY_ATTN (F6) Attn key
380 // VKEY_CRSEL (F7) CrSel key
381 // VKEY_EXSEL (F8) ExSel key
382 // VKEY_EREOF (F9) Erase EOF key
383 // VKEY_PLAY (FA) Play key
384 // VKEY_ZOOM (FB) Zoom key
385 // VKEY_NONAME (FC) Reserved for future use
386 // VKEY_PA1 (FD) PA1 key
387 // VKEY_OEM_CLEAR (FE) Clear key
388 case GDK_F1:
389 case GDK_F2:
390 case GDK_F3:
391 case GDK_F4:
392 case GDK_F5:
393 case GDK_F6:
394 case GDK_F7:
395 case GDK_F8:
396 case GDK_F9:
397 case GDK_F10:
398 case GDK_F11:
399 case GDK_F12:
400 case GDK_F13:
401 case GDK_F14:
402 case GDK_F15:
403 case GDK_F16:
404 case GDK_F17:
405 case GDK_F18:
406 case GDK_F19:
407 case GDK_F20:
408 case GDK_F21:
409 case GDK_F22:
410 case GDK_F23:
411 case GDK_F24:
412 return static_cast<KeyboardCode>(VKEY_F1 + (keycode - GDK_F1));
413 default:
414 return VKEY_UNKNOWN;
415 }
416 } 53 }
417 54
418 int GdkKeyCodeForWindowsKeyCode(KeyboardCode keycode, bool shift) { 55 int GdkKeyCodeForWindowsKeyCode(KeyboardCode keycode, bool shift) {
419 // Gdk key codes (e.g. GDK_BackSpace) and X keysyms (e.g. XK_BackSpace) share 56 // Gdk key codes and X keysyms share the same values.
420 // the same values.
421 // TODO(yusukes): We might want to consolidate WindowsKeyCodeForGdkKeyCode()
422 // and KeyboardCodeFromXKeysym() as well. http://crbug.com/103511
423 return XKeysymForWindowsKeyCode(keycode, shift); 57 return XKeysymForWindowsKeyCode(keycode, shift);
424 } 58 }
425 59
426 // Just in case, test whether Gdk key codes match X ones. 60 // Just in case, test whether Gdk key codes match X ones.
427 COMPILE_ASSERT(GDK_KP_0 == XK_KP_0, keycode_check); 61 COMPILE_ASSERT(GDK_KP_0 == XK_KP_0, keycode_check);
428 COMPILE_ASSERT(GDK_A == XK_A, keycode_check); 62 COMPILE_ASSERT(GDK_A == XK_A, keycode_check);
429 COMPILE_ASSERT(GDK_Escape == XK_Escape, keycode_check); 63 COMPILE_ASSERT(GDK_Escape == XK_Escape, keycode_check);
430 COMPILE_ASSERT(GDK_F1 == XK_F1, keycode_check); 64 COMPILE_ASSERT(GDK_F1 == XK_F1, keycode_check);
431 COMPILE_ASSERT(GDK_Kanji == XK_Kanji, keycode_check); 65 COMPILE_ASSERT(GDK_Kanji == XK_Kanji, keycode_check);
432 COMPILE_ASSERT(GDK_Page_Up == XK_Page_Up, keycode_check); 66 COMPILE_ASSERT(GDK_Page_Up == XK_Page_Up, keycode_check);
(...skipping 20 matching lines...) Expand all
453 // Gtk's key values are same as X11's keysyms. 87 // Gtk's key values are same as X11's keysyms.
454 if (keycode == VKEY_UNKNOWN) { 88 if (keycode == VKEY_UNKNOWN) {
455 unsigned int keyval = 89 unsigned int keyval =
456 DefaultXKeysymFromHardwareKeycode(event->hardware_keycode); 90 DefaultXKeysymFromHardwareKeycode(event->hardware_keycode);
457 keycode = WindowsKeyCodeForGdkKeyCode(keyval); 91 keycode = WindowsKeyCodeForGdkKeyCode(keyval);
458 } 92 }
459 return keycode; 93 return keycode;
460 } 94 }
461 95
462 } // namespace ui 96 } // namespace ui
OLDNEW
« no previous file with comments | « no previous file | ui/base/keycodes/keyboard_code_conversion_x.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698