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 // Data in this file was created by referencing: | 5 // Data in this file was created by referencing: |
6 // USB HID Usage Tables (v1.11) 27 June 2001 | 6 // USB HID Usage Tables (v1.11) 27 June 2001 |
7 // HIToolbox/Events.h (Mac) | 7 // HIToolbox/Events.h (Mac) |
8 | 8 |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
392 for (size_t i = 0; i < arraysize(usb_keycode_map); ++i) { | 392 for (size_t i = 0; i < arraysize(usb_keycode_map); ++i) { |
393 if (usb_keycode_map[i].native_keycode == native_keycode) { | 393 if (usb_keycode_map[i].native_keycode == native_keycode) { |
394 if (usb_keycode_map[i].code != NULL) | 394 if (usb_keycode_map[i].code != NULL) |
395 return usb_keycode_map[i].code; | 395 return usb_keycode_map[i].code; |
396 break; | 396 break; |
397 } | 397 } |
398 } | 398 } |
399 return InvalidKeyboardEventCode(); | 399 return InvalidKeyboardEventCode(); |
400 } | 400 } |
401 | 401 |
402 inline uint16_t CodeToNativeKeycode(const char* code) { | |
403 if (code) { | |
Wez
2013/09/05 00:16:33
You don't need this if - the loop will exit on the
Wez
2013/09/05 00:16:33
You should explicitly check for "Unidentified" her
weitao
2013/09/05 07:49:17
I do need this "if". Otherwise strcmp would crash.
Wez
2013/09/05 19:07:02
Yes, sorry; missed that you're not comparing the p
| |
404 // TODO: sort |usb_keycode_map| by |code| so we can use binary search here. | |
Wez
2013/09/05 00:16:33
This comment assumes that linear search performanc
weitao
2013/09/05 07:49:17
Done.
| |
405 for (size_t i = 0; i < arraysize(usb_keycode_map); ++i) { | |
406 if (usb_keycode_map[i].code && strcmp(usb_keycode_map[i].code, code) == 0) | |
Wez
2013/09/05 00:16:33
Split this into two if()s for clarity.
weitao
2013/09/05 07:49:17
I feel the purpose of two conditions connected by
Wez
2013/09/05 19:07:02
Right - I'm suggesting:
if (!code)
continue;
if
| |
407 return usb_keycode_map[i].native_keycode; | |
408 } | |
409 } | |
410 return InvalidNativeKeycode(); | |
411 } | |
412 | |
402 // USB keycodes | 413 // USB keycodes |
403 // Note that USB keycodes are not part of any web standard. | 414 // Note that USB keycodes are not part of any web standard. |
404 // Please don't use USB keycodes in new code. | 415 // Please don't use USB keycodes in new code. |
405 | 416 |
406 inline uint16_t InvalidUsbKeycode() { | 417 inline uint16_t InvalidUsbKeycode() { |
407 return usb_keycode_map[0].usb_keycode; | 418 return usb_keycode_map[0].usb_keycode; |
408 } | 419 } |
409 | 420 |
410 inline uint16_t UsbKeycodeToNativeKeycode(uint32_t usb_keycode) { | 421 inline uint16_t UsbKeycodeToNativeKeycode(uint32_t usb_keycode) { |
411 // Deal with some special-cases that don't fit the 1:1 mapping. | 422 // Deal with some special-cases that don't fit the 1:1 mapping. |
(...skipping 19 matching lines...) Expand all Loading... | |
431 return InvalidUsbKeycode(); | 442 return InvalidUsbKeycode(); |
432 } | 443 } |
433 | 444 |
434 inline const char* UsbKeycodeToCode(uint32_t usb_keycode) { | 445 inline const char* UsbKeycodeToCode(uint32_t usb_keycode) { |
435 for (size_t i = 0; i < arraysize(usb_keycode_map); ++i) { | 446 for (size_t i = 0; i < arraysize(usb_keycode_map); ++i) { |
436 if (usb_keycode_map[i].usb_keycode == usb_keycode) | 447 if (usb_keycode_map[i].usb_keycode == usb_keycode) |
437 return usb_keycode_map[i].code; | 448 return usb_keycode_map[i].code; |
438 } | 449 } |
439 return InvalidKeyboardEventCode(); | 450 return InvalidKeyboardEventCode(); |
440 } | 451 } |
OLD | NEW |