| 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/strings/string16.h" | 5 #include "base/strings/string16.h" |
| 6 #include "base/strings/utf_string_conversion_utils.h" | 6 #include "base/strings/utf_string_conversion_utils.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/test/chromedriver/chrome/ui_events.h" | 8 #include "chrome/test/chromedriver/chrome/ui_events.h" |
| 9 #include "chrome/test/chromedriver/keycode_text_conversion.h" | 9 #include "chrome/test/chromedriver/keycode_text_conversion.h" |
| 10 #include "ui/events/event_constants.h" | 10 #include "ui/events/event_constants.h" |
| 11 #include "ui/events/keycodes/dom/dom_code.h" | 11 #include "ui/events/keycodes/dom/dom_code.h" |
| 12 #include "ui/events/keycodes/dom/keycode_converter.h" | 12 #include "ui/events/keycodes/dom/keycode_converter.h" |
| 13 #include "ui/events/keycodes/keyboard_code_conversion.h" | 13 #include "ui/events/keycodes/keyboard_code_conversion.h" |
| 14 #include "ui/events/ozone/layout/keyboard_layout_engine.h" | 14 #include "ui/events/ozone/layout/keyboard_layout_engine.h" |
| 15 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" | 15 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" |
| 16 | 16 |
| 17 bool ConvertKeyCodeToText(ui::KeyboardCode key_code, | 17 #if defined(USE_X11) |
| 18 int modifiers, | 18 bool ConvertKeyCodeToTextOzone |
| 19 std::string* text, | 19 #else |
| 20 std::string* error_msg) { | 20 bool ConvertKeyCodeToText |
| 21 #endif |
| 22 (ui::KeyboardCode key_code, |
| 23 int modifiers, |
| 24 std::string* text, |
| 25 std::string* error_msg) { |
| 21 ui::KeyboardLayoutEngine* keyboard_layout_engine = | 26 ui::KeyboardLayoutEngine* keyboard_layout_engine = |
| 22 ui::KeyboardLayoutEngineManager::GetKeyboardLayoutEngine(); | 27 ui::KeyboardLayoutEngineManager::GetKeyboardLayoutEngine(); |
| 23 ui::DomCode dom_code = ui::UsLayoutKeyboardCodeToDomCode(key_code); | 28 ui::DomCode dom_code = ui::UsLayoutKeyboardCodeToDomCode(key_code); |
| 24 int event_flags = ui::EF_NONE; | 29 int event_flags = ui::EF_NONE; |
| 25 | 30 |
| 26 // Chrome OS keyboards don't have meta or num lock keys, so these modifier | 31 // Chrome OS keyboards don't have meta or num lock keys, so these modifier |
| 27 // masks are ignored. Only handle alt, ctrl and shift. | 32 // masks are ignored. Only handle alt, ctrl and shift. |
| 28 if (modifiers & kAltKeyModifierMask) | 33 if (modifiers & kAltKeyModifierMask) |
| 29 event_flags |= ui::EF_ALT_DOWN; | 34 event_flags |= ui::EF_ALT_DOWN; |
| 30 if (modifiers & kControlKeyModifierMask) | 35 if (modifiers & kControlKeyModifierMask) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 41 // The keycode lookup failed, or mapped to a key that isn't a unicode | 46 // The keycode lookup failed, or mapped to a key that isn't a unicode |
| 42 // character. Convert it to the empty string. | 47 // character. Convert it to the empty string. |
| 43 *text = std::string(); | 48 *text = std::string(); |
| 44 return true; | 49 return true; |
| 45 } | 50 } |
| 46 | 51 |
| 47 base::WriteUnicodeCharacter(dom_key.ToCharacter(), text); | 52 base::WriteUnicodeCharacter(dom_key.ToCharacter(), text); |
| 48 return true; | 53 return true; |
| 49 } | 54 } |
| 50 | 55 |
| 51 bool ConvertCharToKeyCode(base::char16 key, | 56 #if defined(USE_X11) |
| 52 ui::KeyboardCode* key_code, | 57 bool ConvertCharToKeyCodeOzone |
| 53 int* necessary_modifiers, | 58 #else |
| 54 std::string* error_msg) { | 59 bool ConvertCharToKeyCode |
| 60 #endif |
| 61 (base::char16 key, |
| 62 ui::KeyboardCode* key_code, |
| 63 int* necessary_modifiers, |
| 64 std::string* error_msg) { |
| 55 base::string16 key_string; | 65 base::string16 key_string; |
| 56 key_string.push_back(key); | 66 key_string.push_back(key); |
| 57 std::string key_string_utf8 = base::UTF16ToUTF8(key_string); | 67 std::string key_string_utf8 = base::UTF16ToUTF8(key_string); |
| 58 bool found_code = false; | 68 bool found_code = false; |
| 59 *error_msg = std::string(); | 69 *error_msg = std::string(); |
| 60 // There doesn't seem to be a way to get a CrOS key code for a given unicode | 70 // There doesn't seem to be a way to get a CrOS key code for a given unicode |
| 61 // character. So here we check every key code to see if it produces the | 71 // character. So here we check every key code to see if it produces the |
| 62 // right character, as we do on Mac (see keycode_text_conversion_mac.mm). | 72 // right character, as we do on Mac (see keycode_text_conversion_mac.mm). |
| 63 for (int i = 0; i < 256; ++i) { | 73 for (int i = 0; i < 256; ++i) { |
| 64 ui::KeyboardCode code = static_cast<ui::KeyboardCode>(i); | 74 ui::KeyboardCode code = static_cast<ui::KeyboardCode>(i); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 77 *necessary_modifiers = kShiftKeyModifierMask; | 87 *necessary_modifiers = kShiftKeyModifierMask; |
| 78 found_code = true; | 88 found_code = true; |
| 79 } | 89 } |
| 80 if (found_code) { | 90 if (found_code) { |
| 81 *key_code = code; | 91 *key_code = code; |
| 82 break; | 92 break; |
| 83 } | 93 } |
| 84 } | 94 } |
| 85 return found_code; | 95 return found_code; |
| 86 } | 96 } |
| OLD | NEW |