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

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

Issue 6674052: [cros] Fix accelerator keys when using non-US/Latin keyboard layouts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 9 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
« no previous file with comments | « ui/base/keycodes/keyboard_code_conversion_x.h ('k') | views/events/event_gtk.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 #include "ui/base/keycodes/keyboard_code_conversion_x.h" 5 #include "ui/base/keycodes/keyboard_code_conversion_x.h"
6 6
7 #include <X11/keysym.h> 7 #include <X11/keysym.h>
8 #include <X11/Xlib.h> 8 #include <X11/Xlib.h>
9 9
10 #include "base/basictypes.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
11 12
12 namespace ui { 13 namespace ui {
13 14
14 // Get an ui::KeyboardCode from an X keyevent 15 // Get an ui::KeyboardCode from an X keyevent
15 KeyboardCode KeyboardCodeFromXKeyEvent(XEvent* xev) { 16 KeyboardCode KeyboardCodeFromXKeyEvent(XEvent* xev) {
16 KeySym keysym = XLookupKeysym(&xev->xkey, 0); 17 KeySym keysym = XLookupKeysym(&xev->xkey, 0);
17 18
19 KeyboardCode keycode = KeyboardCodeFromXKeysym(keysym);
20 if (keycode == VKEY_UNKNOWN) {
21 keysym = DefaultXKeysymFromHardwareKeycode(xev->xkey.keycode);
22 keycode = KeyboardCodeFromXKeysym(keysym);
23 }
24
25 return keycode;
26 }
27
28 KeyboardCode KeyboardCodeFromXKeysym(unsigned int keysym) {
18 // Consult GDK key translation (in WindowsKeyCodeForGdkKeyCode) for details 29 // Consult GDK key translation (in WindowsKeyCodeForGdkKeyCode) for details
19 // about the following translations. 30 // about the following translations.
20 31
21 // TODO(sad): Have |keysym| go through the X map list? 32 // TODO(sad): Have |keysym| go through the X map list?
22 33
23 switch (keysym) { 34 switch (keysym) {
24 case XK_BackSpace: 35 case XK_BackSpace:
25 return VKEY_BACK; 36 return VKEY_BACK;
26 case XK_Delete: 37 case XK_Delete:
27 case XK_KP_Delete: 38 case XK_KP_Delete:
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 case XK_F24: 282 case XK_F24:
272 return static_cast<KeyboardCode>(VKEY_F1 + (keysym - XK_F1)); 283 return static_cast<KeyboardCode>(VKEY_F1 + (keysym - XK_F1));
273 284
274 // TODO(sad): some keycodes are still missing. 285 // TODO(sad): some keycodes are still missing.
275 } 286 }
276 287
277 DLOG(WARNING) << "Unknown keycode: " << keysym; 288 DLOG(WARNING) << "Unknown keycode: " << keysym;
278 return VKEY_UNKNOWN; 289 return VKEY_UNKNOWN;
279 } 290 }
280 291
292 unsigned int DefaultXKeysymFromHardwareKeycode(unsigned int hardware_code) {
293 static const unsigned int kHardwareKeycodeMap[] = {
294 0, // 0x00:
295 0, // 0x01:
296 0, // 0x02:
297 0, // 0x03:
298 0, // 0x04:
299 0, // 0x05:
300 0, // 0x06:
301 0, // 0x07:
302 0, // 0x08:
303 XK_Escape, // 0x09: XK_Escape
304 XK_1, // 0x0A: XK_1
305 XK_2, // 0x0B: XK_2
306 XK_3, // 0x0C: XK_3
307 XK_4, // 0x0D: XK_4
308 XK_5, // 0x0E: XK_5
309 XK_6, // 0x0F: XK_6
310 XK_7, // 0x10: XK_7
311 XK_8, // 0x11: XK_8
312 XK_9, // 0x12: XK_9
313 XK_0, // 0x13: XK_0
314 XK_minus, // 0x14: XK_minus
315 XK_equal, // 0x15: XK_equal
316 XK_BackSpace, // 0x16: XK_BackSpace
317 XK_Tab, // 0x17: XK_Tab
318 XK_q, // 0x18: XK_q
319 XK_w, // 0x19: XK_w
320 XK_e, // 0x1A: XK_e
321 XK_r, // 0x1B: XK_r
322 XK_t, // 0x1C: XK_t
323 XK_y, // 0x1D: XK_y
324 XK_u, // 0x1E: XK_u
325 XK_i, // 0x1F: XK_i
326 XK_o, // 0x20: XK_o
327 XK_p, // 0x21: XK_p
328 XK_bracketleft, // 0x22: XK_bracketleft
329 XK_bracketright, // 0x23: XK_bracketright
330 XK_Return, // 0x24: XK_Return
331 XK_Control_L, // 0x25: XK_Control_L
332 XK_a, // 0x26: XK_a
333 XK_s, // 0x27: XK_s
334 XK_d, // 0x28: XK_d
335 XK_f, // 0x29: XK_f
336 XK_g, // 0x2A: XK_g
337 XK_h, // 0x2B: XK_h
338 XK_j, // 0x2C: XK_j
339 XK_k, // 0x2D: XK_k
340 XK_l, // 0x2E: XK_l
341 XK_semicolon, // 0x2F: XK_semicolon
342 XK_apostrophe, // 0x30: XK_apostrophe
343 XK_grave, // 0x31: XK_grave
344 XK_Shift_L, // 0x32: XK_Shift_L
345 XK_backslash, // 0x33: XK_backslash
346 XK_z, // 0x34: XK_z
347 XK_x, // 0x35: XK_x
348 XK_c, // 0x36: XK_c
349 XK_v, // 0x37: XK_v
350 XK_b, // 0x38: XK_b
351 XK_n, // 0x39: XK_n
352 XK_m, // 0x3A: XK_m
353 XK_comma, // 0x3B: XK_comma
354 XK_period, // 0x3C: XK_period
355 XK_slash, // 0x3D: XK_slash
356 XK_Shift_R, // 0x3E: XK_Shift_R
357 0, // 0x3F: XK_KP_Multiply
358 XK_Alt_L, // 0x40: XK_Alt_L
359 XK_space, // 0x41: XK_space
360 XK_Caps_Lock, // 0x42: XK_Caps_Lock
361 XK_F1, // 0x43: XK_F1
362 XK_F2, // 0x44: XK_F2
363 XK_F3, // 0x45: XK_F3
364 XK_F4, // 0x46: XK_F4
365 XK_F5, // 0x47: XK_F5
366 XK_F6, // 0x48: XK_F6
367 XK_F7, // 0x49: XK_F7
368 XK_F8, // 0x4A: XK_F8
369 XK_F9, // 0x4B: XK_F9
370 XK_F10, // 0x4C: XK_F10
371 XK_Num_Lock, // 0x4D: XK_Num_Lock
372 XK_Scroll_Lock, // 0x4E: XK_Scroll_Lock
373 };
374
375 return hardware_code < arraysize(kHardwareKeycodeMap) ?
376 kHardwareKeycodeMap[hardware_code] : 0;
377 }
378
281 } // namespace ui 379 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/keycodes/keyboard_code_conversion_x.h ('k') | views/events/event_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698