Chromium Code Reviews| 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_tsf.h" | 5 #include "ui/base/ime/input_method_tsf.h" |
| 6 | 6 |
| 7 #include "ui/base/ime/text_input_client.h" | 7 #include "ui/base/ime/text_input_client.h" |
| 8 #include "ui/base/ime/win/tsf_bridge.h" | 8 #include "ui/base/ime/win/tsf_bridge.h" |
| 9 | 9 |
| 10 namespace ui { | 10 namespace ui { |
| 11 | 11 |
| 12 InputMethodTSF::InputMethodTSF(internal::InputMethodDelegate* delegate, | 12 InputMethodTSF::InputMethodTSF(internal::InputMethodDelegate* delegate, |
| 13 HWND toplevel_window_handle) | 13 HWND toplevel_window_handle) |
| 14 : InputMethodWin(delegate, toplevel_window_handle) { | 14 : InputMethodWin(delegate, toplevel_window_handle), |
| 15 is_candidate_popup_open_(false) { | |
| 15 // In non-Aura environment, appropriate callbacks to OnFocus() and OnBlur() | 16 // In non-Aura environment, appropriate callbacks to OnFocus() and OnBlur() |
| 16 // are not implemented yet. To work around this limitation, here we use | 17 // are not implemented yet. To work around this limitation, here we use |
| 17 // "always focused" model. | 18 // "always focused" model. |
| 18 // TODO(ime): Fix the caller of OnFocus() and OnBlur() so that appropriate | 19 // TODO(ime): Fix the caller of OnFocus() and OnBlur() so that appropriate |
| 19 // focus event will be passed. | 20 // focus event will be passed. |
| 20 InputMethodWin::OnFocus(); | 21 InputMethodWin::OnFocus(); |
| 21 } | 22 } |
| 22 | 23 |
| 23 void InputMethodTSF::OnFocus() { | 24 void InputMethodTSF::OnFocus() { |
| 24 // Ignore OnFocus event for "always focused" model. See the comment in the | 25 // Ignore OnFocus event for "always focused" model. See the comment in the |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 54 // - Another application sends WM_CHAR through SendMessage API. | 55 // - Another application sends WM_CHAR through SendMessage API. |
| 55 original_result = OnChar( | 56 original_result = OnChar( |
| 56 event.message, event.wParam, event.lParam, &handled); | 57 event.message, event.wParam, event.lParam, &handled); |
| 57 break; | 58 break; |
| 58 case WM_DEADCHAR: | 59 case WM_DEADCHAR: |
| 59 case WM_SYSDEADCHAR: | 60 case WM_SYSDEADCHAR: |
| 60 // See the comment in WM_CHAR/WM_SYSCHAR. | 61 // See the comment in WM_CHAR/WM_SYSCHAR. |
| 61 original_result = OnDeadChar( | 62 original_result = OnDeadChar( |
| 62 event.message, event.wParam, event.lParam, &handled); | 63 event.message, event.wParam, event.lParam, &handled); |
| 63 break; | 64 break; |
| 65 case WM_IME_NOTIFY: | |
|
Yohei Yukawa
2013/06/21 06:45:47
Wait.
Please do not handle WM_IME_NOTIFY when TSF
| |
| 66 original_result = OnImeNotify( | |
| 67 event.message, event.wParam, event.lParam, &handled); | |
| 68 break; | |
| 64 } | 69 } |
| 65 if (result) | 70 if (result) |
| 66 *result = original_result; | 71 *result = original_result; |
| 67 return !!handled; | 72 return !!handled; |
| 68 } | 73 } |
| 69 | 74 |
| 70 void InputMethodTSF::OnTextInputTypeChanged(const TextInputClient* client) { | 75 void InputMethodTSF::OnTextInputTypeChanged(const TextInputClient* client) { |
| 71 if (IsTextInputClientFocused(client) && IsWindowFocused(client)) { | 76 if (IsTextInputClientFocused(client) && IsWindowFocused(client)) { |
| 72 ui::TSFBridge::GetInstance()->CancelComposition(); | 77 ui::TSFBridge::GetInstance()->CancelComposition(); |
| 73 ui::TSFBridge::GetInstance()->OnTextInputTypeChanged(client); | 78 ui::TSFBridge::GetInstance()->OnTextInputTypeChanged(client); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 86 } | 91 } |
| 87 | 92 |
| 88 void InputMethodTSF::SetFocusedTextInputClient(TextInputClient* client) { | 93 void InputMethodTSF::SetFocusedTextInputClient(TextInputClient* client) { |
| 89 if (IsWindowFocused(client)) { | 94 if (IsWindowFocused(client)) { |
| 90 ui::TSFBridge::GetInstance()->SetFocusedClient( | 95 ui::TSFBridge::GetInstance()->SetFocusedClient( |
| 91 GetAttachedWindowHandle(client), client); | 96 GetAttachedWindowHandle(client), client); |
| 92 } | 97 } |
| 93 InputMethodWin::SetFocusedTextInputClient(client); | 98 InputMethodWin::SetFocusedTextInputClient(client); |
| 94 } | 99 } |
| 95 | 100 |
| 101 bool InputMethodTSF::IsCandidatePopupOpen() const { | |
| 102 return is_candidate_popup_open_; | |
| 103 } | |
| 104 | |
| 96 void InputMethodTSF::OnWillChangeFocusedClient(TextInputClient* focused_before, | 105 void InputMethodTSF::OnWillChangeFocusedClient(TextInputClient* focused_before, |
| 97 TextInputClient* focused) { | 106 TextInputClient* focused) { |
| 98 if (IsWindowFocused(focused_before)) { | 107 if (IsWindowFocused(focused_before)) { |
| 99 ConfirmCompositionText(); | 108 ConfirmCompositionText(); |
| 100 ui::TSFBridge::GetInstance()->RemoveFocusedClient(focused_before); | 109 ui::TSFBridge::GetInstance()->RemoveFocusedClient(focused_before); |
| 101 } | 110 } |
| 102 } | 111 } |
| 103 | 112 |
| 104 void InputMethodTSF::OnDidChangeFocusedClient(TextInputClient* focused_before, | 113 void InputMethodTSF::OnDidChangeFocusedClient(TextInputClient* focused_before, |
| 105 TextInputClient* focused) { | 114 TextInputClient* focused) { |
| 106 if (IsWindowFocused(focused)) { | 115 if (IsWindowFocused(focused)) { |
| 107 ui::TSFBridge::GetInstance()->SetFocusedClient( | 116 ui::TSFBridge::GetInstance()->SetFocusedClient( |
| 108 GetAttachedWindowHandle(focused), focused); | 117 GetAttachedWindowHandle(focused), focused); |
| 109 // Force to update the input type since client's TextInputStateChanged() | 118 // Force to update the input type since client's TextInputStateChanged() |
| 110 // function might not be called if text input types before the client loses | 119 // function might not be called if text input types before the client loses |
| 111 // focus and after it acquires focus again are the same. | 120 // focus and after it acquires focus again are the same. |
| 112 OnTextInputTypeChanged(focused); | 121 OnTextInputTypeChanged(focused); |
| 113 | 122 |
| 114 // Force to update caret bounds, in case the client thinks that the caret | 123 // Force to update caret bounds, in case the client thinks that the caret |
| 115 // bounds has not changed. | 124 // bounds has not changed. |
| 116 OnCaretBoundsChanged(focused); | 125 OnCaretBoundsChanged(focused); |
| 117 } | 126 } |
| 118 } | 127 } |
| 119 | 128 |
| 129 LRESULT InputMethodTSF::OnImeNotify(UINT message, | |
| 130 WPARAM wparam, | |
| 131 LPARAM lparam, | |
| 132 BOOL* handled) { | |
| 133 *handled = FALSE; | |
| 134 | |
| 135 // Update |is_candidate_popup_open_|, whether a candidate window is open. | |
| 136 switch (wparam) { | |
| 137 case IMN_OPENCANDIDATE: | |
| 138 is_candidate_popup_open_ = true; | |
| 139 break; | |
| 140 case IMN_CLOSECANDIDATE: | |
| 141 is_candidate_popup_open_ = false; | |
| 142 break; | |
| 143 } | |
| 144 | |
| 145 return 0; | |
| 146 } | |
| 147 | |
| 120 void InputMethodTSF::ConfirmCompositionText() { | 148 void InputMethodTSF::ConfirmCompositionText() { |
| 121 if (!IsTextInputTypeNone()) { | 149 if (!IsTextInputTypeNone()) { |
| 122 // TSFBridge has not implemented ConfirmComposition yet. So here cancel | 150 // TSFBridge has not implemented ConfirmComposition yet. So here cancel |
| 123 // the composition instead as a workaround. | 151 // the composition instead as a workaround. |
| 124 // TODO(ime): Implement ConfirmComposition for TSF. | 152 // TODO(ime): Implement ConfirmComposition for TSF. |
| 125 ui::TSFBridge::GetInstance()->CancelComposition(); | 153 ui::TSFBridge::GetInstance()->CancelComposition(); |
| 126 } | 154 } |
| 127 } | 155 } |
| 128 | 156 |
| 129 bool InputMethodTSF::IsWindowFocused(const TextInputClient* client) const { | 157 bool InputMethodTSF::IsWindowFocused(const TextInputClient* client) const { |
| 130 if (!client) | 158 if (!client) |
| 131 return false; | 159 return false; |
| 132 HWND attached_window_handle = GetAttachedWindowHandle(client); | 160 HWND attached_window_handle = GetAttachedWindowHandle(client); |
| 133 return attached_window_handle && GetFocus() == attached_window_handle; | 161 return attached_window_handle && GetFocus() == attached_window_handle; |
| 134 } | 162 } |
| 135 | 163 |
| 136 } // namespace ui | 164 } // namespace ui |
| OLD | NEW |