Chromium Code Reviews| Index: ui/events/test/keyboard_layout_win.cc |
| diff --git a/ui/events/test/keyboard_layout_win.cc b/ui/events/test/keyboard_layout_win.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9b2fcca5db8048bbcc8f865c24dfdf93247ba58f |
| --- /dev/null |
| +++ b/ui/events/test/keyboard_layout_win.cc |
| @@ -0,0 +1,55 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ui/events/test/keyboard_layout.h" |
| + |
| +#include "base/logging.h" |
| + |
| +namespace ui { |
| + |
| +// |LoadKeyboardLayout()| ensures the locale to be loaded into the system |
| +// (Similar to temporarily adding a locale in Control Panel), otherwise |
| +// |ToUnicodeEx()| will fall-back to the default locale. |
| +// See MSDN LoadKeyboardLayout(): |
| +// https://msdn.microsoft.com/en-us/library/windows/desktop/ms646305(v=vs.85).aspx |
| +// And language constants and strings: |
| +// https://msdn.microsoft.com/en-us/library/windows/desktop/dd318693(v=vs.85).aspx |
| +PlatformKeyboardLayout GetPlatformKeyboardLayout(KeyboardLayout layout) { |
| + switch (layout) { |
| + case KEYBOARD_LAYOUT_ENGLISH_US: |
| + return LoadKeyboardLayout(L"00000409", KLF_ACTIVATE); |
| + case KEYBOARD_LAYOUT_FRENCH: |
| + return LoadKeyboardLayout(L"0000040c", KLF_ACTIVATE); |
| + case KEYBOARD_LAYOUT_GERMAN: |
| + return LoadKeyboardLayout(L"00000407", KLF_ACTIVATE); |
| + case KEYBOARD_LAYOUT_GREEK: |
| + return LoadKeyboardLayout(L"00000408", KLF_ACTIVATE); |
| + case KEYBOARD_LAYOUT_JAPANESE: |
| + // |LoadKeyboardLayout(L"00000411", KLF_ACTIVATE)| returns the correct |
| + // Japanese locale, but it will fail on DrMemory tests. |
| + // See https://crbug.com/612736#c6 |
|
Peter Kasting
2016/08/18 17:48:19
I tried to read the bug, but I don't understand wh
Tomasz Moniuszko
2016/08/26 08:53:12
Done.
|
| + // However we could bypass it since we are only testing non-printable keys |
| + // on Japanese locale. |
| + // (This issue only happens on Japanese and Korean). |
| + return reinterpret_cast<PlatformKeyboardLayout>(0x04110411); |
| + case KEYBOARD_LAYOUT_KOREAN: |
| + return reinterpret_cast<PlatformKeyboardLayout>(0x04120412); |
| + case KEYBOARD_LAYOUT_RUSSIAN: |
| + return LoadKeyboardLayout(L"00000419", KLF_ACTIVATE); |
| + default: |
| + NOTREACHED(); |
| + return 0; |
| + } |
| +} |
| + |
| +PlatformKeyboardLayout ScopedKeyboardLayout::GetActiveLayout() { |
| + return GetKeyboardLayout(0); |
| +} |
| + |
| +bool ScopedKeyboardLayout::ActivateLayout(PlatformKeyboardLayout layout) { |
| + DCHECK(layout); |
| + return !!ActivateKeyboardLayout(layout, 0); |
| +} |
| + |
| +} // namespace ui |