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 base::ScopedCFTypeRef<TISInputSourceRef>( |
| 33 (TISInputSourceRef)CFArrayGetValueAtIndex(input_source_list, 0), |
| 34 base::scoped_policy::RETAIN); |
| 35 } |
| 36 |
| 37 PlatformKeyboardLayout ScopedKeyboardLayout::GetActiveLayout() { |
| 38 return PlatformKeyboardLayout(TISCopyCurrentKeyboardInputSource()); |
| 39 } |
| 40 |
| 41 void ScopedKeyboardLayout::ActivateLayout(PlatformKeyboardLayout layout) { |
| 42 DCHECK(layout); |
| 43 OSStatus result = TISSelectInputSource(layout); |
| 44 DCHECK_EQ(noErr, result); |
| 45 } |
| 46 |
| 47 } // namespace ui |
OLD | NEW |