Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Unified Diff: ui/base/keycodes/usb_keycode_map.h

Issue 23542008: Add a CodeToNativeKeycode helper that converts UIEvent code to native code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing CR feedback Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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.

Powered by Google App Engine
This is Rietveld 408576698