| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013 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 "chrome/test/chromedriver/test_util.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/strings/utf_string_conversions.h" | |
| 9 #include "build/build_config.h" | |
| 10 | |
| 11 RestoreKeyboardLayoutOnDestruct::RestoreKeyboardLayoutOnDestruct() { | |
| 12 #if defined(OS_WIN) | |
| 13 layout_ = GetKeyboardLayout(NULL); | |
| 14 #elif defined(OS_MACOSX) | |
| 15 layout_.reset(TISCopyCurrentKeyboardInputSource()); | |
| 16 #elif defined(OS_LINUX) | |
| 17 NOTIMPLEMENTED(); | |
| 18 #endif | |
| 19 } | |
| 20 | |
| 21 RestoreKeyboardLayoutOnDestruct::~RestoreKeyboardLayoutOnDestruct() { | |
| 22 #if defined(OS_WIN) | |
| 23 ActivateKeyboardLayout(layout_, 0); | |
| 24 #elif defined(OS_MACOSX) | |
| 25 TISSelectInputSource(layout_); | |
| 26 #elif defined(OS_LINUX) | |
| 27 NOTIMPLEMENTED(); | |
| 28 #endif | |
| 29 } | |
| 30 | |
| 31 #if defined(OS_WIN) | |
| 32 bool SwitchKeyboardLayout(const std::string& input_locale_identifier) { | |
| 33 HKL layout = LoadKeyboardLayout( | |
| 34 base::UTF8ToWide(input_locale_identifier).c_str(), 0); | |
| 35 if (!layout) | |
| 36 return false; | |
| 37 return !!ActivateKeyboardLayout(layout, 0); | |
| 38 } | |
| 39 #endif // defined(OS_WIN) | |
| 40 | |
| 41 #if defined(OS_MACOSX) | |
| 42 bool SwitchKeyboardLayout(const std::string& input_source_id) { | |
| 43 base::ScopedCFTypeRef<CFMutableDictionaryRef> filter_dict( | |
| 44 CFDictionaryCreateMutable(kCFAllocatorDefault, | |
| 45 1, | |
| 46 &kCFTypeDictionaryKeyCallBacks, | |
| 47 &kCFTypeDictionaryValueCallBacks)); | |
| 48 base::ScopedCFTypeRef<CFStringRef> id_ref(CFStringCreateWithCString( | |
| 49 kCFAllocatorDefault, input_source_id.c_str(), kCFStringEncodingUTF8)); | |
| 50 CFDictionaryAddValue(filter_dict, kTISPropertyInputSourceID, id_ref); | |
| 51 base::ScopedCFTypeRef<CFArrayRef> sources( | |
| 52 TISCreateInputSourceList(filter_dict, true)); | |
| 53 if (CFArrayGetCount(sources) != 1) | |
| 54 return false; | |
| 55 TISInputSourceRef source = (TISInputSourceRef)CFArrayGetValueAtIndex( | |
| 56 sources, 0); | |
| 57 return TISSelectInputSource(source) == noErr; | |
| 58 } | |
| 59 #endif // defined(OS_MACOSX) | |
| OLD | NEW |