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 DCHECK_EQ(layout, KEYBOARD_LAYOUT_ENGLISH_US); | |
|
Peter Kasting
2016/08/31 21:16:15
Nit: (expected, actual)
You might want a comment
| |
| 13 const char input_source_id[] = "com.apple.keylayout.US"; | |
| 14 | |
| 15 base::ScopedCFTypeRef<CFMutableDictionaryRef> filter_dict( | |
| 16 CFDictionaryCreateMutable(kCFAllocatorDefault, 1, | |
| 17 &kCFTypeDictionaryKeyCallBacks, | |
| 18 &kCFTypeDictionaryValueCallBacks)); | |
| 19 base::ScopedCFTypeRef<CFStringRef> id_ref(CFStringCreateWithCString( | |
| 20 kCFAllocatorDefault, input_source_id, kCFStringEncodingUTF8)); | |
| 21 CFDictionaryAddValue(filter_dict, kTISPropertyInputSourceID, id_ref); | |
| 22 base::ScopedCFTypeRef<CFArrayRef> sources( | |
| 23 TISCreateInputSourceList(filter_dict, true)); | |
| 24 if (CFArrayGetCount(sources) != 1) | |
| 25 return PlatformKeyboardLayout(); | |
| 26 | |
| 27 return PlatformKeyboardLayout( | |
| 28 (TISInputSourceRef)CFArrayGetValueAtIndex(sources, 0)); | |
| 29 } | |
| 30 | |
| 31 PlatformKeyboardLayout ScopedKeyboardLayout::GetActiveLayout() { | |
| 32 return PlatformKeyboardLayout(TISCopyCurrentKeyboardInputSource()); | |
| 33 } | |
| 34 | |
| 35 bool ScopedKeyboardLayout::ActivateLayout(PlatformKeyboardLayout layout) { | |
| 36 DCHECK(layout); | |
| 37 return TISSelectInputSource(layout) == noErr; | |
| 38 } | |
| 39 | |
| 40 } // namespace ui | |
| OLD | NEW |