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 "ui/events/keycodes/dom/dom_code.h" | 8 #include "ui/events/keycodes/dom/dom_code.h" |
9 #include "ui/events/keycodes/dom/dom_key.h" | 9 #include "ui/events/keycodes/dom/dom_key.h" |
10 | 10 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 if (usb_keycode_map[i].code && | 101 if (usb_keycode_map[i].code && |
102 strcmp(usb_keycode_map[i].code, code) == 0) { | 102 strcmp(usb_keycode_map[i].code, code) == 0) { |
103 return usb_keycode_map[i].native_keycode; | 103 return usb_keycode_map[i].native_keycode; |
104 } | 104 } |
105 } | 105 } |
106 return InvalidNativeKeycode(); | 106 return InvalidNativeKeycode(); |
107 } | 107 } |
108 | 108 |
109 // static | 109 // static |
110 int KeycodeConverter::DomCodeToNativeKeycode(DomCode code) { | 110 int KeycodeConverter::DomCodeToNativeKeycode(DomCode code) { |
111 if (code == DomCode::NONE) | 111 return UsbKeycodeToNativeKeycode(static_cast<uint32_t>(code)); |
112 return InvalidNativeKeycode(); | |
113 for (size_t i = 0; i < kKeycodeMapEntries; ++i) { | |
114 if (usb_keycode_map[i].usb_keycode == static_cast<uint32_t>(code)) | |
115 return usb_keycode_map[i].native_keycode; | |
116 } | |
117 return InvalidNativeKeycode(); | |
118 } | 112 } |
119 | 113 |
120 // static | 114 // static |
121 DomCode KeycodeConverter::CodeStringToDomCode(const char* code) { | 115 DomCode KeycodeConverter::CodeStringToDomCode(const char* code) { |
122 if (!code || !*code) { | 116 if (!code || !*code) { |
123 LOG(WARNING) << "empty code string"; | 117 LOG(WARNING) << "empty code string"; |
124 return DomCode::NONE; | 118 return DomCode::NONE; |
125 } | 119 } |
126 for (size_t i = 0; i < kKeycodeMapEntries; ++i) { | 120 for (size_t i = 0; i < kKeycodeMapEntries; ++i) { |
127 if (usb_keycode_map[i].code && | 121 if (usb_keycode_map[i].code && |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 for (size_t i = 0; i < kKeycodeMapEntries; ++i) { | 267 for (size_t i = 0; i < kKeycodeMapEntries; ++i) { |
274 if (usb_keycode_map[i].code && | 268 if (usb_keycode_map[i].code && |
275 strcmp(usb_keycode_map[i].code, code) == 0) { | 269 strcmp(usb_keycode_map[i].code, code) == 0) { |
276 return usb_keycode_map[i].usb_keycode; | 270 return usb_keycode_map[i].usb_keycode; |
277 } | 271 } |
278 } | 272 } |
279 return InvalidUsbKeycode(); | 273 return InvalidUsbKeycode(); |
280 } | 274 } |
281 | 275 |
282 } // namespace ui | 276 } // namespace ui |
OLD | NEW |