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 const char* input_source_id; | |
13 switch (layout) { | |
14 case KEYBOARD_LAYOUT_GERMAN: | |
15 input_source_id = "com.apple.keylayout.German"; | |
16 break; | |
17 default: | |
18 NOTREACHED(); | |
19 return PlatformKeyboardLayout(); | |
Peter Kasting
2016/08/18 17:48:19
Nit: Avoid handling NOTREACHED(). Just do:
DCH
Tomasz Moniuszko
2016/08/26 08:53:12
I added support for English US keyboard so I think
| |
20 } | |
21 | |
22 base::ScopedCFTypeRef<CFMutableDictionaryRef> filter_dict( | |
23 CFDictionaryCreateMutable(kCFAllocatorDefault, 1, | |
24 &kCFTypeDictionaryKeyCallBacks, | |
25 &kCFTypeDictionaryValueCallBacks)); | |
26 base::ScopedCFTypeRef<CFStringRef> id_ref(CFStringCreateWithCString( | |
27 kCFAllocatorDefault, input_source_id, kCFStringEncodingUTF8)); | |
28 CFDictionaryAddValue(filter_dict, kTISPropertyInputSourceID, id_ref); | |
29 base::ScopedCFTypeRef<CFArrayRef> sources( | |
30 TISCreateInputSourceList(filter_dict, true)); | |
31 if (CFArrayGetCount(sources) != 1) | |
32 return PlatformKeyboardLayout(); | |
33 | |
34 return PlatformKeyboardLayout( | |
35 (TISInputSourceRef)CFArrayGetValueAtIndex(sources, 0)); | |
36 } | |
37 | |
38 PlatformKeyboardLayout ScopedKeyboardLayout::GetActiveLayout() { | |
39 return PlatformKeyboardLayout(TISCopyCurrentKeyboardInputSource()); | |
40 } | |
41 | |
42 bool ScopedKeyboardLayout::ActivateLayout(PlatformKeyboardLayout layout) { | |
43 DCHECK(layout); | |
44 return TISSelectInputSource(layout) == noErr; | |
45 } | |
46 | |
47 } // namespace ui | |
OLD | NEW |