| OLD | NEW | 
|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "ui/events/keycodes/dom/keycode_converter.h" | 5 #include "ui/events/keycodes/dom/keycode_converter.h" | 
| 6 | 6 | 
| 7 #include "base/logging.h" | 7 #include "base/logging.h" | 
| 8 #include "base/macros.h" | 8 #include "base/macros.h" | 
| 9 #include "base/strings/utf_string_conversion_utils.h" | 9 #include "base/strings/utf_string_conversion_utils.h" | 
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" | 
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 68   if (index >= kDomKeyMapEntries) | 68   if (index >= kDomKeyMapEntries) | 
| 69     return nullptr; | 69     return nullptr; | 
| 70   return dom_key_map[index].string; | 70   return dom_key_map[index].string; | 
| 71 } | 71 } | 
| 72 | 72 | 
| 73 // static | 73 // static | 
| 74 int KeycodeConverter::InvalidNativeKeycode() { | 74 int KeycodeConverter::InvalidNativeKeycode() { | 
| 75   return usb_keycode_map[0].native_keycode; | 75   return usb_keycode_map[0].native_keycode; | 
| 76 } | 76 } | 
| 77 | 77 | 
|  | 78 // TODO(zijiehe): Most of the following functions can be optimized by using | 
|  | 79 // either multiple arrays or unordered_map. | 
|  | 80 | 
| 78 // static | 81 // static | 
| 79 DomCode KeycodeConverter::NativeKeycodeToDomCode(int native_keycode) { | 82 DomCode KeycodeConverter::NativeKeycodeToDomCode(int native_keycode) { | 
| 80   for (size_t i = 0; i < kKeycodeMapEntries; ++i) { | 83   for (size_t i = 0; i < kKeycodeMapEntries; ++i) { | 
| 81     if (usb_keycode_map[i].native_keycode == native_keycode) { | 84     if (usb_keycode_map[i].native_keycode == native_keycode) { | 
| 82       if (usb_keycode_map[i].code != NULL) | 85       if (usb_keycode_map[i].code != NULL) | 
| 83         return static_cast<DomCode>(usb_keycode_map[i].usb_keycode); | 86         return static_cast<DomCode>(usb_keycode_map[i].usb_keycode); | 
| 84       break; | 87       break; | 
| 85     } | 88     } | 
| 86   } | 89   } | 
| 87   return DomCode::NONE; | 90   return DomCode::NONE; | 
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 290 // static | 293 // static | 
| 291 uint32_t KeycodeConverter::DomCodeToUsbKeycode(DomCode dom_code) { | 294 uint32_t KeycodeConverter::DomCodeToUsbKeycode(DomCode dom_code) { | 
| 292   for (size_t i = 0; i < kKeycodeMapEntries; ++i) { | 295   for (size_t i = 0; i < kKeycodeMapEntries; ++i) { | 
| 293     if (usb_keycode_map[i].usb_keycode == static_cast<uint32_t>(dom_code)) | 296     if (usb_keycode_map[i].usb_keycode == static_cast<uint32_t>(dom_code)) | 
| 294       return usb_keycode_map[i].usb_keycode; | 297       return usb_keycode_map[i].usb_keycode; | 
| 295   } | 298   } | 
| 296   return InvalidUsbKeycode(); | 299   return InvalidUsbKeycode(); | 
| 297 } | 300 } | 
| 298 | 301 | 
| 299 // static | 302 // static | 
| 300 uint32_t KeycodeConverter::CodeToUsbKeycode(const std::string& code) { | 303 uint32_t KeycodeConverter::CodeStringToUsbKeycode(const std::string& code) { | 
| 301   if (code.empty()) | 304   if (code.empty()) | 
| 302     return InvalidUsbKeycode(); | 305     return InvalidUsbKeycode(); | 
| 303 | 306 | 
| 304   for (size_t i = 0; i < kKeycodeMapEntries; ++i) { | 307   for (size_t i = 0; i < kKeycodeMapEntries; ++i) { | 
| 305     if (usb_keycode_map[i].code && code == usb_keycode_map[i].code) { | 308     if (usb_keycode_map[i].code && code == usb_keycode_map[i].code) { | 
| 306       return usb_keycode_map[i].usb_keycode; | 309       return usb_keycode_map[i].usb_keycode; | 
| 307     } | 310     } | 
| 308   } | 311   } | 
| 309   return InvalidUsbKeycode(); | 312   return InvalidUsbKeycode(); | 
| 310 } | 313 } | 
| 311 | 314 | 
|  | 315 // static | 
|  | 316 int KeycodeConverter::CodeStringToNativeKeycode(const std::string& code) { | 
|  | 317   return UsbKeycodeToNativeKeycode(CodeStringToUsbKeycode(code)); | 
|  | 318 } | 
|  | 319 | 
| 312 }  // namespace ui | 320 }  // namespace ui | 
| OLD | NEW | 
|---|