summaryrefslogtreecommitdiffstats
path: root/ui/base/keycodes
diff options
context:
space:
mode:
authorwez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-23 14:14:24 +0000
committerwez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-23 14:14:24 +0000
commit662d091e3a9f13158274577f0ddc94f424e39959 (patch)
tree369efe7bcb7eada253b2a544df3df0b0a4b54ffd /ui/base/keycodes
parent8f72269f2b1e3bfe229ba26612aef17c8f1a6f52 (diff)
downloadchromium_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
Diffstat (limited to 'ui/base/keycodes')
-rw-r--r--ui/base/keycodes/usb_keycode_map.h20
-rw-r--r--ui/base/keycodes/usb_keycode_map_unittest.cc10
2 files changed, 22 insertions, 8 deletions
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) {