Chromium Code Reviews| Index: views/ime/input_method_win.cc |
| diff --git a/views/ime/input_method_win.cc b/views/ime/input_method_win.cc |
| index 4ab1a187378d389ba70bf8dc6d3131b107afa847..7574ee9f6f224c5f8f2666d92b609332855cdf1d 100644 |
| --- a/views/ime/input_method_win.cc |
| +++ b/views/ime/input_method_win.cc |
| @@ -115,6 +115,9 @@ LRESULT InputMethodWin::OnImeMessages( |
| case WM_IME_ENDCOMPOSITION: |
| result = OnImeEndComposition(message, w_param, l_param, handled); |
| break; |
| + case WM_IME_REQUEST: |
| + result = OnImeRequest(message, w_param, l_param, handled); |
| + break; |
| case WM_CHAR: |
| case WM_SYSCHAR: |
| result = OnChar(message, w_param, l_param, handled); |
| @@ -219,6 +222,29 @@ LRESULT InputMethodWin::OnImeEndComposition( |
| return 0; |
| } |
| +LRESULT InputMethodWin::OnImeRequest( |
| + UINT message, WPARAM wparam, LPARAM lparam, BOOL* handled) { |
| + *handled = FALSE; |
| + |
| + // Should not receive WM_IME_REQUEST message, if IME is disabled. |
| + ui::TextInputType type = GetTextInputType(); |
|
James Su
2011/10/26 18:41:57
nit: const ui::TextInputType
|
| + if (type == ui::TEXT_INPUT_TYPE_NONE || |
| + type == ui::TEXT_INPUT_TYPE_PASSWORD) { |
| + return 0; |
| + } |
| + |
| + switch (wparam) { |
| + case IMR_RECONVERTSTRING: |
| + *handled = TRUE; |
| + return OnReconvertString(reinterpret_cast<RECONVERTSTRING*>(lparam)); |
| + case IMR_DOCUMENTFEED: |
| + *handled = TRUE; |
| + return OnDocumentFeed(reinterpret_cast<RECONVERTSTRING*>(lparam)); |
| + default: |
| + return 0; |
| + } |
| +} |
| + |
| LRESULT InputMethodWin::OnChar( |
| UINT message, WPARAM wparam, LPARAM lparam, BOOL* handled) { |
| *handled = TRUE; |
| @@ -254,6 +280,115 @@ LRESULT InputMethodWin::OnDeadChar( |
| return 0; |
| } |
| +LRESULT InputMethodWin::OnDocumentFeed(RECONVERTSTRING *reconv) { |
| + TextInputClient* client = GetTextInputClient(); |
| + if (!client) |
| + return 0; |
| + |
| + ui::Range text_range; |
| + if (!client->GetTextRange(&text_range) || text_range.is_empty()) |
| + return 0; |
| + |
| + ui::Range target_range; |
| + do { |
| + if (client->HasCompositionText() && |
| + client->GetCompositionTextRange(&target_range) && |
| + !target_range.is_empty()) { |
| + break; |
| + } |
| + if (client->GetSelectionRange(&target_range)) |
| + break; |
| + return 0; |
| + } while (0); |
| + |
| + if (!text_range.Contains(target_range)) |
| + return 0; |
| + |
| + size_t len = text_range.length(); |
| + size_t need_size = sizeof(RECONVERTSTRING) + len * sizeof(WCHAR); |
| + |
| + if (!reconv) |
| + return need_size; |
| + |
| + if (reconv->dwSize < need_size) |
| + return 0; |
| + |
| + string16 text; |
| + ui::Range actual_range; |
| + if (!GetTextInputClient()->GetTextFromRange( |
| + text_range, &text, &actual_range)) { |
| + return 0; |
| + } |
| + |
| + DCHECK(text_range == actual_range); |
| + |
| + reconv->dwVersion = 0; |
| + reconv->dwStrLen = len; |
| + reconv->dwStrOffset = sizeof(RECONVERTSTRING); |
| + reconv->dwCompStrLen = |
| + client->HasCompositionText() ? reconv->dwTargetStrOffset : 0; |
| + reconv->dwCompStrOffset = |
| + (target_range.GetMin() - text_range.start()) * sizeof(WCHAR); |
| + reconv->dwTargetStrLen = target_range.length(); |
| + reconv->dwTargetStrOffset = reconv->dwCompStrOffset; |
| + |
| + memcpy((char*)reconv + sizeof(RECONVERTSTRING), |
| + text.c_str(), len * sizeof(WCHAR)); |
| + |
| + return need_size; |
| +} |
| + |
| +LRESULT InputMethodWin::OnReconvertString(RECONVERTSTRING *reconv) { |
| + TextInputClient* client = GetTextInputClient(); |
| + if (!client) |
| + return 0; |
| + |
| + // If there is a composition string already, we don't allow reconversion. |
| + if (client->HasCompositionText()) |
| + return 0; |
| + |
| + ui::Range text_range; |
| + if (!client->GetTextRange(&text_range) || text_range.is_empty()) |
| + return 0; |
| + |
| + ui::Range selection_range; |
| + if (!client->GetSelectionRange(&selection_range) || |
| + selection_range.is_empty()) { |
| + return 0; |
| + } |
| + |
| + if (!text_range.Contains(selection_range)) |
| + return 0; |
| + |
| + size_t len = text_range.length(); |
|
James Su
2011/10/26 18:41:57
It's better not to return all text content, becaus
|
| + size_t need_size = sizeof(RECONVERTSTRING) + len * sizeof(WCHAR); |
| + |
| + if (!reconv) |
| + return need_size; |
| + |
| + if (reconv->dwSize < need_size) |
| + return 0; |
| + |
| + string16 text; |
| + ui::Range actual_range; |
| + if (!GetTextInputClient()->GetTextFromRange( |
| + text_range, &text, &actual_range)) |
| + return 0; |
| + |
| + reconv->dwVersion = 0; |
| + reconv->dwStrLen = len; |
| + reconv->dwStrOffset = sizeof(RECONVERTSTRING); |
| + reconv->dwCompStrLen = selection_range.length(); |
| + reconv->dwCompStrOffset = |
| + (selection_range.GetMin() - text_range.start()) * sizeof(WCHAR); |
| + reconv->dwTargetStrLen = reconv->dwCompStrLen; |
| + reconv->dwTargetStrOffset = reconv->dwCompStrOffset; |
| + memcpy(reinterpret_cast<char*>(reconv) + sizeof(RECONVERTSTRING), |
| + text.c_str(), len * sizeof(WCHAR)); |
| + |
| + return need_size; |
| +} |
| + |
| void InputMethodWin::ConfirmCompositionText() { |
| if (!IsTextInputTypeNone()) { |
| ime_input_.CleanupComposition(hwnd()); |