Chromium Code Reviews| Index: ui/base/ime/win/imm32_manager.cc |
| diff --git a/ui/base/ime/win/imm32_manager.cc b/ui/base/ime/win/imm32_manager.cc |
| index bd50e933942e35e6680f788286d74b7df19bdbf0..6d6887b66d2aaccf7bf3703729ac03f1cb45e39a 100644 |
| --- a/ui/base/ime/win/imm32_manager.cc |
| +++ b/ui/base/ime/win/imm32_manager.cc |
| @@ -124,13 +124,16 @@ IMM32Manager::~IMM32Manager() { |
| } |
| void IMM32Manager::SetInputLanguage() { |
| - // Retrieve the current keyboard layout from Windows and determine whether |
| - // or not the current input context has IMEs. |
| - // Also save its input language for language-specific operations required |
| - // while composing a text. |
| - HKL keyboard_layout = ::GetKeyboardLayout(0); |
| + // Retrieve the current input language from the system's keyboard layout. |
| + // Using GetKeyboardLayoutName instead of GetKeyboardLayout, because |
| + // the language from GetKeyboardLayout is the language under where the |
| + // keyboard layout is installed. And the language from GetKeyboardLayoutName |
| + // indicates the language of the keyboard layout itself. |
| + // See crbug.com/344834. |
| + WCHAR keyboard_layout[KL_NAMELENGTH]; |
| + ::GetKeyboardLayoutNameW(keyboard_layout); |
|
yukawa
2016/09/01 20:15:03
Let's check the return value. If |GetKeyboardLayo
Shu Chen
2016/09/07 03:13:34
Done.
|
| input_language_id_ = |
| - static_cast<LANGID>(reinterpret_cast<uintptr_t>(keyboard_layout)); |
| + static_cast<LANGID>(_wtoi(&keyboard_layout[KL_NAMELENGTH >> 1])); |
| } |
| void IMM32Manager::CreateImeWindow(HWND window_handle) { |
| @@ -457,31 +460,10 @@ void IMM32Manager::SetUseCompositionWindow(bool use_composition_window) { |
| use_composition_window_ = use_composition_window; |
| } |
| -std::string IMM32Manager::GetInputLanguageName() const { |
| - const LCID locale_id = MAKELCID(input_language_id_, SORT_DEFAULT); |
| - // max size for LOCALE_SISO639LANGNAME and LOCALE_SISO3166CTRYNAME is 9. |
| - wchar_t buffer[9]; |
| - |
| - // Get language id. |
| - int length = ::GetLocaleInfo(locale_id, LOCALE_SISO639LANGNAME, &buffer[0], |
| - arraysize(buffer)); |
| - if (length <= 1) |
| - return std::string(); |
| - |
| - std::string language; |
| - base::WideToUTF8(buffer, length - 1, &language); |
| - if (SUBLANGID(input_language_id_) == SUBLANG_NEUTRAL) |
| - return language; |
| - |
| - // Get region id. |
| - length = ::GetLocaleInfo(locale_id, LOCALE_SISO3166CTRYNAME, &buffer[0], |
| - arraysize(buffer)); |
| - if (length <= 1) |
| - return language; |
| - |
| - std::string region; |
| - base::WideToUTF8(buffer, length - 1, ®ion); |
| - return language.append(1, '-').append(region); |
| +bool IMM32Manager::IsInputLanguageCJK() const { |
| + LANGID lang = PRIMARYLANGID(input_language_id_); |
| + return lang == LANG_CHINESE || lang == LANG_JAPANESE || |
| + lang == LANG_KOREAN; |
| } |
| void IMM32Manager::SetTextInputMode(HWND window_handle, |