Index: ui/events/test/keyboard_layout_mac.cc |
diff --git a/ui/events/test/keyboard_layout_mac.cc b/ui/events/test/keyboard_layout_mac.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..bf8d6aa2e55c29956b48e0e166b3347f5dfab7f6 |
--- /dev/null |
+++ b/ui/events/test/keyboard_layout_mac.cc |
@@ -0,0 +1,43 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "ui/events/test/keyboard_layout.h" |
+ |
+#include "base/logging.h" |
+ |
+namespace ui { |
+ |
+PlatformKeyboardLayout GetPlatformKeyboardLayout(KeyboardLayout layout) { |
+ // Right now tests only need US English. If other layouts need to be |
+ // supported in the future this code should be extended. |
+ DCHECK_EQ(KEYBOARD_LAYOUT_ENGLISH_US, layout); |
Wez
2016/09/13 20:03:16
nit: I generally recommend leaving a blank-line be
Tomasz Moniuszko
2016/09/14 13:56:06
Done.
|
+ const char input_source_id[] = "com.apple.keylayout.US"; |
Wez
2016/09/13 20:03:16
kInputSourceId? Or kUsInputSourceId?
Tomasz Moniuszko
2016/09/14 13:56:06
Done.
|
+ |
+ base::ScopedCFTypeRef<CFMutableDictionaryRef> filter_dict( |
Wez
2016/09/13 20:03:16
Can we give the variables in this section more hel
Tomasz Moniuszko
2016/09/14 13:56:06
I moved this code from chrome/test/chromedriver/te
Wez
2016/09/16 00:57:18
Thanks!
|
+ CFDictionaryCreateMutable(kCFAllocatorDefault, 1, |
+ &kCFTypeDictionaryKeyCallBacks, |
+ &kCFTypeDictionaryValueCallBacks)); |
+ base::ScopedCFTypeRef<CFStringRef> id_ref(CFStringCreateWithCString( |
+ kCFAllocatorDefault, input_source_id, kCFStringEncodingUTF8)); |
+ CFDictionaryAddValue(filter_dict, kTISPropertyInputSourceID, id_ref); |
+ base::ScopedCFTypeRef<CFArrayRef> sources( |
+ TISCreateInputSourceList(filter_dict, true)); |
+ if (CFArrayGetCount(sources) != 1) |
+ return PlatformKeyboardLayout(); |
+ |
+ return PlatformKeyboardLayout( |
+ (TISInputSourceRef)CFArrayGetValueAtIndex(sources, 0)); |
+} |
+ |
+PlatformKeyboardLayout ScopedKeyboardLayout::GetActiveLayout() { |
+ return PlatformKeyboardLayout(TISCopyCurrentKeyboardInputSource()); |
+} |
+ |
+void ScopedKeyboardLayout::ActivateLayout(PlatformKeyboardLayout layout) { |
+ DCHECK(layout); |
+ OSStatus result = TISSelectInputSource(layout); |
+ DCHECK_EQ(noErr, result); |
+} |
+ |
+} // namespace ui |