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

Side by Side 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 unified diff | Download patch
OLDNEW
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
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 ||
404 strcmp(code, InvalidKeyboardEventCode()) == 0) {
405 return InvalidNativeKeycode();
406 }
407
408 for (size_t i = 0; i < arraysize(usb_keycode_map); ++i) {
409 if (usb_keycode_map[i].code &&
410 strcmp(usb_keycode_map[i].code, code) == 0) {
411 return usb_keycode_map[i].native_keycode;
412 }
413 }
414 return InvalidNativeKeycode();
415 }
416
402 // USB keycodes 417 // USB keycodes
403 // Note that USB keycodes are not part of any web standard. 418 // Note that USB keycodes are not part of any web standard.
404 // Please don't use USB keycodes in new code. 419 // Please don't use USB keycodes in new code.
405 420
406 inline uint16_t InvalidUsbKeycode() { 421 inline uint16_t InvalidUsbKeycode() {
407 return usb_keycode_map[0].usb_keycode; 422 return usb_keycode_map[0].usb_keycode;
408 } 423 }
409 424
410 inline uint16_t UsbKeycodeToNativeKeycode(uint32_t usb_keycode) { 425 inline uint16_t UsbKeycodeToNativeKeycode(uint32_t usb_keycode) {
411 // Deal with some special-cases that don't fit the 1:1 mapping. 426 // Deal with some special-cases that don't fit the 1:1 mapping.
(...skipping 19 matching lines...) Expand all
431 return InvalidUsbKeycode(); 446 return InvalidUsbKeycode();
432 } 447 }
433 448
434 inline const char* UsbKeycodeToCode(uint32_t usb_keycode) { 449 inline const char* UsbKeycodeToCode(uint32_t usb_keycode) {
435 for (size_t i = 0; i < arraysize(usb_keycode_map); ++i) { 450 for (size_t i = 0; i < arraysize(usb_keycode_map); ++i) {
436 if (usb_keycode_map[i].usb_keycode == usb_keycode) 451 if (usb_keycode_map[i].usb_keycode == usb_keycode)
437 return usb_keycode_map[i].code; 452 return usb_keycode_map[i].code;
438 } 453 }
439 return InvalidKeyboardEventCode(); 454 return InvalidKeyboardEventCode();
440 } 455 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698