Chromium Code Reviews| Index: ui/views/focus/focus_manager.cc |
| diff --git a/ui/views/focus/focus_manager.cc b/ui/views/focus/focus_manager.cc |
| index aba46e079ca754d507900c818265490b2713e6bc..b4bbd17cba9081be0fea01481b4bb9e41b0d2bdc 100644 |
| --- a/ui/views/focus/focus_manager.cc |
| +++ b/ui/views/focus/focus_manager.cc |
| @@ -11,6 +11,10 @@ |
| #include "base/logging.h" |
| #include "build/build_config.h" |
| #include "ui/base/accelerators/accelerator.h" |
| +#include "ui/base/ime/input_method.h" |
| +#include "ui/base/ime/text_input_client.h" |
| +#include "ui/base/ime/text_input_focus_manager.h" |
| +#include "ui/base/ui_base_switches_util.h" |
| #include "ui/events/event.h" |
| #include "ui/events/keycodes/keyboard_codes.h" |
| #include "ui/views/focus/focus_manager_delegate.h" |
| @@ -321,14 +325,18 @@ void FocusManager::SetFocusedViewWithReason( |
| View* old_focused_view = focused_view_; |
| focused_view_ = view; |
| - if (old_focused_view) |
| + if (old_focused_view) { |
| old_focused_view->Blur(); |
| + BlurTextInputClient(old_focused_view); |
| + } |
| // Also make |focused_view_| the stored focus view. This way the stored focus |
| // view is remembered if focus changes are requested prior to a show or while |
| // hidden. |
| SetStoredFocusView(focused_view_); |
| - if (focused_view_) |
| + if (focused_view_) { |
| + FocusTextInputClient(focused_view_); |
| focused_view_->Focus(); |
| + } |
| FOR_EACH_OBSERVER(FocusChangeListener, focus_change_listeners_, |
| OnDidChangeFocus(old_focused_view, focused_view_)); |
| @@ -427,6 +435,46 @@ void FocusManager::ClearStoredFocusedView() { |
| SetStoredFocusView(NULL); |
| } |
| +void FocusManager::OnTextInputClientChanged(View* view) { |
|
sky
2014/04/24 16:05:05
Wouldn't all of these functions fit better on view
Yuki
2014/04/25 15:05:48
No, I don't think so.
I expect these functions to
sky
2014/04/25 18:20:21
I didn't realize FocusManager needs to use these f
|
| + if (view == focused_view_) |
| + FocusTextInputClient(view); |
| +} |
| + |
| +void FocusManager::FocusTextInputClient(View* view) { |
| + if (!switches::IsTextInputFocusManagerEnabled()) |
| + return; |
| + |
| + // If the widget is not active, do not steal the text input focus. |
| + if (!widget_->IsActive()) |
| + return; |
| + |
| + ui::TextInputClient* text_input_client = |
| + view ? view->GetTextInputClient() : NULL; |
| + ui::TextInputFocusManager::GetInstance()-> |
| + FocusTextInputClient(text_input_client); |
| + ui::InputMethod* input_method = widget_->GetHostInputMethod(); |
| + if (input_method) { |
| + input_method->OnTextInputTypeChanged(text_input_client); |
| + input_method->OnCaretBoundsChanged(text_input_client); |
| + } |
| +} |
| + |
| +void FocusManager::BlurTextInputClient(View* view) { |
| + if (!switches::IsTextInputFocusManagerEnabled()) |
| + return; |
| + |
| + ui::TextInputClient* text_input_client = |
| + view ? view->GetTextInputClient() : NULL; |
| + if (text_input_client && text_input_client->HasCompositionText()) { |
| + text_input_client->ConfirmCompositionText(); |
| + ui::InputMethod* input_method = widget_->GetHostInputMethod(); |
| + if (input_method && input_method->GetTextInputClient() == text_input_client) |
| + input_method->CancelComposition(text_input_client); |
| + } |
| + ui::TextInputFocusManager::GetInstance()-> |
| + BlurTextInputClient(text_input_client); |
| +} |
| + |
| // Find the next (previous if reverse is true) focusable view for the specified |
| // FocusTraversable, starting at the specified view, traversing down the |
| // FocusTraversable hierarchy. |