Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(375)

Side by Side Diff: ui/events/test/keyboard_layout_mac.cc

Issue 2353333002: Reland of Force U.S. English keyboard layout for TextfieldTest.KeysWithModifiersTest (Closed)
Patch Set: Retain CFArray element being returned Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/events/test/keyboard_layout.cc ('k') | ui/events/test/keyboard_layout_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 PlatformKeyboardLayout(
33 (TISInputSourceRef)CFArrayGetValueAtIndex(input_source_list, 0),
34 base::scoped_policy::RETAIN);
Wez 2016/09/21 16:28:19 nit: Woah, weird; it might be easier-to-read to us
Tomasz Moniuszko 2016/09/23 13:00:48 Done.
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
OLDNEW
« no previous file with comments | « ui/events/test/keyboard_layout.cc ('k') | ui/events/test/keyboard_layout_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698