Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "base/strings/string16.h" | 6 #include "base/strings/string16.h" |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/test/chromedriver/chrome/ui_events.h" | 9 #include "chrome/test/chromedriver/chrome/ui_events.h" |
| 10 #include "chrome/test/chromedriver/keycode_text_conversion.h" | 10 #include "chrome/test/chromedriver/keycode_text_conversion.h" |
| 11 #include "ui/events/event_constants.h" | 11 #include "ui/events/event_constants.h" |
| 12 #include "ui/events/keycodes/dom/dom_code.h" | 12 #include "ui/events/keycodes/dom/dom_code.h" |
| 13 #include "ui/events/keycodes/dom/keycode_converter.h" | |
| 13 #include "ui/events/keycodes/keyboard_code_conversion.h" | 14 #include "ui/events/keycodes/keyboard_code_conversion.h" |
| 14 #include "ui/events/ozone/layout/keyboard_layout_engine.h" | 15 #include "ui/events/ozone/layout/keyboard_layout_engine.h" |
| 15 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" | 16 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" |
| 16 | 17 |
| 17 bool ConvertKeyCodeToText(ui::KeyboardCode key_code, | 18 bool ConvertKeyCodeToText(ui::KeyboardCode key_code, |
| 18 int modifiers, | 19 int modifiers, |
| 19 std::string* text, | 20 std::string* text, |
| 20 std::string* error_msg) { | 21 std::string* error_msg) { |
| 21 ui::KeyboardLayoutEngine* keyboard_layout_engine = | 22 ui::KeyboardLayoutEngine* keyboard_layout_engine = |
| 22 ui::KeyboardLayoutEngineManager::GetKeyboardLayoutEngine(); | 23 ui::KeyboardLayoutEngineManager::GetKeyboardLayoutEngine(); |
| 23 ui::DomCode dom_code = ui::UsLayoutKeyboardCodeToDomCode(key_code); | 24 ui::DomCode dom_code = ui::UsLayoutKeyboardCodeToDomCode(key_code); |
| 24 int event_flags = ui::EF_NONE; | 25 int event_flags = ui::EF_NONE; |
| 25 | 26 |
| 26 // Chrome OS keyboards don't have meta or num lock keys, so these modifier | 27 // Chrome OS keyboards don't have meta or num lock keys, so these modifier |
| 27 // masks are ignored. Only handle alt, ctrl and shift. | 28 // masks are ignored. Only handle alt, ctrl and shift. |
| 28 if (modifiers & kAltKeyModifierMask) | 29 if (modifiers & kAltKeyModifierMask) |
| 29 event_flags |= ui::EF_ALT_DOWN; | 30 event_flags |= ui::EF_ALT_DOWN; |
| 30 if (modifiers & kControlKeyModifierMask) | 31 if (modifiers & kControlKeyModifierMask) |
| 31 event_flags |= ui::EF_CONTROL_DOWN; | 32 event_flags |= ui::EF_CONTROL_DOWN; |
| 32 if (modifiers & kShiftKeyModifierMask) | 33 if (modifiers & kShiftKeyModifierMask) |
| 33 event_flags |= ui::EF_SHIFT_DOWN; | 34 event_flags |= ui::EF_SHIFT_DOWN; |
| 34 | 35 |
| 35 ui::DomKey dom_key_ignored; | 36 ui::DomKey dom_key; |
| 36 base::char16 str[2] = {'\0'}; | |
| 37 ui::KeyboardCode key_code_ignored; | 37 ui::KeyboardCode key_code_ignored; |
| 38 uint32 platform_keycode_ignored; | 38 uint32 platform_keycode_ignored; |
| 39 | 39 |
| 40 if (!keyboard_layout_engine->Lookup(dom_code, event_flags, &dom_key_ignored, | 40 if (!keyboard_layout_engine->Lookup(dom_code, event_flags, &dom_key, |
| 41 &str[0], &key_code_ignored, | 41 &key_code_ignored, |
| 42 &platform_keycode_ignored)) { | 42 &platform_keycode_ignored)) { |
| 43 // Key codes like ui::VKEY_UNKNOWN need to be mapped to the empty string, so | 43 // Key codes like ui::VKEY_UNKNOWN need to be mapped to the empty string, so |
| 44 // even if the lookup fails we still need to return true here. | 44 // even if the lookup fails we still need to return true here. |
| 45 *text = std::string(); | 45 *text = std::string(); |
| 46 return true; | 46 return true; |
| 47 } | 47 } |
| 48 | 48 |
| 49 if (!base::UTF16ToUTF8(str, base::c16len(str), text)) { | 49 if (!dom_key.IsUnicode()) { |
|
kpschoedel
2015/08/07 20:42:12
The original code here succeeded for DomKey::CHARA
| |
| 50 *error_msg = base::StringPrintf( | 50 *error_msg = base::StringPrintf( |
| 51 "unicode conversion failed for keycode %d with modifiers 0x%x", | 51 "unicode conversion failed for keycode %d with modifiers 0x%x", |
| 52 key_code, modifiers); | 52 key_code, modifiers); |
| 53 return false; | 53 return false; |
| 54 } | 54 } |
| 55 | 55 |
| 56 *text = ui::KeycodeConverter::DomKeyToKeyString(dom_key); | |
| 56 return true; | 57 return true; |
| 57 } | 58 } |
| 58 | 59 |
| 59 bool ConvertCharToKeyCode(base::char16 key, | 60 bool ConvertCharToKeyCode(base::char16 key, |
| 60 ui::KeyboardCode* key_code, | 61 ui::KeyboardCode* key_code, |
| 61 int* necessary_modifiers, | 62 int* necessary_modifiers, |
| 62 std::string* error_msg) { | 63 std::string* error_msg) { |
| 63 base::string16 key_string; | 64 base::string16 key_string; |
| 64 key_string.push_back(key); | 65 key_string.push_back(key); |
| 65 std::string key_string_utf8 = base::UTF16ToUTF8(key_string); | 66 std::string key_string_utf8 = base::UTF16ToUTF8(key_string); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 85 *necessary_modifiers = kShiftKeyModifierMask; | 86 *necessary_modifiers = kShiftKeyModifierMask; |
| 86 found_code = true; | 87 found_code = true; |
| 87 } | 88 } |
| 88 if (found_code) { | 89 if (found_code) { |
| 89 *key_code = code; | 90 *key_code = code; |
| 90 break; | 91 break; |
| 91 } | 92 } |
| 92 } | 93 } |
| 93 return found_code; | 94 return found_code; |
| 94 } | 95 } |
| OLD | NEW |