Chromium Code Reviews| 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_ENGLISH_US: | |
| 15 input_source_id = "com.apple.keylayout.US"; | |
| 16 break; | |
| 17 case KEYBOARD_LAYOUT_GERMAN: | |
| 18 input_source_id = "com.apple.keylayout.German"; | |
| 19 break; | |
| 20 default: | |
| 21 NOTREACHED(); | |
| 22 return PlatformKeyboardLayout(); | |
|
Peter Kasting
2016/08/26 18:54:33
Nit: I still probably would have tried to avoid ha
Tomasz Moniuszko
2016/08/31 15:29:42
Actually, it seems that tests which need German ke
| |
| 23 } | |
| 24 | |
| 25 base::ScopedCFTypeRef<CFMutableDictionaryRef> filter_dict( | |
| 26 CFDictionaryCreateMutable(kCFAllocatorDefault, 1, | |
| 27 &kCFTypeDictionaryKeyCallBacks, | |
| 28 &kCFTypeDictionaryValueCallBacks)); | |
| 29 base::ScopedCFTypeRef<CFStringRef> id_ref(CFStringCreateWithCString( | |
| 30 kCFAllocatorDefault, input_source_id, kCFStringEncodingUTF8)); | |
| 31 CFDictionaryAddValue(filter_dict, kTISPropertyInputSourceID, id_ref); | |
| 32 base::ScopedCFTypeRef<CFArrayRef> sources( | |
| 33 TISCreateInputSourceList(filter_dict, true)); | |
| 34 if (CFArrayGetCount(sources) != 1) | |
| 35 return PlatformKeyboardLayout(); | |
| 36 | |
| 37 return PlatformKeyboardLayout( | |
| 38 (TISInputSourceRef)CFArrayGetValueAtIndex(sources, 0)); | |
| 39 } | |
| 40 | |
| 41 PlatformKeyboardLayout ScopedKeyboardLayout::GetActiveLayout() { | |
| 42 return PlatformKeyboardLayout(TISCopyCurrentKeyboardInputSource()); | |
| 43 } | |
| 44 | |
| 45 bool ScopedKeyboardLayout::ActivateLayout(PlatformKeyboardLayout layout) { | |
| 46 DCHECK(layout); | |
| 47 return TISSelectInputSource(layout) == noErr; | |
| 48 } | |
| 49 | |
| 50 } // namespace ui | |
| OLD | NEW |