| 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/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_popup_open_(false) { |
| 18 } | 18 } |
| 19 | 19 |
| 20 void InputMethodIMM32::OnFocus() { | 20 void InputMethodIMM32::OnFocus() { |
| 21 InputMethodWin::OnFocus(); | 21 InputMethodWin::OnFocus(); |
| 22 UpdateIMEState(); | 22 UpdateIMEState(); |
| 23 } | 23 } |
| 24 | 24 |
| 25 void InputMethodIMM32::OnBlur() { | 25 void InputMethodIMM32::OnBlur() { |
| 26 ConfirmCompositionText(); | 26 ConfirmCompositionText(); |
| 27 InputMethodWin::OnBlur(); | 27 InputMethodWin::OnBlur(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 55 case WM_CHAR: | 55 case WM_CHAR: |
| 56 case WM_SYSCHAR: | 56 case WM_SYSCHAR: |
| 57 original_result = OnChar( | 57 original_result = OnChar( |
| 58 event.message, event.wParam, event.lParam, &handled); | 58 event.message, event.wParam, event.lParam, &handled); |
| 59 break; | 59 break; |
| 60 case WM_DEADCHAR: | 60 case WM_DEADCHAR: |
| 61 case WM_SYSDEADCHAR: | 61 case WM_SYSDEADCHAR: |
| 62 original_result = OnDeadChar( | 62 original_result = OnDeadChar( |
| 63 event.message, event.wParam, event.lParam, &handled); | 63 event.message, event.wParam, event.lParam, &handled); |
| 64 break; | 64 break; |
| 65 case WM_IME_NOTIFY: |
| 66 original_result = OnImeNotify( |
| 67 event.message, event.wParam, event.lParam, &handled); |
| 68 break; |
| 65 default: | 69 default: |
| 66 NOTREACHED() << "Unknown IME message:" << event.message; | 70 NOTREACHED() << "Unknown IME message:" << event.message; |
| 67 break; | 71 break; |
| 68 } | 72 } |
| 69 if (result) | 73 if (result) |
| 70 *result = original_result; | 74 *result = original_result; |
| 71 return !!handled; | 75 return !!handled; |
| 72 } | 76 } |
| 73 | 77 |
| 74 void InputMethodIMM32::OnTextInputTypeChanged(const TextInputClient* client) { | 78 void InputMethodIMM32::OnTextInputTypeChanged(const TextInputClient* client) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 101 | 105 |
| 102 void InputMethodIMM32::CancelComposition(const TextInputClient* client) { | 106 void InputMethodIMM32::CancelComposition(const TextInputClient* client) { |
| 103 if (enabled_ && IsTextInputClientFocused(client)) | 107 if (enabled_ && IsTextInputClientFocused(client)) |
| 104 ime_input_.CancelIME(GetAttachedWindowHandle(client)); | 108 ime_input_.CancelIME(GetAttachedWindowHandle(client)); |
| 105 } | 109 } |
| 106 | 110 |
| 107 void InputMethodIMM32::SetFocusedTextInputClient(TextInputClient* client) { | 111 void InputMethodIMM32::SetFocusedTextInputClient(TextInputClient* client) { |
| 108 InputMethodWin::SetFocusedTextInputClient(client); | 112 InputMethodWin::SetFocusedTextInputClient(client); |
| 109 } | 113 } |
| 110 | 114 |
| 115 bool InputMethodIMM32::IsPopupOpen() const { |
| 116 return is_popup_open_; |
| 117 } |
| 118 |
| 111 void InputMethodIMM32::OnWillChangeFocusedClient( | 119 void InputMethodIMM32::OnWillChangeFocusedClient( |
| 112 TextInputClient* focused_before, | 120 TextInputClient* focused_before, |
| 113 TextInputClient* focused) { | 121 TextInputClient* focused) { |
| 114 ConfirmCompositionText(); | 122 ConfirmCompositionText(); |
| 115 } | 123 } |
| 116 | 124 |
| 117 void InputMethodIMM32::OnDidChangeFocusedClient(TextInputClient* focused_before, | 125 void InputMethodIMM32::OnDidChangeFocusedClient(TextInputClient* focused_before, |
| 118 TextInputClient* focused) { | 126 TextInputClient* focused) { |
| 119 // Force to update the input type since client's TextInputStateChanged() | 127 // Force to update the input type since client's TextInputStateChanged() |
| 120 // function might not be called if text input types before the client loses | 128 // function might not be called if text input types before the client loses |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 | 218 |
| 211 if (GetTextInputClient()->HasCompositionText()) | 219 if (GetTextInputClient()->HasCompositionText()) |
| 212 GetTextInputClient()->ClearCompositionText(); | 220 GetTextInputClient()->ClearCompositionText(); |
| 213 | 221 |
| 214 HWND attached_window = GetAttachedWindowHandle(GetTextInputClient()); | 222 HWND attached_window = GetAttachedWindowHandle(GetTextInputClient()); |
| 215 ime_input_.ResetComposition(attached_window); | 223 ime_input_.ResetComposition(attached_window); |
| 216 ime_input_.DestroyImeWindow(attached_window); | 224 ime_input_.DestroyImeWindow(attached_window); |
| 217 return 0; | 225 return 0; |
| 218 } | 226 } |
| 219 | 227 |
| 228 LRESULT InputMethodIMM32::OnImeNotify(UINT message, |
| 229 WPARAM wparam, |
| 230 LPARAM lparam, |
| 231 BOOL* handled) { |
| 232 *handled = FALSE; |
| 233 |
| 234 // Update |is_popup_open_|, whether a candidate window is open or not. |
| 235 switch (wparam) { |
| 236 case IMN_OPENCANDIDATE: |
| 237 is_popup_open_ = true; |
| 238 break; |
| 239 case IMN_CLOSECANDIDATE: |
| 240 is_popup_open_ = false; |
| 241 break; |
| 242 } |
| 243 |
| 244 return 0; |
| 245 } |
| 246 |
| 220 void InputMethodIMM32::ConfirmCompositionText() { | 247 void InputMethodIMM32::ConfirmCompositionText() { |
| 221 if (!IsTextInputTypeNone()) { | 248 if (!IsTextInputTypeNone()) { |
| 222 HWND attached_window = GetAttachedWindowHandle(GetTextInputClient()); | 249 HWND attached_window = GetAttachedWindowHandle(GetTextInputClient()); |
| 223 | 250 |
| 224 ime_input_.CleanupComposition(attached_window); | 251 ime_input_.CleanupComposition(attached_window); |
| 225 // Though above line should confirm the client's composition text by sending | 252 // Though above line should confirm the client's composition text by sending |
| 226 // a result text to us, in case the input method and the client are in | 253 // a result text to us, in case the input method and the client are in |
| 227 // inconsistent states, we check the client's composition state again. | 254 // inconsistent states, we check the client's composition state again. |
| 228 if (GetTextInputClient()->HasCompositionText()) | 255 if (GetTextInputClient()->HasCompositionText()) |
| 229 GetTextInputClient()->ConfirmCompositionText(); | 256 GetTextInputClient()->ConfirmCompositionText(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 240 enabled_ = false; | 267 enabled_ = false; |
| 241 break; | 268 break; |
| 242 default: | 269 default: |
| 243 ime_input_.EnableIME(GetAttachedWindowHandle(GetTextInputClient())); | 270 ime_input_.EnableIME(GetAttachedWindowHandle(GetTextInputClient())); |
| 244 enabled_ = true; | 271 enabled_ = true; |
| 245 break; | 272 break; |
| 246 } | 273 } |
| 247 } | 274 } |
| 248 | 275 |
| 249 } // namespace ui | 276 } // namespace ui |
| OLD | NEW |