Index: content/browser/renderer_host/render_widget_host_view_aura.cc |
diff --git a/content/browser/renderer_host/render_widget_host_view_aura.cc b/content/browser/renderer_host/render_widget_host_view_aura.cc |
index c33e325cef30eaab1a331b7c0dcf7f6d7f8f6166..f40f52bea123fd99076a9ee87cc44d79f0d020f9 100644 |
--- a/content/browser/renderer_host/render_widget_host_view_aura.cc |
+++ b/content/browser/renderer_host/render_widget_host_view_aura.cc |
@@ -370,10 +370,6 @@ RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host, |
popup_parent_host_view_(nullptr), |
popup_child_host_view_(nullptr), |
is_loading_(false), |
- text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
- text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), |
- text_input_flags_(0), |
- can_compose_inline_(true), |
has_composition_text_(false), |
accept_return_character_(false), |
begin_frame_source_(nullptr), |
@@ -400,6 +396,12 @@ RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host, |
GetSurfaceIdNamespace(), this); |
} |
+ // We should start observing the TextInputManager for IME-related events as |
+ // well as monitoring its lifetime. |
+ text_input_manager_ = GetTextInputManager(); |
+ if (text_input_manager_) |
+ text_input_manager_->AddObserver(this); |
+ |
bool overscroll_enabled = base::CommandLine::ForCurrentProcess()-> |
GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0"; |
SetOverscrollControllerEnabled(overscroll_enabled); |
@@ -877,25 +879,6 @@ void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) { |
UpdateCursorIfOverSelf(); |
} |
-void RenderWidgetHostViewAura::TextInputStateChanged( |
- const TextInputState& params) { |
- if (text_input_type_ != params.type || |
- text_input_mode_ != params.mode || |
- can_compose_inline_ != params.can_compose_inline || |
- text_input_flags_ != params.flags) { |
- text_input_type_ = params.type; |
- text_input_mode_ = params.mode; |
- can_compose_inline_ = params.can_compose_inline; |
- text_input_flags_ = params.flags; |
- if (GetInputMethod()) |
- GetInputMethod()->OnTextInputTypeChanged(this); |
- } |
- if (params.show_ime_if_needed && params.type != ui::TEXT_INPUT_TYPE_NONE) { |
- if (GetInputMethod()) |
- GetInputMethod()->ShowImeIfNeeded(); |
- } |
-} |
- |
void RenderWidgetHostViewAura::ImeCancelComposition() { |
if (GetInputMethod()) |
GetInputMethod()->CancelComposition(this); |
@@ -1398,7 +1381,8 @@ void RenderWidgetHostViewAura::ClearCompositionText() { |
} |
void RenderWidgetHostViewAura::InsertText(const base::string16& text) { |
- DCHECK(text_input_type_ != ui::TEXT_INPUT_TYPE_NONE); |
+ DCHECK(GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE); |
+ |
// TODO(wjmaclean): can host_ ever be null? |
if (host_) |
host_->ImeConfirmComposition(text, gfx::Range::InvalidRange(), false); |
@@ -1421,19 +1405,27 @@ void RenderWidgetHostViewAura::InsertChar(const ui::KeyEvent& event) { |
} |
ui::TextInputType RenderWidgetHostViewAura::GetTextInputType() const { |
- return text_input_type_; |
+ if (text_input_manager_ && text_input_manager_->GetTextInputState()) |
+ return text_input_manager_->GetTextInputState()->type; |
+ return ui::TEXT_INPUT_TYPE_NONE; |
} |
ui::TextInputMode RenderWidgetHostViewAura::GetTextInputMode() const { |
- return text_input_mode_; |
+ if (text_input_manager_ && text_input_manager_->GetTextInputState()) |
+ return text_input_manager_->GetTextInputState()->mode; |
+ return ui::TEXT_INPUT_MODE_DEFAULT; |
} |
int RenderWidgetHostViewAura::GetTextInputFlags() const { |
- return text_input_flags_; |
+ if (text_input_manager_ && text_input_manager_->GetTextInputState()) |
+ return text_input_manager_->GetTextInputState()->flags; |
+ return 0; |
} |
bool RenderWidgetHostViewAura::CanComposeInline() const { |
- return can_compose_inline_; |
+ if (text_input_manager_ && text_input_manager_->GetTextInputState()) |
+ return text_input_manager_->GetTextInputState()->can_compose_inline; |
+ return true; |
} |
gfx::Rect RenderWidgetHostViewAura::ConvertRectToScreen( |
@@ -2287,6 +2279,9 @@ RenderWidgetHostViewAura::~RenderWidgetHostViewAura() { |
// be set to NULL. |
DCHECK(!legacy_render_widget_host_HWND_); |
#endif |
+ |
+ if (text_input_manager_) |
+ text_input_manager_->RemoveObserver(this); |
} |
void RenderWidgetHostViewAura::CreateAuraWindow() { |
@@ -2863,6 +2858,35 @@ cc::SurfaceId RenderWidgetHostViewAura::SurfaceIdForTesting() const { |
return delegated_frame_host_->SurfaceIdForTesting(); |
} |
+void RenderWidgetHostViewAura::OnTextInputStateUpdated( |
+ TextInputManager* text_input_manager, |
+ RenderWidgetHostViewBase* updated_view, |
+ bool changed) { |
+ DCHECK(text_input_manager_ == text_input_manager); |
+ if (!GetInputMethod()) |
+ return; |
+ |
+ if (changed) |
+ GetInputMethod()->OnTextInputTypeChanged(this); |
+ |
+ const TextInputState* state = text_input_manager_->GetTextInputState(); |
+ |
+ if (state && state->show_ime_if_needed && |
+ state->type != ui::TEXT_INPUT_TYPE_NONE) |
+ GetInputMethod()->ShowImeIfNeeded(); |
+} |
+ |
+void RenderWidgetHostViewAura::OnTextInputManagerDestroyed( |
Shu Chen
2016/05/13 07:20:41
nit: maybe clearer to rename this as OnDestroyingT
EhsanK
2016/05/13 16:00:56
Acknowledged.
|
+ TextInputManager* text_input_manager) { |
+ DCHECK(text_input_manager && text_input_manager_ == text_input_manager); |
+ |
+ if (text_input_manager_->IsRegisteredView(this)) |
+ text_input_manager_->Unregister(this); |
+ |
+ text_input_manager_->RemoveObserver(this); |
+ |
+ text_input_manager_ = nullptr; |
+} |
//////////////////////////////////////////////////////////////////////////////// |
// RenderWidgetHostViewBase, public: |