Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "chrome/test/chromedriver/keycode_text_conversion.h" | 5 #include "chrome/test/chromedriver/keycode_text_conversion.h" |
| 6 | 6 |
| 7 #include <VersionHelpers.h> | |
| 7 #include <stdlib.h> | 8 #include <stdlib.h> |
| 8 #include <windows.h> | 9 #include <windows.h> |
| 9 | 10 |
| 11 #include "base/memory/scoped_ptr.h" | |
| 10 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/test/chromedriver/chrome/ui_events.h" | 13 #include "chrome/test/chromedriver/chrome/ui_events.h" |
| 12 | 14 |
| 15 #define US_KEYBOARD_LAYOUT L"00000409" | |
|
samuong
2015/02/18 19:59:34
We should use const variables instead of #defines,
| |
| 16 | |
| 13 bool ConvertKeyCodeToText( | 17 bool ConvertKeyCodeToText( |
| 14 ui::KeyboardCode key_code, int modifiers, std::string* text, | 18 ui::KeyboardCode key_code, int modifiers, std::string* text, |
| 15 std::string* error_msg) { | 19 std::string* error_msg) { |
| 16 UINT scan_code = ::MapVirtualKeyW(key_code, MAPVK_VK_TO_VSC); | 20 UINT scan_code = ::MapVirtualKeyW(key_code, MAPVK_VK_TO_VSC); |
| 17 BYTE keyboard_state[256]; | 21 BYTE keyboard_state[256]; |
| 18 memset(keyboard_state, 0, 256); | 22 memset(keyboard_state, 0, 256); |
| 19 *error_msg = std::string(); | 23 *error_msg = std::string(); |
| 20 if (modifiers & kShiftKeyModifierMask) | 24 if (modifiers & kShiftKeyModifierMask) |
| 21 keyboard_state[VK_SHIFT] |= 0x80; | 25 keyboard_state[VK_SHIFT] |= 0x80; |
| 22 if (modifiers & kControlKeyModifierMask) | 26 if (modifiers & kControlKeyModifierMask) |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 50 modifiers |= kShiftKeyModifierMask; | 54 modifiers |= kShiftKeyModifierMask; |
| 51 if (win_modifiers & 0x02) | 55 if (win_modifiers & 0x02) |
| 52 modifiers |= kControlKeyModifierMask; | 56 modifiers |= kControlKeyModifierMask; |
| 53 if (win_modifiers & 0x04) | 57 if (win_modifiers & 0x04) |
| 54 modifiers |= kAltKeyModifierMask; | 58 modifiers |= kAltKeyModifierMask; |
| 55 // Ignore bit 0x08: It is for Hankaku key. | 59 // Ignore bit 0x08: It is for Hankaku key. |
| 56 *necessary_modifiers = modifiers; | 60 *necessary_modifiers = modifiers; |
| 57 } | 61 } |
| 58 return translated; | 62 return translated; |
| 59 } | 63 } |
| 64 | |
| 65 bool SwitchToUSKeyboardLayout() { | |
| 66 | |
|
samuong
2015/02/18 19:59:35
nit: delete blank line
| |
| 67 // For LoadKeyboardLayout - Prior to Windows 8: If the specified input | |
| 68 // locale identifier is not already loaded, the function loads and | |
| 69 // activates the input locale identifier for the current thread. | |
| 70 // Beginning in Windows 8: If the specified input locale identifier is not | |
| 71 // already loaded, the function loads and activates the input | |
| 72 // locale identifier for the system. | |
| 73 // For Windows 8 - Use ActivateKeyboardLayout instead of LoadKeyboardLayout | |
| 74 if (IsWindows8OrGreater()) { | |
| 75 int size; | |
| 76 TCHAR active_keyboard[KL_NAMELENGTH]; | |
| 77 | |
| 78 if ((size = ::GetKeyboardLayoutList(0, NULL)) <= 0) | |
| 79 return false; | |
| 80 | |
| 81 scoped_ptr<HKL[]> keyboard_handles_list(new HKL[size]); | |
| 82 ::GetKeyboardLayoutList(size, keyboard_handles_list.get()); | |
| 83 | |
| 84 for (int keyboard_index = 0; keyboard_index < size; keyboard_index++) { | |
| 85 ::ActivateKeyboardLayout(keyboard_handles_list[keyboard_index], | |
| 86 KLF_SETFORPROCESS); | |
| 87 ::GetKeyboardLayoutName(active_keyboard); | |
| 88 // if active keyboard match US keyboard layout - 00000409 | |
|
samuong
2015/02/18 19:59:34
delete this comment
| |
| 89 if (wcscmp(active_keyboard, US_KEYBOARD_LAYOUT) == 0) | |
| 90 return true; | |
| 91 } | |
| 92 return false; | |
| 93 } else { | |
| 94 HKL layout = ::LoadKeyboardLayout((LPCTSTR)US_KEYBOARD_LAYOUT, | |
| 95 KLF_ACTIVATE); | |
| 96 if (!layout) | |
| 97 return false; | |
| 98 else | |
| 99 return true; | |
|
samuong
2015/02/18 19:59:35
return ::LoadKeyboardLayout(kUsKeyboardLayout, KLF
| |
| 100 } | |
| 101 } | |
| OLD | NEW |