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 PlatformKeyboardLayout GetPlatformKeyboardLayout(KeyboardLayout layout) { | |
12 // Right now tests only need US English. If other layouts need to be | |
13 // supported in the future this code should be extended. | |
14 DCHECK_EQ(KEYBOARD_LAYOUT_ENGLISH_US, layout); | |
15 | |
16 const char kUsInputSourceId[] = "com.apple.keylayout.US"; | |
17 | |
18 base::ScopedCFTypeRef<CFMutableDictionaryRef> input_source_list_filter( | |
19 CFDictionaryCreateMutable(kCFAllocatorDefault, 1, | |
20 &kCFTypeDictionaryKeyCallBacks, | |
21 &kCFTypeDictionaryValueCallBacks)); | |
22 base::ScopedCFTypeRef<CFStringRef> input_source_id_ref( | |
23 CFStringCreateWithCString(kCFAllocatorDefault, kUsInputSourceId, | |
24 kCFStringEncodingUTF8)); | |
25 CFDictionaryAddValue(input_source_list_filter, kTISPropertyInputSourceID, | |
26 input_source_id_ref); | |
27 base::ScopedCFTypeRef<CFArrayRef> input_source_list( | |
28 TISCreateInputSourceList(input_source_list_filter, true)); | |
29 if (CFArrayGetCount(input_source_list) != 1) | |
30 return PlatformKeyboardLayout(); | |
31 | |
32 return PlatformKeyboardLayout( | |
33 (TISInputSourceRef)CFArrayGetValueAtIndex(input_source_list, 0)); | |
34 } | |
35 | |
36 PlatformKeyboardLayout ScopedKeyboardLayout::GetActiveLayout() { | |
37 return PlatformKeyboardLayout(TISCopyCurrentKeyboardInputSource()); | |
38 } | |
39 | |
40 void ScopedKeyboardLayout::ActivateLayout(PlatformKeyboardLayout layout) { | |
41 DCHECK(layout); | |
42 OSStatus result = TISSelectInputSource(layout); | |
43 DCHECK_EQ(noErr, result); | |
44 } | |
45 | |
46 } // namespace ui | |
OLD | NEW |