diff options
author | oshima@google.com <oshima@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-24 21:39:02 +0000 |
---|---|---|
committer | oshima@google.com <oshima@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-24 21:39:02 +0000 |
commit | f0f1db697fe2ff3501611c6a024eaa8d619767ac (patch) | |
tree | a5581a395c888e7272e03c165ef3dfdc1c7b14b2 /views | |
parent | 6acbd8dd984f3d4427f46d138464a21760676c7b (diff) | |
download | chromium_src-f0f1db697fe2ff3501611c6a024eaa8d619767ac.zip chromium_src-f0f1db697fe2ff3501611c6a024eaa8d619767ac.tar.gz chromium_src-f0f1db697fe2ff3501611c6a024eaa8d619767ac.tar.bz2 |
* Fix wrong condition check in OnFocusOut.
* Create inputmethod only when it's requested via Widget::GetInputMethod. This is what original code did.
BUG=none
TEST=added WidgetTest::ChangeActivation
Review URL: http://codereview.chromium.org/7729007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98118 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/widget/native_widget_gtk.cc | 10 | ||||
-rw-r--r-- | views/widget/widget.cc | 12 | ||||
-rw-r--r-- | views/widget/widget_unittest.cc | 28 |
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. // |