diff options
author | wez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-23 14:14:24 +0000 |
---|---|---|
committer | wez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-23 14:14:24 +0000 |
commit | 662d091e3a9f13158274577f0ddc94f424e39959 (patch) | |
tree | 369efe7bcb7eada253b2a544df3df0b0a4b54ffd | |
parent | 8f72269f2b1e3bfe229ba26612aef17c8f1a6f52 (diff) | |
download | chromium_src-662d091e3a9f13158274577f0ddc94f424e39959.zip chromium_src-662d091e3a9f13158274577f0ddc94f424e39959.tar.gz chromium_src-662d091e3a9f13158274577f0ddc94f424e39959.tar.bz2 |
Switch Pepper Linux to use shared USB<->native key conversion table.
This fixes issues with the Linux table lagging behind the shared version, and:
- Marks the UsbKeycodeToNativeKeycode helper "inline", for now, to avoid the warning on unused static functions, and since it is sufficiently simple to make sense to inline.
- Tweaks the types of the array iterator in the other platform-specific implementations.
BUG=177278,118432,165704
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=183841
Review URL: https://chromiumcodereview.appspot.com/12320014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@184318 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | remoting/host/desktop_session_agent.cc | 3 | ||||
-rw-r--r-- | remoting/host/event_executor_linux.cc | 2 | ||||
-rw-r--r-- | remoting/host/event_executor_mac.cc | 2 | ||||
-rw-r--r-- | remoting/host/event_executor_win.cc | 2 | ||||
-rw-r--r-- | ui/base/keycodes/usb_keycode_map.h | 20 | ||||
-rw-r--r-- | ui/base/keycodes/usb_keycode_map_unittest.cc | 10 | ||||
-rw-r--r-- | webkit/plugins/ppapi/usb_key_code_conversion_linux.cc | 155 | ||||
-rw-r--r-- | webkit/plugins/ppapi/usb_key_code_conversion_mac.cc | 12 | ||||
-rw-r--r-- | webkit/plugins/ppapi/usb_key_code_conversion_win.cc | 8 |
9 files changed, 35 insertions, 179 deletions
diff --git a/remoting/host/desktop_session_agent.cc b/remoting/host/desktop_session_agent.cc index 6f0996e..cd47677 100644 --- a/remoting/host/desktop_session_agent.cc +++ b/remoting/host/desktop_session_agent.cc @@ -437,7 +437,8 @@ void DesktopSessionAgent::OnInjectKeyEvent( // Ignore unknown keycodes. if (event.has_usb_keycode() && - UsbKeycodeToNativeKeycode(event.usb_keycode()) == kInvalidKeycode) { + (UsbKeycodeToNativeKeycode(event.usb_keycode()) == + InvalidNativeKeycode())) { LOG(ERROR) << "KeyEvent: unknown USB keycode: " << std::hex << event.usb_keycode() << std::dec; return; diff --git a/remoting/host/event_executor_linux.cc b/remoting/host/event_executor_linux.cc index 0cc6cf9..e668b16 100644 --- a/remoting/host/event_executor_linux.cc +++ b/remoting/host/event_executor_linux.cc @@ -215,7 +215,7 @@ void EventExecutorLinux::Core::InjectKeyEvent(const KeyEvent& event) { << " to keycode: " << keycode << std::dec; // Ignore events which can't be mapped. - if (keycode == kInvalidKeycode) + if (keycode == InvalidNativeKeycode()) return; if (event.pressed()) { diff --git a/remoting/host/event_executor_mac.cc b/remoting/host/event_executor_mac.cc index 2c778c4..bdd6034 100644 --- a/remoting/host/event_executor_mac.cc +++ b/remoting/host/event_executor_mac.cc @@ -161,7 +161,7 @@ void EventExecutorMac::Core::InjectKeyEvent(const KeyEvent& event) { << " to keycode: " << keycode << std::dec; // If we couldn't determine the Mac virtual key code then ignore the event. - if (keycode == kInvalidKeycode) + if (keycode == InvalidNativeKeycode()) return; // We use the deprecated event injection API because the new one doesn't diff --git a/remoting/host/event_executor_win.cc b/remoting/host/event_executor_win.cc index 66e6059..02e0f4c 100644 --- a/remoting/host/event_executor_win.cc +++ b/remoting/host/event_executor_win.cc @@ -197,7 +197,7 @@ void EventExecutorWin::Core::HandleKey(const KeyEvent& event) { << " to scancode: " << scancode << std::dec; // Ignore events which can't be mapped. - if (scancode == kInvalidKeycode) + if (scancode == InvalidNativeKeycode()) return; // Windows scancodes are only 8-bit, so store the low-order byte into the diff --git a/ui/base/keycodes/usb_keycode_map.h b/ui/base/keycodes/usb_keycode_map.h index 53b8627..6549bf8 100644 --- a/ui/base/keycodes/usb_keycode_map.h +++ b/ui/base/keycodes/usb_keycode_map.h @@ -376,9 +376,15 @@ const usb_keymap usb_keycode_map[] = { USB_KEYMAP(0x0c028c, 0x00ef, 0x0000, 0xffff), // AC_Send }; -const uint16_t kInvalidKeycode = usb_keycode_map[0].native_keycode; +inline uint16_t InvalidNativeKeycode() { + return usb_keycode_map[0].native_keycode; +} + +inline uint16_t InvalidUsbKeycode() { + return usb_keycode_map[0].usb_keycode; +} -static uint16 UsbKeycodeToNativeKeycode(uint32_t usb_keycode) { +inline uint16_t UsbKeycodeToNativeKeycode(uint32_t usb_keycode) { // Deal with some special-cases that don't fit the 1:1 mapping. if (usb_keycode == 0x070032) // non-US hash. usb_keycode = 0x070031; // US backslash. @@ -391,5 +397,13 @@ static uint16 UsbKeycodeToNativeKeycode(uint32_t usb_keycode) { if (usb_keycode_map[i].usb_keycode == usb_keycode) return usb_keycode_map[i].native_keycode; } - return kInvalidKeycode; + return InvalidNativeKeycode(); +} + +inline uint32_t NativeKeycodeToUsbKeycode(uint16_t native_keycode) { + for (size_t i = 0; i < arraysize(usb_keycode_map); ++i) { + if (usb_keycode_map[i].native_keycode == native_keycode) + return usb_keycode_map[i].usb_keycode; + } + return InvalidUsbKeycode(); } diff --git a/ui/base/keycodes/usb_keycode_map_unittest.cc b/ui/base/keycodes/usb_keycode_map_unittest.cc index add2edf..09e4258 100644 --- a/ui/base/keycodes/usb_keycode_map_unittest.cc +++ b/ui/base/keycodes/usb_keycode_map_unittest.cc @@ -25,22 +25,21 @@ const size_t kExpectedMappedKeyCount = 0; #include "ui/base/keycodes/usb_keycode_map.h" #undef USB_KEYMAP -const uint32_t kUsbInvalidKeycode = 0x000000; const uint32_t kUsbNonExistentKeycode = 0xffffff; const uint32_t kUsbUsBackslash = 0x070031; const uint32_t kUsbNonUsHash = 0x070032; TEST(UsbKeycodeMap, Basic) { // Verify that the first element in the table is the "invalid" code. - EXPECT_EQ(kUsbInvalidKeycode, usb_keycode_map[0].usb_keycode); - EXPECT_EQ(kInvalidKeycode, usb_keycode_map[0].native_keycode); + EXPECT_EQ(InvalidUsbKeycode(), usb_keycode_map[0].usb_keycode); + EXPECT_EQ(InvalidNativeKeycode(), usb_keycode_map[0].native_keycode); // Verify that there are no duplicate entries in the mapping. std::map<uint32_t, uint16_t> usb_to_native; std::map<uint16_t, uint32_t> native_to_usb; for (size_t i = 0; i < arraysize(usb_keycode_map); ++i) { // Don't test keys with no native keycode mapping on this platform. - if (usb_keycode_map[i].native_keycode == kInvalidKeycode) + if (usb_keycode_map[i].native_keycode == InvalidNativeKeycode()) continue; // Verify UsbKeycodeToNativeKeycode works for this key. @@ -78,7 +77,8 @@ TEST(UsbKeycodeMap, Basic) { TEST(UsbKeycodeMap, NonExistent) { // Verify that UsbKeycodeToNativeKeycode works for a non-existent USB keycode. - EXPECT_EQ(kInvalidKeycode, UsbKeycodeToNativeKeycode(kUsbNonExistentKeycode)); + EXPECT_EQ(InvalidNativeKeycode(), + UsbKeycodeToNativeKeycode(kUsbNonExistentKeycode)); } TEST(UsbKeycodeMap, UsBackslashIsNonUsHash) { diff --git a/webkit/plugins/ppapi/usb_key_code_conversion_linux.cc b/webkit/plugins/ppapi/usb_key_code_conversion_linux.cc index d99601d..8ba6949 100644 --- a/webkit/plugins/ppapi/usb_key_code_conversion_linux.cc +++ b/webkit/plugins/ppapi/usb_key_code_conversion_linux.cc @@ -5,7 +5,6 @@ #include "webkit/plugins/ppapi/usb_key_code_conversion.h" #include "base/basictypes.h" -#include "base/logging.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" using WebKit::WebKeyboardEvent; @@ -15,162 +14,18 @@ namespace ppapi { namespace { -// Mapping from 8-bit xkb scancode to 32-bit USB Usage Page and Id. -// -// TODO(garykac): This table covers only USB HID Boot Protocol. The keys -// marked with '???' should be extended (e.g. with "media keys"), or derived -// automatically from the USB-to-linux keycode mapping. -uint32_t linux_xkb_code_to_usb[] = { - // 00-04: unused - 0x000000, 0x000000, 0x000000, 0x000000, - // 04-07: unused - 0x000000, 0x000000, 0x000000, 0x000000, - // 08-0b: unused Escape 1! 2@ - 0x000000, 0x070029, 0x07001e, 0x07001f, - // 0c-0f: 3# 4$ 5% 6^ - 0x070020, 0x070021, 0x070022, 0x070023, - // 10-13: 7& 8* 9( 0) - 0x070024, 0x070025, 0x070026, 0x070027, - // 14-17: -_ =+ Backspace Tab - 0x07002d, 0x07002e, 0x07002a, 0x07002b, - // 18-1b: qQ wW eE rR - 0x070014, 0x07001a, 0x070008, 0x070015, - // 1c-1f: tT yY uU iI - 0x070017, 0x07001c, 0x070018, 0x07000c, - // 20-23: oO pP [{ ]} - 0x070012, 0x070013, 0x07002f, 0x070030, - // 24-27: Return LeftControl aA sS - 0x070028, 0x0700e0, 0x070004, 0x070016, - // 28-2b: dD fF gG hH - 0x070007, 0x070009, 0x07000a, 0x07000b, - // 2c-2f: jJ kK lL ;: - 0x07000d, 0x07000e, 0x07000f, 0x070033, - // 30-33: '" `~ LeftShift \| - 0x070034, 0x070035, 0x0700e1, 0x070031, - // 34-37: zZ xX cC vV - 0x07001d, 0x07001b, 0x070006, 0x070019, - // 38-3b: bB nN mM ,< - 0x070005, 0x070011, 0x070010, 0x070036, - // 3c-3f: .> /? RightShift Keypad_* - 0x070037, 0x070038, 0x0700e5, 0x070055, - // 40-43: LeftAlt Space CapsLock F1 - 0x0700e2, 0x07002c, 0x070039, 0x07003a, - // 44-47: F2 F3 F4 F5 - 0x07003b, 0x07003c, 0x07003d, 0x07003e, - // 48-4b: F6 F7 F8 F9 - 0x07003f, 0x070040, 0x070041, 0x070042, - // 4c-4f: F10 NumLock ScrollLock Keypad_7 - 0x070043, 0x070053, 0x070047, 0x07005f, - // 50-53: Keypad_8 Keypad_9 Keypad_- Keypad_4 - 0x070060, 0x070061, 0x070056, 0x07005c, - // 54-57: Keypad_5 Keypad_6 Keypad_+ Keypad_1 - 0x07005d, 0x07005e, 0x070057, 0x070059, - // 58-5b: Keypad_2 Keypad_3 Keypad_0 Keypad_. - 0x07005a, 0x07005b, 0x070062, 0x070063, - // 5c-5f: ISO_Level3_Shift unused <>|| F11 - 0x000000, 0x000000, 0x070064, 0x070044, - // 60-63: F12 unused Katakana Hiragana - 0x070045, 0x000000, 0x070092, 0x070093, - // 64-67: Henkan Hiragana_Katakana Muhenkan unused - 0x070094, 0x070088, 0x07008b, 0x000000, - // 68-6b: Keypad_Enter RightControl Keypad_/ Print/SysReq - // For 6b, USB#0046 is PrintScreen, USB#009a is SysReq/Attention - 0x070058, 0x0700e4, 0x070054, 0x070046, - // 6c-6f: RightAlt Linefeed Home UpArrow - 0x0700e6, 0x000000, 0x07004a, 0x070052, - // 70-73: PageUp/Prior LeftArrow RightArrow End - 0x07004b, 0x070050, 0x07004f, 0x07004d, - // 74-77: DownArrow PageDown/Next Insert Delete/ForwardDelete - 0x070051, 0x07004e, 0x070049, 0x07004c, - // 78-7b: unused Mute VolumeDown VolumeUp - 0x000000, 0x07007f, 0x070081, 0x070080, - // 7c-7f: PowerOff Keypad_= Keypad_+- Pause/Break - 0x070066, 0x070067, 0x0700d7, 0x070048, - // 80-83: LaunchA Keypad_Decimal HangulToggle HanjaConversion - // For 81, cf. 5b: Keypad_. - 0x000000, 0x0700dc, 0x070090, 0x070091, - // 84-87: unused LeftSuper/LeftWin RightSuper/RightWin Menu - 0x000000, 0x0700e3, 0x0700e7, 0x070065, - // 88-8b: Cancel Again/Redo CrSel/Props Undo - 0x07009b, 0x070079, 0x0700a3, 0x07007a, - // 8c-8f: SunFront Copy SunOpen Paste - 0x000000, 0x07007c, 0x000000, 0x07007d, - // 90-93: Find Cut Help MenuKB - // For 93, cf. 87 (Menu) and c1 (MenuKB) - 0x07007e, 0x07007b, 0x070075, 0x000000, - // 94-97: AL_Calculator unused Sleep WakeUp - 0x0c0192, 0x000000, 0x000000, 0x000000, - // 98-9b: Explorer Send unused Xfer - 0x000000, 0x000000, 0x000000, 0x000000, - // 9c-9f: Launch1 Launch2 WWW DOS - 0x000000, 0x000000, 0x000000, 0x000000, - // a0-a3: ScreenSaver unused RotateWindows Mail - 0x000000, 0x000000, 0x000000, 0x000000, - // a4-a7: Favorites MyComputer Back Forward - 0x000000, 0x000000, 0x000000, 0x000000, - // a8-ab: unused Eject Eject AudioNext - 0x000000, 0x000000, 0x000000, 0x000000, - // ac-af: AudioPlay AudioPrev AudioStop AudioRecord - 0x000000, 0x000000, 0x000000, 0x000000, - // b0-b3: AudioRewind Phone unused Tools - 0x000000, 0x000000, 0x000000, 0x000000, - // b4-b7: HomePage Reload Close unused - 0x000000, 0x000000, 0x000000, 0x000000, - // b8-bb: unused ScrollUp ScrollDown ( - // For bb, mapped to Keypad_( - 0x000000, 0x000000, 0x000000, 0x0700b6, - // bc-bf: ) New Redo Tools - // For bc, mapped to Keypad_) - 0x0700b7, 0x000000, 0x000000, 0x000000, - // c0-c3: Launch5 MenuKB unused unused - 0x000000, 0x000000, 0x000000, 0x000000, - // c4-c7: unused - 0x000000, 0x000000, 0x000000, 0x000000, - // c8-cb: TouchpadToggle unused unused ModeSwitch - 0x000000, 0x000000, 0x000000, 0x000000, - // cc-cf: Generates no symbol without Shift. - // With shift: LeftAlt LeftMeta LeftSuper LeftHyper. - 0x000000, 0x000000, 0x000000, 0x000000, - // d0-d3: AudioPlay AudioPause Launch3 Launch4 - 0x000000, 0x000000, 0x000000, 0x000000, - // d4-d7: LaunchB Suspend Close AudioPlay - 0x000000, 0x000000, 0x000000, 0x000000, - // d8-db: AudioForward unused Print unused - 0x000000, 0x000000, 0x000000, 0x000000, - // dc-df: WebCam unused unused Mail - 0x000000, 0x000000, 0x000000, 0x000000, - // e0-e3: unused Search unused AL_Finance - 0x000000, 0x000000, 0x000000, 0x0c0191, - // e4-e7: unused Shop unused Cancel - 0x000000, 0x000000, 0x000000, 0x000000, - // e8-eb: MonBrightnessDown MonBrightnessUp AudioMedia Display - 0x000000, 0x000000, 0x000000, 0x000000, - // ec-ef: KbdLightOnOff KbdBightnessDown KdbBrightnessUp Send - 0x000000, 0x000000, 0x000000, 0x000000, - // f0-f3: Reply MailForward Save Documents - 0x000000, 0x000000, 0x000000, 0x000000, - // f4-f7: Battery Bluetooth WLAN unused - 0x000000, 0x000000, 0x000000, 0x000000, - // f8-fb: unused - 0x000000, 0x000000, 0x000000, 0x000000, - // fc-ff: unused - 0x000000, 0x000000, 0x000000, 0x000000 -}; +#define USB_KEYMAP(usb, xkb, win, mac) {usb, xkb} +#include "ui/base/keycodes/usb_keycode_map.h" +#undef USB_KEYMAP -COMPILE_ASSERT(arraysize(linux_xkb_code_to_usb) == 256, - linux_xkb_code_to_usb_table_incorrect_size); - -} // anonymous namespace +} // anonymous namespace uint32_t UsbKeyCodeForKeyboardEvent(const WebKeyboardEvent& key_event) { // TODO(garykac): This code assumes that on Linux we're receiving events via // the XKB driver. We should detect between "XKB", "kbd" and "evdev" at // run-time and re-map accordingly, but that's not possible here, inside the // sandbox. - if (key_event.nativeKeyCode < 0 || key_event.nativeKeyCode > 255) { - return 0; - } - return linux_xkb_code_to_usb[key_event.nativeKeyCode]; + return NativeKeycodeToUsbKeycode(key_event.nativeKeyCode); } } // namespace ppapi diff --git a/webkit/plugins/ppapi/usb_key_code_conversion_mac.cc b/webkit/plugins/ppapi/usb_key_code_conversion_mac.cc index fab38b6..82d109b 100644 --- a/webkit/plugins/ppapi/usb_key_code_conversion_mac.cc +++ b/webkit/plugins/ppapi/usb_key_code_conversion_mac.cc @@ -18,18 +18,10 @@ namespace { #include "ui/base/keycodes/usb_keycode_map.h" #undef USB_KEYMAP -} // anonymous namespace +} // anonymous namespace uint32_t UsbKeyCodeForKeyboardEvent(const WebKeyboardEvent& key_event) { - if (key_event.nativeKeyCode < 0 || key_event.nativeKeyCode > 0x7f) - return 0; - - for (uint i = 0; i < arraysize(usb_keycode_map); i++) { - if (usb_keycode_map[i].native_keycode == key_event.nativeKeyCode) - return usb_keycode_map[i].usb_keycode; - } - - return 0; + return NativeKeycodeToUsbKeycode(key_event.nativeKeyCode); } } // namespace ppapi diff --git a/webkit/plugins/ppapi/usb_key_code_conversion_win.cc b/webkit/plugins/ppapi/usb_key_code_conversion_win.cc index 93bdfef..c497f15 100644 --- a/webkit/plugins/ppapi/usb_key_code_conversion_win.cc +++ b/webkit/plugins/ppapi/usb_key_code_conversion_win.cc @@ -20,19 +20,13 @@ namespace { } // anonymous namespace - uint32_t UsbKeyCodeForKeyboardEvent(const WebKeyboardEvent& key_event) { // Extract the scancode and extended bit from the native key event's lParam. int scancode = (key_event.nativeKeyCode >> 16) & 0x000000FF; if ((key_event.nativeKeyCode & (1 << 24)) != 0) scancode |= 0xe000; - for (int i = 0; i < arraysize(usb_keycode_map); i++) { - if (usb_keycode_map[i].native_keycode == scancode) - return usb_keycode_map[i].usb_keycode; - } - - return 0; + return NativeKeycodeToUsbKeycode(scancode); } } // namespace ppapi |