diff options
author | hbono@chromium.org <hbono@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-06 07:40:53 +0000 |
---|---|---|
committer | hbono@chromium.org <hbono@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-06 07:40:53 +0000 |
commit | 34f6bc1937fe617875e8f5e95485904569cca582 (patch) | |
tree | 94f201b6bb78ff601a8a97783f4ac0134423af48 /chrome/browser/ime_input.cc | |
parent | 576d8bff4e6778c6de60b8a7269a78c5e8bf602a (diff) | |
download | chromium_src-34f6bc1937fe617875e8f5e95485904569cca582.zip chromium_src-34f6bc1937fe617875e8f5e95485904569cca582.tar.gz chromium_src-34f6bc1937fe617875e8f5e95485904569cca582.tar.bz2 |
Changes parameters used by IME code to fix several issues caused by Japanese IMEs.
Recent Japanese IMEs (ATOK2008 and MSIME 2007) display a suggestion window (a window which contains suggestions) above a composition string. To fix this issue, we do not only send the lower-left corner of a composition string but also send its upper-left corner and its upper-right corner. So, this change changes IPC parameters used by IME from a tuple of integers to gfx::Rect.
Also, this change fixes cursor positions for Japanese IMEs.
BUG=2770 "IME: Candidate window of Japanese IME follows the end of composition"
BUG=2771 "ATOK 2008 IME pop-ups are displayed below the main Chrome window."
BUG=2775 "IME: Caret is always displayed at the last of IME composition."
Review URL: http://codereview.chromium.org/7385
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4872 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ime_input.cc')
-rw-r--r-- | chrome/browser/ime_input.cc | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/chrome/browser/ime_input.cc b/chrome/browser/ime_input.cc index 83bd090..68bde20 100644 --- a/chrome/browser/ime_input.cc +++ b/chrome/browser/ime_input.cc @@ -20,8 +20,7 @@ ImeInput::ImeInput() input_language_id_(LANG_USER_DEFAULT), is_composing_(false), system_caret_(false), - caret_x_(-1), - caret_y_(-1) { + caret_rect_(-1, -1, 0, 0) { } ImeInput::~ImeInput() { @@ -48,7 +47,10 @@ void ImeInput::CreateImeWindow(HWND window_handle) { // retrieve the position of their IME candidate window. // Therefore, we create a temporary system caret for Chinese IMEs and use // it during this input context. - if (PRIMARYLANGID(input_language_id_) == LANG_CHINESE) { + // Since some third-party Japanese IME also uses ::GetCaretPos() to determine + // their window position, we also create a caret for Japanese IMEs. + if (PRIMARYLANGID(input_language_id_) == LANG_CHINESE || + PRIMARYLANGID(input_language_id_) == LANG_JAPANESE) { if (!system_caret_) { if (::CreateCaret(window_handle, NULL, 1, 1)) { system_caret_ = true; @@ -84,8 +86,8 @@ void ImeInput::DestroyImeWindow(HWND window_handle) { } void ImeInput::MoveImeWindow(HWND window_handle, HIMC imm_context) { - int x = caret_x_; - int y = caret_y_; + int x = caret_rect_.x(); + int y = caret_rect_.y(); const int kCaretMargin = 1; // As written in a comment in ImeInput::CreateImeWindow(), // Chinese IMEs ignore function calls to ::ImmSetCandidateWindow() @@ -101,7 +103,14 @@ void ImeInput::MoveImeWindow(HWND window_handle, HIMC imm_context) { {0, 0, 0, 0}}; ::ImmSetCandidateWindow(imm_context, &candidate_position); if (system_caret_) { - ::SetCaretPos(x, y); + switch (PRIMARYLANGID(input_language_id_)) { + case LANG_JAPANESE: + ::SetCaretPos(x, y + caret_rect_.height()); + break; + default: + ::SetCaretPos(x, y); + break; + } } if (PRIMARYLANGID(input_language_id_) == LANG_KOREAN) { // Chinese IMEs and Japanese IMEs require the upper-left corner of @@ -115,13 +124,13 @@ void ImeInput::MoveImeWindow(HWND window_handle, HIMC imm_context) { // to move their candidate windows when a user disables TSF and CUAS. // Therefore, we also set this parameter here. CANDIDATEFORM exclude_rectangle = {0, CFS_EXCLUDE, {x, y}, - {x, y, x, y + kCaretMargin}}; + {x, y, x + caret_rect_.width(), y + caret_rect_.height()}}; ::ImmSetCandidateWindow(imm_context, &exclude_rectangle); } void ImeInput::UpdateImeWindow(HWND window_handle) { // Just move the IME window attached to the given window. - if (caret_x_ >= 0 && caret_y_ >= 0) { + if (caret_rect_.x() >= 0 && caret_rect_.y() >= 0) { HIMC imm_context = ::ImmGetContext(window_handle); if (imm_context) { MoveImeWindow(window_handle, imm_context); @@ -185,8 +194,6 @@ void ImeInput::GetCaret(HIMC imm_context, LPARAM lparam, // is scanning the attribute of the latest composition string and // retrieving the begining and the end of the target clause, i.e. // a clause being converted. - size_t composition_length = composition->ime_string.length(); - composition->cursor_position = static_cast<int>(composition_length); if (lparam & GCS_COMPATTR) { int attribute_size = ::ImmGetCompositionString(imm_context, GCS_COMPATTR, @@ -297,7 +304,9 @@ void ImeInput::DisableIME(HWND window_handle) { ::ImmAssociateContextEx(window_handle, NULL, 0); } -void ImeInput::EnableIME(HWND window_handle, int x, int y, bool complete) { +void ImeInput::EnableIME(HWND window_handle, + const gfx::Rect& caret_rect, + bool complete) { // Load the default IME context. // NOTE(hbono) // IMM ignores this call if the IME context is loaded. Therefore, we do @@ -318,9 +327,9 @@ void ImeInput::EnableIME(HWND window_handle, int x, int y, bool complete) { // Save the caret position, and Update the position of the IME window. // This update is used for moving an IME window when a renderer process // resize/moves the input caret. - if (x >= 0 && y >= 0) { - caret_x_ = x; - caret_y_ = y; + if (caret_rect.x() >= 0 && caret_rect.y() >= 0) { + caret_rect_.SetRect(caret_rect.x(), caret_rect.y(), caret_rect.width(), + caret_rect.height()); MoveImeWindow(window_handle, imm_context); } ::ImmReleaseContext(window_handle, imm_context); |