| 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/dom4/keycode_converter.h" | 5 #include "ui/events/keycodes/dom4/keycode_converter.h" |
| 6 | 6 |
| 7 #include "base/logging.h" |
| 7 #include "ui/events/keycodes/dom3/dom_code.h" | 8 #include "ui/events/keycodes/dom3/dom_code.h" |
| 8 #include "ui/events/keycodes/dom3/dom_key.h" | 9 #include "ui/events/keycodes/dom3/dom_key.h" |
| 9 | 10 |
| 10 namespace ui { | 11 namespace ui { |
| 11 | 12 |
| 12 namespace { | 13 namespace { |
| 13 | 14 |
| 14 // Table of USB codes (equivalent to DomCode values), native scan codes, | 15 // Table of USB codes (equivalent to DomCode values), native scan codes, |
| 15 // and DOM Level 3 |code| strings. | 16 // and DOM Level 3 |code| strings. |
| 16 #if defined(OS_WIN) | 17 #if defined(OS_WIN) |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 return InvalidNativeKeycode(); | 112 return InvalidNativeKeycode(); |
| 112 for (size_t i = 0; i < kKeycodeMapEntries; ++i) { | 113 for (size_t i = 0; i < kKeycodeMapEntries; ++i) { |
| 113 if (usb_keycode_map[i].usb_keycode == static_cast<uint32_t>(code)) | 114 if (usb_keycode_map[i].usb_keycode == static_cast<uint32_t>(code)) |
| 114 return usb_keycode_map[i].native_keycode; | 115 return usb_keycode_map[i].native_keycode; |
| 115 } | 116 } |
| 116 return InvalidNativeKeycode(); | 117 return InvalidNativeKeycode(); |
| 117 } | 118 } |
| 118 | 119 |
| 119 // static | 120 // static |
| 120 DomCode KeycodeConverter::CodeStringToDomCode(const char* code) { | 121 DomCode KeycodeConverter::CodeStringToDomCode(const char* code) { |
| 121 if (!code || !*code) | 122 if (!code || !*code) { |
| 123 LOG(WARNING) << "empty code string"; |
| 122 return DomCode::NONE; | 124 return DomCode::NONE; |
| 125 } |
| 123 for (size_t i = 0; i < kKeycodeMapEntries; ++i) { | 126 for (size_t i = 0; i < kKeycodeMapEntries; ++i) { |
| 124 if (usb_keycode_map[i].code && | 127 if (usb_keycode_map[i].code && |
| 125 strcmp(usb_keycode_map[i].code, code) == 0) { | 128 strcmp(usb_keycode_map[i].code, code) == 0) { |
| 126 return static_cast<DomCode>(usb_keycode_map[i].usb_keycode); | 129 return static_cast<DomCode>(usb_keycode_map[i].usb_keycode); |
| 127 } | 130 } |
| 128 } | 131 } |
| 132 LOG(WARNING) << "unrecognized code string '" << code << "'"; |
| 129 return DomCode::NONE; | 133 return DomCode::NONE; |
| 130 } | 134 } |
| 131 | 135 |
| 132 // static | 136 // static |
| 133 const char* KeycodeConverter::DomCodeToCodeString(DomCode dom_code) { | 137 const char* KeycodeConverter::DomCodeToCodeString(DomCode dom_code) { |
| 134 return UsbKeycodeToCode(static_cast<uint32_t>(dom_code)); | 138 return UsbKeycodeToCode(static_cast<uint32_t>(dom_code)); |
| 135 } | 139 } |
| 136 | 140 |
| 137 // static | 141 // static |
| 138 DomKey KeycodeConverter::KeyStringToDomKey(const char* key) { | 142 DomKey KeycodeConverter::KeyStringToDomKey(const char* key) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 for (size_t i = 0; i < kKeycodeMapEntries; ++i) { | 224 for (size_t i = 0; i < kKeycodeMapEntries; ++i) { |
| 221 if (usb_keycode_map[i].code && | 225 if (usb_keycode_map[i].code && |
| 222 strcmp(usb_keycode_map[i].code, code) == 0) { | 226 strcmp(usb_keycode_map[i].code, code) == 0) { |
| 223 return usb_keycode_map[i].usb_keycode; | 227 return usb_keycode_map[i].usb_keycode; |
| 224 } | 228 } |
| 225 } | 229 } |
| 226 return InvalidUsbKeycode(); | 230 return InvalidUsbKeycode(); |
| 227 } | 231 } |
| 228 | 232 |
| 229 } // namespace ui | 233 } // namespace ui |
| OLD | NEW |