Index: ui/base/keycodes/usb_keycode_map.h |
diff --git a/ui/base/keycodes/usb_keycode_map.h b/ui/base/keycodes/usb_keycode_map.h |
index 90cd7ed71723e4ba6dcdb3ecb9248bac942140bd..1ebbbbbb3fdbd1ea1e6dec3db5f94239c1d49910 100644 |
--- a/ui/base/keycodes/usb_keycode_map.h |
+++ b/ui/base/keycodes/usb_keycode_map.h |
@@ -399,6 +399,17 @@ inline const char* NativeKeycodeToCode(uint16_t native_keycode) { |
return InvalidKeyboardEventCode(); |
} |
+inline uint16_t CodeToNativeKeycode(const char* code) { |
+ 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
|
+ // 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.
|
+ for (size_t i = 0; i < arraysize(usb_keycode_map); ++i) { |
+ 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
|
+ return usb_keycode_map[i].native_keycode; |
+ } |
+ } |
+ return InvalidNativeKeycode(); |
+} |
+ |
// USB keycodes |
// Note that USB keycodes are not part of any web standard. |
// Please don't use USB keycodes in new code. |