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..1cd01f535c6f6f55ddd224443fb00907d431aa36 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,126 @@ LRESULT InputMethodWin::OnImeEndComposition( |
return 0; |
} |
+LRESULT InputMethodWin::OnReconvertString(RECONVERTSTRING *reconv) { |
James Su
2011/10/25 19:15:03
Please keep the order of methods in .cc file same
Peng
2011/10/25 22:01:21
Done.
James Su
2011/10/26 04:25:38
It's not done yet. OnReconvertString() and OnDocum
Peng
2011/10/26 16:20:16
Sorry. Done again.
|
+ 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 selection_range; |
+ if (!client->GetSelectionRange(&selection_range) || |
+ selection_range.is_empty()) { |
+ return 0; |
+ } |
+ |
+ size_t len = selection_range.length(); |
+ size_t need_size = sizeof(RECONVERTSTRING) + len * sizeof(WCHAR); |
James Su
2011/10/25 19:15:03
It's better to return some extra content around se
Peng
2011/10/25 22:01:21
This logic is same with firefox. And currently we
James Su
2011/10/26 04:25:38
I think you misunderstood the purpose of those ext
Peng
2011/10/26 16:20:16
Done.
|
+ |
+ if (!reconv) |
+ return need_size; |
James Su
2011/10/25 19:15:03
The actual_range returned by TextInputClient::GetT
Peng
2011/10/25 22:01:21
Because text range must cover the selection range,
James Su
2011/10/26 04:25:38
You can't assume it here, especially if you want t
Peng
2011/10/26 16:20:16
Actually, I would like to remove actual_range from
James Su
2011/10/26 18:41:57
I don't think it's ok. The current api design look
Peng
2011/10/26 19:36:53
Remove acutal_range, can make both caller and text
James Su
2011/10/26 19:57:17
actual_range is necessary from the api design poin
Peng
2011/10/27 00:28:00
I didn't get it. Why we must have it from the API
James Su
2011/10/27 04:56:39
Without |actual_range| it's impossible for the cli
Peng
2011/10/27 16:12:24
I refined the document. The text input client must
|
+ |
+ if (reconv->dwSize < need_size) |
+ return 0; |
+ |
+ string16 text; |
+ ui::Range actual_range; |
+ if (!GetTextInputClient()->GetTextFromRange( |
+ selection_range, &text, &actual_range)) |
+ return 0; |
+ |
+ reconv->dwVersion = 0; |
+ reconv->dwStrLen = len; |
+ reconv->dwStrOffset = sizeof(RECONVERTSTRING); |
+ reconv->dwCompStrLen = len; |
+ reconv->dwCompStrOffset = 0; |
+ reconv->dwTargetStrLen = len; |
+ reconv->dwTargetStrOffset = 0; |
+ memcpy(reinterpret_cast<char*>(reconv) + sizeof(RECONVERTSTRING), |
+ text.c_str(), len * sizeof(WCHAR)); |
+ |
+ return need_size; |
+} |
+ |
+LRESULT InputMethodWin::OnDocumentFeed(RECONVERTSTRING *reconv) { |
James Su
2011/10/25 19:15:03
Please refer to the Microsoft sample to see how th
Peng
2011/10/25 22:01:21
It is almost same with MS sample. Only a little di
James Su
2011/10/26 04:25:38
I mean the extra context thing.
Peng
2011/10/26 16:20:16
This function returns all text which can be access
James Su
2011/10/26 18:41:57
I suggest to do the same thing as the Microsoft SD
Peng
2011/10/26 19:36:53
It is not easy task to decide how large context is
James Su
2011/10/26 19:57:17
The content in omnibox might be huge, especially w
Peng
2011/10/27 00:28:00
So I think currently it is better to just return t
James Su
2011/10/27 04:56:39
As I said, the document might be huge, and if the
Peng
2011/10/27 16:12:24
I would like to implement this function as firefox
|
+ 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); |
James Su
2011/10/25 19:15:03
nit: I don't like do { } while(0); style myself. I
Peng
2011/10/25 22:01:21
I tried using 'if else', but it looks worse.
James Su
2011/10/26 04:25:38
Please try your best to rewrite this piece of code
Peng
2011/10/26 16:20:16
I think it is not a big deal. It is very common fo
James Su
2011/10/26 18:41:57
I'd prefer something like:
ui::Range target_range
Peng
2011/10/26 19:36:53
Do not need check the return value of GetCompositi
James Su
2011/10/26 19:57:17
The return value is actually not a big deal here.
Peng
2011/10/27 00:28:00
Done.
|
+ |
+ 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::OnImeRequest( |
+ UINT message, WPARAM wparam, LPARAM lparam, BOOL* handled) { |
+ *handled = FALSE; |
+ |
+ if (IsTextInputTypeNone()) |
+ return 0; |
+ |
+ switch (wparam) { |
+ case IMR_RECONVERTSTRING: |
+ *handled = TRUE; |
James Su
2011/10/25 19:15:03
should we set *handled to FALSE if any method of T
Peng
2011/10/25 22:01:21
I think we should set *handled to TRUE, because we
|
+ 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; |