OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/events/keycodes/keyboard_code_conversion_x.h" | 5 #include "ui/events/keycodes/keyboard_code_conversion_x.h" |
6 | 6 |
7 #define XK_3270 // for XK_3270_BackTab | 7 #define XK_3270 // for XK_3270_BackTab |
8 #include <X11/keysym.h> | 8 #include <X11/keysym.h> |
9 #include <X11/Xlib.h> | 9 #include <X11/Xlib.h> |
10 #include <X11/Xutil.h> | 10 #include <X11/Xutil.h> |
11 #include <X11/XF86keysym.h> | 11 #include <X11/XF86keysym.h> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "base/strings/sys_string_conversions.h" |
16 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
17 #include "ui/events/keycodes/dom4/keycode_converter.h" | 18 #include "ui/events/keycodes/dom4/keycode_converter.h" |
18 | 19 |
19 namespace ui { | 20 namespace ui { |
20 | 21 |
21 // Get an ui::KeyboardCode from an X keyevent | 22 // Get an ui::KeyboardCode from an X keyevent |
22 KeyboardCode KeyboardCodeFromXKeyEvent(XEvent* xev) { | 23 KeyboardCode KeyboardCodeFromXKeyEvent(XEvent* xev) { |
23 // XLookupKeysym does not take into consideration the state of the lock/shift | 24 // XLookupKeysym does not take into consideration the state of the lock/shift |
24 // etc. keys. So it is necessary to use XLookupString instead. | 25 // etc. keys. So it is necessary to use XLookupString instead. |
25 KeySym keysym; | 26 KeySym keysym; |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 const char* CodeFromXEvent(XEvent* xev) { | 430 const char* CodeFromXEvent(XEvent* xev) { |
430 return KeycodeConverter::GetInstance()->NativeKeycodeToCode( | 431 return KeycodeConverter::GetInstance()->NativeKeycodeToCode( |
431 xev->xkey.keycode); | 432 xev->xkey.keycode); |
432 } | 433 } |
433 | 434 |
434 uint16 GetCharacterFromXEvent(XEvent* xev) { | 435 uint16 GetCharacterFromXEvent(XEvent* xev) { |
435 char buf[6]; | 436 char buf[6]; |
436 int bytes_written = XLookupString(&xev->xkey, buf, 6, NULL, NULL); | 437 int bytes_written = XLookupString(&xev->xkey, buf, 6, NULL, NULL); |
437 DCHECK_LE(bytes_written, 6); | 438 DCHECK_LE(bytes_written, 6); |
438 | 439 |
439 base::string16 result; | 440 if (bytes_written <= 0) |
440 return (bytes_written > 0 && base::UTF8ToUTF16(buf, bytes_written, &result) && | 441 return 0; |
441 result.length() == 1) ? result[0] : 0; | 442 const base::string16& result = base::WideToUTF16( |
| 443 base::SysNativeMBToWide(base::StringPiece(buf, bytes_written))); |
| 444 return result.length() == 1 ? result[0] : 0; |
442 } | 445 } |
443 | 446 |
444 unsigned int DefaultXKeysymFromHardwareKeycode(unsigned int hardware_code) { | 447 unsigned int DefaultXKeysymFromHardwareKeycode(unsigned int hardware_code) { |
445 // This function assumes that X11 is using evdev-based keycodes. | 448 // This function assumes that X11 is using evdev-based keycodes. |
446 static const unsigned int kHardwareKeycodeMap[] = { | 449 static const unsigned int kHardwareKeycodeMap[] = { |
447 // This table covers the core 105-key keyboard. | 450 // This table covers the core 105-key keyboard. |
448 0, // 0x00: | 451 0, // 0x00: |
449 0, // 0x01: | 452 0, // 0x01: |
450 0, // 0x02: | 453 0, // 0x02: |
451 0, // 0x03: | 454 0, // 0x03: |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
867 case VKEY_KBD_BRIGHTNESS_UP: | 870 case VKEY_KBD_BRIGHTNESS_UP: |
868 return XF86XK_KbdBrightnessUp; | 871 return XF86XK_KbdBrightnessUp; |
869 | 872 |
870 default: | 873 default: |
871 LOG(WARNING) << "Unknown keycode:" << keycode; | 874 LOG(WARNING) << "Unknown keycode:" << keycode; |
872 return 0; | 875 return 0; |
873 } | 876 } |
874 } | 877 } |
875 | 878 |
876 } // namespace ui | 879 } // namespace ui |
OLD | NEW |