| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/base/ime/win/imm32_manager.h" | 5 #include "ui/base/ime/win/imm32_manager.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 input_language_id_(LANG_USER_DEFAULT), | 117 input_language_id_(LANG_USER_DEFAULT), |
| 118 system_caret_(false), | 118 system_caret_(false), |
| 119 caret_rect_(-1, -1, 0, 0), | 119 caret_rect_(-1, -1, 0, 0), |
| 120 use_composition_window_(false) { | 120 use_composition_window_(false) { |
| 121 } | 121 } |
| 122 | 122 |
| 123 IMM32Manager::~IMM32Manager() { | 123 IMM32Manager::~IMM32Manager() { |
| 124 } | 124 } |
| 125 | 125 |
| 126 void IMM32Manager::SetInputLanguage() { | 126 void IMM32Manager::SetInputLanguage() { |
| 127 // Retrieve the current keyboard layout from Windows and determine whether | 127 // Retrieve the current input language from the system's keyboard layout. |
| 128 // or not the current input context has IMEs. | 128 // Using GetKeyboardLayoutName instead of GetKeyboardLayout, because |
| 129 // Also save its input language for language-specific operations required | 129 // the language from GetKeyboardLayout is the language under where the |
| 130 // while composing a text. | 130 // keyboard layout is installed. And the language from GetKeyboardLayoutName |
| 131 HKL keyboard_layout = ::GetKeyboardLayout(0); | 131 // indicates the language of the keyboard layout itself. |
| 132 input_language_id_ = | 132 // See crbug.com/344834. |
| 133 static_cast<LANGID>(reinterpret_cast<uintptr_t>(keyboard_layout)); | 133 WCHAR keyboard_layout[KL_NAMELENGTH]; |
| 134 if (::GetKeyboardLayoutNameW(keyboard_layout)) { |
| 135 input_language_id_ = |
| 136 static_cast<LANGID>(_wtoi(&keyboard_layout[KL_NAMELENGTH >> 1])); |
| 137 } else { |
| 138 input_language_id_ = 0x0409; // Fallback to en-US. |
| 139 } |
| 134 } | 140 } |
| 135 | 141 |
| 136 void IMM32Manager::CreateImeWindow(HWND window_handle) { | 142 void IMM32Manager::CreateImeWindow(HWND window_handle) { |
| 137 // When a user disables TSF (Text Service Framework) and CUAS (Cicero | 143 // When a user disables TSF (Text Service Framework) and CUAS (Cicero |
| 138 // Unaware Application Support), Chinese IMEs somehow ignore function calls | 144 // Unaware Application Support), Chinese IMEs somehow ignore function calls |
| 139 // to ::ImmSetCandidateWindow(), i.e. they do not move their candidate | 145 // to ::ImmSetCandidateWindow(), i.e. they do not move their candidate |
| 140 // window to the position given as its parameters, and use the position | 146 // window to the position given as its parameters, and use the position |
| 141 // of the current system caret instead, i.e. it uses ::GetCaretPos() to | 147 // of the current system caret instead, i.e. it uses ::GetCaretPos() to |
| 142 // retrieve the position of their IME candidate window. | 148 // retrieve the position of their IME candidate window. |
| 143 // Therefore, we create a temporary system caret for Chinese IMEs and use | 149 // Therefore, we create a temporary system caret for Chinese IMEs and use |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 MoveImeWindow(window_handle, imm_context); | 456 MoveImeWindow(window_handle, imm_context); |
| 451 ::ImmReleaseContext(window_handle, imm_context); | 457 ::ImmReleaseContext(window_handle, imm_context); |
| 452 } | 458 } |
| 453 } | 459 } |
| 454 } | 460 } |
| 455 | 461 |
| 456 void IMM32Manager::SetUseCompositionWindow(bool use_composition_window) { | 462 void IMM32Manager::SetUseCompositionWindow(bool use_composition_window) { |
| 457 use_composition_window_ = use_composition_window; | 463 use_composition_window_ = use_composition_window; |
| 458 } | 464 } |
| 459 | 465 |
| 460 std::string IMM32Manager::GetInputLanguageName() const { | 466 bool IMM32Manager::IsInputLanguageCJK() const { |
| 461 const LCID locale_id = MAKELCID(input_language_id_, SORT_DEFAULT); | 467 LANGID lang = PRIMARYLANGID(input_language_id_); |
| 462 // max size for LOCALE_SISO639LANGNAME and LOCALE_SISO3166CTRYNAME is 9. | 468 return lang == LANG_CHINESE || lang == LANG_JAPANESE || |
| 463 wchar_t buffer[9]; | 469 lang == LANG_KOREAN; |
| 464 | |
| 465 // Get language id. | |
| 466 int length = ::GetLocaleInfo(locale_id, LOCALE_SISO639LANGNAME, &buffer[0], | |
| 467 arraysize(buffer)); | |
| 468 if (length <= 1) | |
| 469 return std::string(); | |
| 470 | |
| 471 std::string language; | |
| 472 base::WideToUTF8(buffer, length - 1, &language); | |
| 473 if (SUBLANGID(input_language_id_) == SUBLANG_NEUTRAL) | |
| 474 return language; | |
| 475 | |
| 476 // Get region id. | |
| 477 length = ::GetLocaleInfo(locale_id, LOCALE_SISO3166CTRYNAME, &buffer[0], | |
| 478 arraysize(buffer)); | |
| 479 if (length <= 1) | |
| 480 return language; | |
| 481 | |
| 482 std::string region; | |
| 483 base::WideToUTF8(buffer, length - 1, ®ion); | |
| 484 return language.append(1, '-').append(region); | |
| 485 } | 470 } |
| 486 | 471 |
| 487 void IMM32Manager::SetTextInputMode(HWND window_handle, | 472 void IMM32Manager::SetTextInputMode(HWND window_handle, |
| 488 TextInputMode input_mode) { | 473 TextInputMode input_mode) { |
| 489 if (input_mode == ui::TEXT_INPUT_MODE_DEFAULT) | 474 if (input_mode == ui::TEXT_INPUT_MODE_DEFAULT) |
| 490 return; | 475 return; |
| 491 | 476 |
| 492 const HIMC imm_context = ::ImmGetContext(window_handle); | 477 const HIMC imm_context = ::ImmGetContext(window_handle); |
| 493 if (!imm_context) | 478 if (!imm_context) |
| 494 return; | 479 return; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 | IME_CMODE_KATAKANA | 601 | IME_CMODE_KATAKANA |
| 617 | IME_CMODE_FULLSHAPE); | 602 | IME_CMODE_FULLSHAPE); |
| 618 break; | 603 break; |
| 619 default: | 604 default: |
| 620 *open = FALSE; | 605 *open = FALSE; |
| 621 break; | 606 break; |
| 622 } | 607 } |
| 623 } | 608 } |
| 624 | 609 |
| 625 } // namespace ui | 610 } // namespace ui |
| OLD | NEW |