| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/dom4/keycode_converter.h" | 5 #include "ui/events/keycodes/dom4/keycode_converter.h" |
| 6 | 6 |
| 7 namespace ui { | 7 namespace ui { |
| 8 | 8 |
| 9 namespace { | 9 namespace { |
| 10 | 10 |
| 11 #if defined(OS_WIN) | 11 #if defined(OS_LINUX) |
| 12 #define USB_KEYMAP(usb, xkb, win, mac, code) {usb, win, code} | |
| 13 #elif defined(OS_LINUX) | |
| 14 #define USB_KEYMAP(usb, xkb, win, mac, code) {usb, xkb, code} | 12 #define USB_KEYMAP(usb, xkb, win, mac, code) {usb, xkb, code} |
| 15 #elif defined(OS_MACOSX) | |
| 16 #define USB_KEYMAP(usb, xkb, win, mac, code) {usb, mac, code} | |
| 17 #else | 13 #else |
| 18 #define USB_KEYMAP(usb, xkb, win, mac, code) {usb, 0, code} | 14 #define USB_KEYMAP(usb, xkb, win, mac, code) {usb, 0, code} |
| 19 #endif | 15 #endif |
| 20 #include "ui/events/keycodes/dom4/keycode_converter_data.h" | 16 #include "ui/events/keycodes/dom4/keycode_converter_data.h" |
| 21 | 17 |
| 22 const size_t kKeycodeMapEntries = arraysize(usb_keycode_map); | 18 const size_t kKeycodeMapEntries = arraysize(usb_keycode_map); |
| 23 | 19 |
| 24 } // namespace | 20 } // namespace |
| 25 | 21 |
| 26 // static | 22 // static |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 // static | 74 // static |
| 79 uint16_t KeycodeConverter::InvalidUsbKeycode() { | 75 uint16_t KeycodeConverter::InvalidUsbKeycode() { |
| 80 return static_cast<uint16_t>(usb_keycode_map[0].usb_keycode); | 76 return static_cast<uint16_t>(usb_keycode_map[0].usb_keycode); |
| 81 } | 77 } |
| 82 | 78 |
| 83 // static | 79 // static |
| 84 uint16_t KeycodeConverter::UsbKeycodeToNativeKeycode(uint32_t usb_keycode) { | 80 uint16_t KeycodeConverter::UsbKeycodeToNativeKeycode(uint32_t usb_keycode) { |
| 85 // Deal with some special-cases that don't fit the 1:1 mapping. | 81 // Deal with some special-cases that don't fit the 1:1 mapping. |
| 86 if (usb_keycode == 0x070032) // non-US hash. | 82 if (usb_keycode == 0x070032) // non-US hash. |
| 87 usb_keycode = 0x070031; // US backslash. | 83 usb_keycode = 0x070031; // US backslash. |
| 88 #if defined(OS_MACOSX) | |
| 89 if (usb_keycode == 0x070046) // PrintScreen. | |
| 90 usb_keycode = 0x070068; // F13. | |
| 91 #endif | |
| 92 | 84 |
| 93 for (size_t i = 0; i < kKeycodeMapEntries; ++i) { | 85 for (size_t i = 0; i < kKeycodeMapEntries; ++i) { |
| 94 if (usb_keycode_map[i].usb_keycode == usb_keycode) | 86 if (usb_keycode_map[i].usb_keycode == usb_keycode) |
| 95 return usb_keycode_map[i].native_keycode; | 87 return usb_keycode_map[i].native_keycode; |
| 96 } | 88 } |
| 97 return InvalidNativeKeycode(); | 89 return InvalidNativeKeycode(); |
| 98 } | 90 } |
| 99 | 91 |
| 100 // static | 92 // static |
| 101 uint32_t KeycodeConverter::NativeKeycodeToUsbKeycode(uint16_t native_keycode) { | 93 uint32_t KeycodeConverter::NativeKeycodeToUsbKeycode(uint16_t native_keycode) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 125 for (size_t i = 0; i < kKeycodeMapEntries; ++i) { | 117 for (size_t i = 0; i < kKeycodeMapEntries; ++i) { |
| 126 if (usb_keycode_map[i].code && | 118 if (usb_keycode_map[i].code && |
| 127 strcmp(usb_keycode_map[i].code, code) == 0) { | 119 strcmp(usb_keycode_map[i].code, code) == 0) { |
| 128 return usb_keycode_map[i].usb_keycode; | 120 return usb_keycode_map[i].usb_keycode; |
| 129 } | 121 } |
| 130 } | 122 } |
| 131 return InvalidUsbKeycode(); | 123 return InvalidUsbKeycode(); |
| 132 } | 124 } |
| 133 | 125 |
| 134 } // namespace ui | 126 } // namespace ui |
| OLD | NEW |