OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "webkit/plugins/ppapi/usb_scan_code_conversion.h" |
| 6 |
| 7 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 8 |
| 9 using WebKit::WebKeyboardEvent; |
| 10 |
| 11 namespace webkit { |
| 12 namespace ppapi { |
| 13 |
| 14 namespace { |
| 15 |
| 16 // TODO(garykac): This table covers only USB HID Boot Protocol. It should be |
| 17 // extended (e.g. with "media keys"), or derived automatically from the |
| 18 // evdev USB-to-linux keycode mapping. |
| 19 uint16_t linux_evdev_key_code_to_usb[256] = { |
| 20 // 0x00-0x0f |
| 21 0x0000, 0x0029, 0x001e, 0x001f, 0x0020, 0x0021, 0x0022, 0x0023, |
| 22 0x0024, 0x0025, 0x0026, 0x0027, 0x002d, 0x002e, 0x002a, 0x002b, |
| 23 // 0x10-0x1f |
| 24 0x0014, 0x001a, 0x0008, 0x0015, 0x0017, 0x001c, 0x0018, 0x000c, |
| 25 0x0012, 0x0013, 0x002f, 0x0030, 0x0028, 0x00e0, 0x0004, 0x0016, |
| 26 // 0x20-0x2f |
| 27 0x0007, 0x0009, 0x000a, 0x000b, 0x000d, 0x000e, 0x000f, 0x0033, |
| 28 0x0034, 0x0035, 0x00e1, 0x0032, 0x001d, 0x001b, 0x0006, 0x0019, |
| 29 // 0x30-0x3f |
| 30 0x0005, 0x0011, 0x0010, 0x0036, 0x0037, 0x0038, 0x00e5, 0x0055, |
| 31 0x00e2, 0x002c, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, |
| 32 // 0x40-0x4f |
| 33 0x003f, 0x0040, 0x0041, 0x0042, 0x0043, 0x0053, 0x0047, 0x005f, |
| 34 0x0060, 0x0061, 0x0056, 0x005c, 0x005d, 0x005e, 0x0057, 0x0059, |
| 35 // 0x50-0x5f |
| 36 0x005a, 0x005b, 0x0062, 0x0063, 0x0000, 0x0094, 0x0064, 0x0044, |
| 37 0x0045, 0x0087, 0x0092, 0x0093, 0x008a, 0x0088, 0x008b, 0x008c, |
| 38 // 0x60-0x6f |
| 39 0x0058, 0x00e4, 0x0054, 0x0046, 0x00e6, 0x0000, 0x004a, 0x0052, |
| 40 0x004b, 0x0050, 0x004f, 0x004d, 0x0051, 0x004e, 0x0049, 0x004c, |
| 41 // 0x70-0x7f |
| 42 0x0000, 0x00ef, 0x00ee, 0x00ed, 0x0066, 0x0067, 0x0000, 0x0048, |
| 43 0x0000, 0x0085, 0x0090, 0x0091, 0x0089, 0x00e3, 0x00e7, 0x0065, |
| 44 // 0x80-0x8f |
| 45 0x00f3, 0x0079, 0x0076, 0x007a, 0x0077, 0x007c, 0x0074, 0x007d, |
| 46 0x00f4, 0x007b, 0x0075, 0x0000, 0x00fb, 0x0000, 0x00f8, 0x0000, |
| 47 // 0x90-0x9f |
| 48 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x00f0, 0x0000, |
| 49 0x00f9, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x00f1, 0x00f2, |
| 50 // 0xa0-0xaf |
| 51 0x0000, 0x00ec, 0x0000, 0x00eb, 0x00e8, 0x00ea, 0x00e9, 0x0000, |
| 52 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x00fa, 0x0000, 0x0000, |
| 53 // 0xb0-0xbf |
| 54 0x00f7, 0x00f5, 0x00f6, 0x0000, 0x0000, 0x0000, 0x0000, 0x0068, |
| 55 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, 0x0070, |
| 56 // 0xc0-0xcf |
| 57 0x0071, 0x0072, 0x0073, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
| 58 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
| 59 // 0xd0-0xdf |
| 60 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
| 61 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
| 62 // 0xe0-0xef |
| 63 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
| 64 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
| 65 // 0xf0-0xff |
| 66 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
| 67 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
| 68 }; |
| 69 |
| 70 } // anonymous namespace |
| 71 |
| 72 uint32_t UsbScanCodeForKeyboardEvent(const WebKeyboardEvent& key_event) { |
| 73 // TODO(garykac): This code assumes that on Linux we're receiving events via |
| 74 // the Xorg "evdev" driver. We should detect "XKB" or "kbd" at run-time and |
| 75 // re-map accordingly, but that's not possible here, inside the sandbox. |
| 76 if (key_event.nativeKeyCode < 0 || key_event.nativeKeyCode > 255) |
| 77 return 0; |
| 78 |
| 79 uint32_t scancode = 0; |
| 80 uint16_t code = linux_evdev_key_code_to_usb[key_event.nativeKeyCode]; |
| 81 if (code != 0) { |
| 82 // Set complete scancode to be the USB keyboard page (7) and key scancode. |
| 83 scancode = 0x070000 | code; |
| 84 } |
| 85 return scancode; |
| 86 } |
| 87 |
| 88 } // namespace ppapi |
| 89 } // namespace webkit |
OLD | NEW |