OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ui/events/test/keyboard_layout.h" | |
6 | |
7 #include "base/logging.h" | |
8 | |
9 namespace ui { | |
10 | |
11 // |LoadKeyboardLayout()| ensures the locale to be loaded into the system | |
12 // (Similar to temporarily adding a locale in Control Panel), otherwise | |
13 // |ToUnicodeEx()| will fall-back to the default locale. | |
14 // See MSDN LoadKeyboardLayout(): | |
15 // https://msdn.microsoft.com/en-us/library/windows/desktop/ms646305(v=vs.85).as px | |
16 // And language constants and strings: | |
17 // https://msdn.microsoft.com/en-us/library/windows/desktop/dd318693(v=vs.85).as px | |
18 PlatformKeyboardLayout GetPlatformKeyboardLayout(KeyboardLayout layout) { | |
19 switch (layout) { | |
20 case KEYBOARD_LAYOUT_ENGLISH_US: | |
21 return LoadKeyboardLayout(L"00000409", KLF_ACTIVATE); | |
22 case KEYBOARD_LAYOUT_FRENCH: | |
23 return LoadKeyboardLayout(L"0000040c", KLF_ACTIVATE); | |
24 case KEYBOARD_LAYOUT_GERMAN: | |
25 return LoadKeyboardLayout(L"00000407", KLF_ACTIVATE); | |
26 case KEYBOARD_LAYOUT_GREEK: | |
27 return LoadKeyboardLayout(L"00000408", KLF_ACTIVATE); | |
28 case KEYBOARD_LAYOUT_JAPANESE: | |
29 // |LoadKeyboardLayout(L"00000411", KLF_ACTIVATE)| returns the correct | |
30 // Japanese locale, but it will fail on DrMemory tests. | |
31 // 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.
| |
32 // However we could bypass it since we are only testing non-printable keys | |
33 // on Japanese locale. | |
34 // (This issue only happens on Japanese and Korean). | |
35 return reinterpret_cast<PlatformKeyboardLayout>(0x04110411); | |
36 case KEYBOARD_LAYOUT_KOREAN: | |
37 return reinterpret_cast<PlatformKeyboardLayout>(0x04120412); | |
38 case KEYBOARD_LAYOUT_RUSSIAN: | |
39 return LoadKeyboardLayout(L"00000419", KLF_ACTIVATE); | |
40 default: | |
41 NOTREACHED(); | |
42 return 0; | |
43 } | |
44 } | |
45 | |
46 PlatformKeyboardLayout ScopedKeyboardLayout::GetActiveLayout() { | |
47 return GetKeyboardLayout(0); | |
48 } | |
49 | |
50 bool ScopedKeyboardLayout::ActivateLayout(PlatformKeyboardLayout layout) { | |
51 DCHECK(layout); | |
52 return !!ActivateKeyboardLayout(layout, 0); | |
53 } | |
54 | |
55 } // namespace ui | |
OLD | NEW |