OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/input_method_imm32.h" | 5 #include "ui/base/ime/input_method_imm32.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "ui/base/ime/composition_text.h" | 8 #include "ui/base/ime/composition_text.h" |
9 #include "ui/base/ime/text_input_client.h" | 9 #include "ui/base/ime/text_input_client.h" |
10 | 10 |
11 | 11 |
12 namespace ui { | 12 namespace ui { |
13 | 13 |
14 InputMethodIMM32::InputMethodIMM32(internal::InputMethodDelegate* delegate, | 14 InputMethodIMM32::InputMethodIMM32(internal::InputMethodDelegate* delegate, |
15 HWND toplevel_window_handle) | 15 HWND toplevel_window_handle) |
16 : InputMethodWin(delegate, toplevel_window_handle), | 16 : InputMethodWin(delegate, toplevel_window_handle), |
17 enabled_(false), | 17 enabled_(false), is_candidate_popup_open_(false), |
18 composing_window_handle_(NULL) { | 18 composing_window_handle_(NULL) { |
19 // In non-Aura environment, appropriate callbacks to OnFocus() and OnBlur() | 19 // In non-Aura environment, appropriate callbacks to OnFocus() and OnBlur() |
20 // are not implemented yet. To work around this limitation, here we use | 20 // are not implemented yet. To work around this limitation, here we use |
21 // "always focused" model. | 21 // "always focused" model. |
22 // TODO(ime): Fix the caller of OnFocus() and OnBlur() so that appropriate | 22 // TODO(ime): Fix the caller of OnFocus() and OnBlur() so that appropriate |
23 // focus event will be passed. | 23 // focus event will be passed. |
24 InputMethodWin::OnFocus(); | 24 InputMethodWin::OnFocus(); |
25 } | 25 } |
26 | 26 |
27 void InputMethodIMM32::OnFocus() { | 27 void InputMethodIMM32::OnFocus() { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 case WM_CHAR: | 64 case WM_CHAR: |
65 case WM_SYSCHAR: | 65 case WM_SYSCHAR: |
66 original_result = OnChar( | 66 original_result = OnChar( |
67 event.message, event.wParam, event.lParam, &handled); | 67 event.message, event.wParam, event.lParam, &handled); |
68 break; | 68 break; |
69 case WM_DEADCHAR: | 69 case WM_DEADCHAR: |
70 case WM_SYSDEADCHAR: | 70 case WM_SYSDEADCHAR: |
71 original_result = OnDeadChar( | 71 original_result = OnDeadChar( |
72 event.message, event.wParam, event.lParam, &handled); | 72 event.message, event.wParam, event.lParam, &handled); |
73 break; | 73 break; |
| 74 case WM_IME_NOTIFY: |
| 75 original_result = OnImeNotify( |
| 76 event.message, event.wParam, event.lParam, &handled); |
| 77 break; |
74 default: | 78 default: |
75 NOTREACHED() << "Unknown IME message:" << event.message; | 79 NOTREACHED() << "Unknown IME message:" << event.message; |
76 break; | 80 break; |
77 } | 81 } |
78 if (result) | 82 if (result) |
79 *result = original_result; | 83 *result = original_result; |
80 return !!handled; | 84 return !!handled; |
81 } | 85 } |
82 | 86 |
83 void InputMethodIMM32::OnTextInputTypeChanged(const TextInputClient* client) { | 87 void InputMethodIMM32::OnTextInputTypeChanged(const TextInputClient* client) { |
(...skipping 30 matching lines...) Expand all Loading... |
114 void InputMethodIMM32::CancelComposition(const TextInputClient* client) { | 118 void InputMethodIMM32::CancelComposition(const TextInputClient* client) { |
115 if (enabled_ && IsTextInputClientFocused(client)) | 119 if (enabled_ && IsTextInputClientFocused(client)) |
116 ime_input_.CancelIME(GetAttachedWindowHandle(client)); | 120 ime_input_.CancelIME(GetAttachedWindowHandle(client)); |
117 } | 121 } |
118 | 122 |
119 void InputMethodIMM32::SetFocusedTextInputClient(TextInputClient* client) { | 123 void InputMethodIMM32::SetFocusedTextInputClient(TextInputClient* client) { |
120 ConfirmCompositionText(); | 124 ConfirmCompositionText(); |
121 InputMethodWin::SetFocusedTextInputClient(client); | 125 InputMethodWin::SetFocusedTextInputClient(client); |
122 } | 126 } |
123 | 127 |
| 128 bool InputMethodIMM32::IsCandidatePopupOpen() const { |
| 129 return is_candidate_popup_open_; |
| 130 } |
| 131 |
124 void InputMethodIMM32::OnWillChangeFocusedClient( | 132 void InputMethodIMM32::OnWillChangeFocusedClient( |
125 TextInputClient* focused_before, | 133 TextInputClient* focused_before, |
126 TextInputClient* focused) { | 134 TextInputClient* focused) { |
127 if (IsWindowFocused(focused_before)) { | 135 if (IsWindowFocused(focused_before)) { |
128 ConfirmCompositionText(); | 136 ConfirmCompositionText(); |
129 } | 137 } |
130 } | 138 } |
131 | 139 |
132 void InputMethodIMM32::OnDidChangeFocusedClient(TextInputClient* focused_before, | 140 void InputMethodIMM32::OnDidChangeFocusedClient(TextInputClient* focused_before, |
133 TextInputClient* focused) { | 141 TextInputClient* focused) { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 composing_window_handle_ = NULL; | 228 composing_window_handle_ = NULL; |
221 | 229 |
222 if (!IsTextInputTypeNone() && GetTextInputClient()->HasCompositionText()) | 230 if (!IsTextInputTypeNone() && GetTextInputClient()->HasCompositionText()) |
223 GetTextInputClient()->ClearCompositionText(); | 231 GetTextInputClient()->ClearCompositionText(); |
224 | 232 |
225 ime_input_.ResetComposition(window_handle); | 233 ime_input_.ResetComposition(window_handle); |
226 ime_input_.DestroyImeWindow(window_handle); | 234 ime_input_.DestroyImeWindow(window_handle); |
227 return 0; | 235 return 0; |
228 } | 236 } |
229 | 237 |
| 238 LRESULT InputMethodIMM32::OnImeNotify(UINT message, |
| 239 WPARAM wparam, |
| 240 LPARAM lparam, |
| 241 BOOL* handled) { |
| 242 *handled = FALSE; |
| 243 |
| 244 // Update |is_candidate_popup_open_|, whether a candidate window is open. |
| 245 switch (wparam) { |
| 246 case IMN_OPENCANDIDATE: |
| 247 is_candidate_popup_open_ = true; |
| 248 break; |
| 249 case IMN_CLOSECANDIDATE: |
| 250 is_candidate_popup_open_ = false; |
| 251 break; |
| 252 } |
| 253 |
| 254 return 0; |
| 255 } |
| 256 |
230 void InputMethodIMM32::ConfirmCompositionText() { | 257 void InputMethodIMM32::ConfirmCompositionText() { |
231 if (composing_window_handle_) | 258 if (composing_window_handle_) |
232 ime_input_.CleanupComposition(composing_window_handle_); | 259 ime_input_.CleanupComposition(composing_window_handle_); |
233 | 260 |
234 if (!IsTextInputTypeNone()) { | 261 if (!IsTextInputTypeNone()) { |
235 // Though above line should confirm the client's composition text by sending | 262 // Though above line should confirm the client's composition text by sending |
236 // a result text to us, in case the input method and the client are in | 263 // a result text to us, in case the input method and the client are in |
237 // inconsistent states, we check the client's composition state again. | 264 // inconsistent states, we check the client's composition state again. |
238 if (GetTextInputClient()->HasCompositionText()) | 265 if (GetTextInputClient()->HasCompositionText()) |
239 GetTextInputClient()->ConfirmCompositionText(); | 266 GetTextInputClient()->ConfirmCompositionText(); |
(...skipping 17 matching lines...) Expand all Loading... |
257 } | 284 } |
258 | 285 |
259 bool InputMethodIMM32::IsWindowFocused(const TextInputClient* client) const { | 286 bool InputMethodIMM32::IsWindowFocused(const TextInputClient* client) const { |
260 if (!client) | 287 if (!client) |
261 return false; | 288 return false; |
262 HWND attached_window_handle = GetAttachedWindowHandle(client); | 289 HWND attached_window_handle = GetAttachedWindowHandle(client); |
263 return attached_window_handle && GetFocus() == attached_window_handle; | 290 return attached_window_handle && GetFocus() == attached_window_handle; |
264 } | 291 } |
265 | 292 |
266 } // namespace ui | 293 } // namespace ui |
OLD | NEW |