| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_win.h" | 5 #include "ui/base/ime/input_method_win.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/profiler/scoped_tracker.h" | 8 #include "base/profiler/scoped_tracker.h" |
| 9 #include "ui/base/ime/text_input_client.h" | 9 #include "ui/base/ime/text_input_client.h" |
| 10 #include "ui/base/ime/win/tsf_input_scope.h" | 10 #include "ui/base/ime/win/tsf_input_scope.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 // is returned to IME for improving conversion accuracy. | 22 // is returned to IME for improving conversion accuracy. |
| 23 static const size_t kExtraNumberOfChars = 20; | 23 static const size_t kExtraNumberOfChars = 20; |
| 24 | 24 |
| 25 } // namespace | 25 } // namespace |
| 26 | 26 |
| 27 InputMethodWin::InputMethodWin(internal::InputMethodDelegate* delegate, | 27 InputMethodWin::InputMethodWin(internal::InputMethodDelegate* delegate, |
| 28 HWND toplevel_window_handle) | 28 HWND toplevel_window_handle) |
| 29 : toplevel_window_handle_(toplevel_window_handle), | 29 : toplevel_window_handle_(toplevel_window_handle), |
| 30 pending_requested_direction_(base::i18n::UNKNOWN_DIRECTION), | 30 pending_requested_direction_(base::i18n::UNKNOWN_DIRECTION), |
| 31 accept_carriage_return_(false), | 31 accept_carriage_return_(false), |
| 32 active_(false), | |
| 33 enabled_(false), | 32 enabled_(false), |
| 34 is_candidate_popup_open_(false), | 33 is_candidate_popup_open_(false), |
| 35 composing_window_handle_(NULL), | 34 composing_window_handle_(NULL), |
| 36 default_input_language_initialized_(false), | |
| 37 suppress_next_char_(false) { | 35 suppress_next_char_(false) { |
| 38 SetDelegate(delegate); | 36 SetDelegate(delegate); |
| 37 OnInputLocaleChanged(); |
| 39 } | 38 } |
| 40 | 39 |
| 41 void InputMethodWin::OnFocus() { | 40 void InputMethodWin::OnFocus() { |
| 42 InputMethodBase::OnFocus(); | 41 InputMethodBase::OnFocus(); |
| 43 if (GetTextInputClient()) | 42 if (GetTextInputClient()) |
| 44 UpdateIMEState(); | 43 UpdateIMEState(); |
| 45 } | 44 } |
| 46 | 45 |
| 47 void InputMethodWin::OnBlur() { | 46 void InputMethodWin::OnBlur() { |
| 48 ConfirmCompositionText(); | 47 ConfirmCompositionText(); |
| 49 // Gets the focused text input client before calling parent's OnBlur() because | 48 // Gets the focused text input client before calling parent's OnBlur() because |
| 50 // it will cause GetTextInputClient() returns NULL. | 49 // it will cause GetTextInputClient() returns NULL. |
| 51 ui::TextInputClient* client = GetTextInputClient(); | 50 ui::TextInputClient* client = GetTextInputClient(); |
| 52 InputMethodBase::OnBlur(); | 51 InputMethodBase::OnBlur(); |
| 53 if (client) | 52 if (client) |
| 54 UpdateIMEState(); | 53 UpdateIMEState(); |
| 55 } | 54 } |
| 56 | 55 |
| 57 bool InputMethodWin::OnUntranslatedIMEMessage( | 56 bool InputMethodWin::OnUntranslatedIMEMessage( |
| 58 const base::NativeEvent& event, | 57 const base::NativeEvent& event, |
| 59 InputMethod::NativeEventResult* result) { | 58 InputMethod::NativeEventResult* result) { |
| 60 LRESULT original_result = 0; | 59 LRESULT original_result = 0; |
| 61 BOOL handled = FALSE; | 60 BOOL handled = FALSE; |
| 62 | 61 |
| 63 if (!default_input_language_initialized_) { | |
| 64 // Gets the initial input locale. | |
| 65 OnInputLocaleChanged(); | |
| 66 } | |
| 67 | |
| 68 switch (event.message) { | 62 switch (event.message) { |
| 69 case WM_IME_SETCONTEXT: | 63 case WM_IME_SETCONTEXT: |
| 70 original_result = OnImeSetContext( | 64 original_result = OnImeSetContext( |
| 71 event.hwnd, event.message, event.wParam, event.lParam, &handled); | 65 event.hwnd, event.message, event.wParam, event.lParam, &handled); |
| 72 break; | 66 break; |
| 73 case WM_IME_STARTCOMPOSITION: | 67 case WM_IME_STARTCOMPOSITION: |
| 74 original_result = OnImeStartComposition( | 68 original_result = OnImeStartComposition( |
| 75 event.hwnd, event.message, event.wParam, event.lParam, &handled); | 69 event.hwnd, event.message, event.wParam, event.lParam, &handled); |
| 76 break; | 70 break; |
| 77 case WM_IME_COMPOSITION: | 71 case WM_IME_COMPOSITION: |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 screen_bounds.size()); | 166 screen_bounds.size()); |
| 173 imm32_manager_.UpdateCaretRect(attached_window, caret_rect); | 167 imm32_manager_.UpdateCaretRect(attached_window, caret_rect); |
| 174 } | 168 } |
| 175 | 169 |
| 176 void InputMethodWin::CancelComposition(const TextInputClient* client) { | 170 void InputMethodWin::CancelComposition(const TextInputClient* client) { |
| 177 if (enabled_ && IsTextInputClientFocused(client)) | 171 if (enabled_ && IsTextInputClientFocused(client)) |
| 178 imm32_manager_.CancelIME(toplevel_window_handle_); | 172 imm32_manager_.CancelIME(toplevel_window_handle_); |
| 179 } | 173 } |
| 180 | 174 |
| 181 void InputMethodWin::OnInputLocaleChanged() { | 175 void InputMethodWin::OnInputLocaleChanged() { |
| 182 default_input_language_initialized_ = true; | |
| 183 active_ = imm32_manager_.SetInputLanguage(); | |
| 184 locale_ = imm32_manager_.GetInputLanguageName(); | 176 locale_ = imm32_manager_.GetInputLanguageName(); |
| 185 OnInputMethodChanged(); | 177 OnInputMethodChanged(); |
| 186 } | 178 } |
| 187 | 179 |
| 188 std::string InputMethodWin::GetInputLocale() { | 180 std::string InputMethodWin::GetInputLocale() { |
| 189 return locale_; | 181 return locale_; |
| 190 } | 182 } |
| 191 | 183 |
| 192 bool InputMethodWin::IsActive() { | |
| 193 return active_; | |
| 194 } | |
| 195 | |
| 196 bool InputMethodWin::IsCandidatePopupOpen() const { | 184 bool InputMethodWin::IsCandidatePopupOpen() const { |
| 197 return is_candidate_popup_open_; | 185 return is_candidate_popup_open_; |
| 198 } | 186 } |
| 199 | 187 |
| 200 void InputMethodWin::OnWillChangeFocusedClient(TextInputClient* focused_before, | 188 void InputMethodWin::OnWillChangeFocusedClient(TextInputClient* focused_before, |
| 201 TextInputClient* focused) { | 189 TextInputClient* focused) { |
| 202 if (IsWindowFocused(focused_before)) | 190 if (IsWindowFocused(focused_before)) |
| 203 ConfirmCompositionText(); | 191 ConfirmCompositionText(); |
| 204 } | 192 } |
| 205 | 193 |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 enabled_ = true; | 616 enabled_ = true; |
| 629 break; | 617 break; |
| 630 } | 618 } |
| 631 | 619 |
| 632 imm32_manager_.SetTextInputMode(window_handle, text_input_mode); | 620 imm32_manager_.SetTextInputMode(window_handle, text_input_mode); |
| 633 tsf_inputscope::SetInputScopeForTsfUnawareWindow( | 621 tsf_inputscope::SetInputScopeForTsfUnawareWindow( |
| 634 window_handle, text_input_type, text_input_mode); | 622 window_handle, text_input_type, text_input_mode); |
| 635 } | 623 } |
| 636 | 624 |
| 637 } // namespace ui | 625 } // namespace ui |
| OLD | NEW |