summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--views/widget/native_widget_gtk.cc10
-rw-r--r--views/widget/widget.cc12
-rw-r--r--views/widget/widget_unittest.cc28
3 files changed, 43 insertions, 7 deletions
diff --git a/views/widget/native_widget_gtk.cc b/views/widget/native_widget_gtk.cc
index 8081a31..b2a4342 100644
--- a/views/widget/native_widget_gtk.cc
+++ b/views/widget/native_widget_gtk.cc
@@ -966,12 +966,16 @@ InputMethod* NativeWidgetGtk::CreateInputMethod() {
// RenderWidgetHostViewViews in normal ChromeOS.
if (views::Widget::IsPureViews()) {
#if defined(HAVE_IBUS)
- return InputMethodIBus::IsInputMethodIBusEnabled() ?
+ InputMethod* input_method =
+ InputMethodIBus::IsInputMethodIBusEnabled() ?
static_cast<InputMethod*>(new InputMethodIBus(this)) :
static_cast<InputMethod*>(new InputMethodGtk(this));
#else
- return new InputMethodGtk(this);
+ InputMethod* input_method = new InputMethodGtk(this);
#endif
+ if (has_focus_)
+ input_method->OnFocus();
+ return input_method;
}
// GTK's textfield handles IME.
return NULL;
@@ -1658,7 +1662,7 @@ gboolean NativeWidgetGtk::OnFocusOut(GtkWidget* widget, GdkEventFocus* event) {
return false; // This is the second focus-out event in a row, ignore it.
has_focus_ = false;
- if (GetWidget()->is_top_level())
+ if (!GetWidget()->is_top_level())
return false;
// Only top-level Widget should have an InputMethod instance.
diff --git a/views/widget/widget.cc b/views/widget/widget.cc
index 07a6687..45423c6 100644
--- a/views/widget/widget.cc
+++ b/views/widget/widget.cc
@@ -596,8 +596,14 @@ FocusManager* Widget::GetFocusManager() {
}
InputMethod* Widget::GetInputMethod() {
- Widget* toplevel_widget = GetTopLevelWidget();
- return toplevel_widget ? toplevel_widget->GetInputMethodDirect() : NULL;
+ if (is_top_level()) {
+ if (!input_method_.get())
+ ReplaceInputMethod(native_widget_->CreateInputMethod());
+ return input_method_.get();
+ } else {
+ Widget* toplevel = GetTopLevelWidget();
+ return toplevel ? toplevel->GetInputMethod() : NULL;
+ }
}
void Widget::RunShellDrag(View* view, const ui::OSExchangeData& data,
@@ -976,8 +982,6 @@ bool Widget::ExecuteCommand(int command_id) {
}
InputMethod* Widget::GetInputMethodDirect() {
- if (!input_method_.get() && is_top_level())
- ReplaceInputMethod(native_widget_->CreateInputMethod());
return input_method_.get();
}
diff --git a/views/widget/widget_unittest.cc b/views/widget/widget_unittest.cc
index 3833975..c9bfbee 100644
--- a/views/widget/widget_unittest.cc
+++ b/views/widget/widget_unittest.cc
@@ -271,6 +271,34 @@ TEST_F(WidgetTest, GrabUngrab) {
toplevel->CloseNow();
}
+// Test if a focus manager and an inputmethod work without CHECK failure
+// when window activation changes.
+TEST_F(WidgetTest, ChangeActivation) {
+ Widget* top1 = CreateTopLevelPlatformWidget();
+ // CreateInputMethod before activated
+ top1->GetInputMethod();
+ top1->Show();
+ RunPendingMessages();
+
+ Widget* top2 = CreateTopLevelPlatformWidget();
+ top2->Show();
+ RunPendingMessages();
+
+ top1->Activate();
+ RunPendingMessages();
+
+ // Create InputMethod after deactivated.
+ top2->GetInputMethod();
+ top2->Activate();
+ RunPendingMessages();
+
+ top1->Activate();
+ RunPendingMessages();
+
+ top1->CloseNow();
+ top2->CloseNow();
+}
+
////////////////////////////////////////////////////////////////////////////////
// Widget ownership tests.
//