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

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..1985f1d16b0899144a660d3d92cc2538dfe01766 100644
--- a/ui/base/keycodes/usb_keycode_map.h
+++ b/ui/base/keycodes/usb_keycode_map.h
@@ -399,6 +399,18 @@ inline const char* NativeKeycodeToCode(uint16_t native_keycode) {
return InvalidKeyboardEventCode();
}
+inline uint16_t CodeToNativeKeycode(const char* code) {
+ if (!code ||
+ strcmp(code, InvalidKeyboardEventCode()) == 0)
+ return InvalidNativeKeycode();
+
+ 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)
+ 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