summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbeng@google.com <beng@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-15 16:48:14 +0000
committerbeng@google.com <beng@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-15 16:48:14 +0000
commit3c8cd81992440ed81a862ac7b18c2fe4f6180a9b (patch)
tree1fc6a23f91c6ad354db00a3e77c9592e6abebd45
parent62da82b0b9555d89b9e63815e658f8f654aadf13 (diff)
downloadchromium_src-3c8cd81992440ed81a862ac7b18c2fe4f6180a9b.zip
chromium_src-3c8cd81992440ed81a862ac7b18c2fe4f6180a9b.tar.gz
chromium_src-3c8cd81992440ed81a862ac7b18c2fe4f6180a9b.tar.bz2
This restores a hack that was in place in the old NativeTabContentsContainer code that seemed to clear focus during restoration (though the hack was for another purpose, the hack seemed to fix this bug too). I've isolated the hack to the re-activation code.
http://crbug.com/125976 TEST=see bug Review URL: https://chromiumcodereview.appspot.com/10378043 Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=137040 Review URL: https://chromiumcodereview.appspot.com/10378043 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137153 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/ui/views/accessibility_event_router_views_unittest.cc21
-rw-r--r--ui/base/test/dummy_input_method.cc70
-rw-r--r--ui/base/test/dummy_input_method.h45
-rw-r--r--ui/ui_unittests.gypi10
-rw-r--r--ui/views/accessible_pane_view_unittest.cc5
-rw-r--r--ui/views/test/views_test_base.cc43
-rw-r--r--ui/views/views.gyp1
-rw-r--r--ui/views/widget/native_widget_win.cc14
8 files changed, 158 insertions, 51 deletions
diff --git a/chrome/browser/ui/views/accessibility_event_router_views_unittest.cc b/chrome/browser/ui/views/accessibility_event_router_views_unittest.cc
index 82ad589..121c652 100644
--- a/chrome/browser/ui/views/accessibility_event_router_views_unittest.cc
+++ b/chrome/browser/ui/views/accessibility_event_router_views_unittest.cc
@@ -25,12 +25,16 @@
#include "ui/views/widget/widget_delegate.h"
#if defined(USE_AURA)
+#include "ui/aura/client/aura_constants.h"
#include "ui/aura/env.h"
#include "ui/aura/monitor_manager.h"
#include "ui/aura/root_window.h"
#include "ui/aura/single_monitor_manager.h"
+#include "ui/aura/test/test_activation_client.h"
#include "ui/aura/test/test_screen.h"
#include "ui/aura/test/test_stacking_client.h"
+#include "ui/base/ime/input_method.h"
+#include "ui/base/test/dummy_input_method.h"
#include "ui/gfx/screen.h"
#endif
@@ -139,15 +143,23 @@ class AccessibilityEventRouterViewsTest
: public testing::Test,
public content::NotificationObserver {
public:
+ AccessibilityEventRouterViewsTest() {
+#if defined(USE_AURA)
+ test_input_method_.reset(new ui::test::DummyInputMethod);
+#endif
+ }
+
virtual void SetUp() {
views::ViewsDelegate::views_delegate = new AccessibilityViewsDelegate();
#if defined(USE_AURA)
aura::Env::GetInstance()->SetMonitorManager(new aura::SingleMonitorManager);
root_window_.reset(
aura::MonitorManager::CreateRootWindowForPrimaryMonitor());
-#if defined(USE_AURA)
gfx::Screen::SetInstance(new aura::TestScreen(root_window_.get()));
-#endif // USE_ASH
+ root_window_->SetProperty(aura::client::kRootWindowInputMethodKey,
+ test_input_method_.get());
+ test_activation_client_.reset(
+ new aura::test::TestActivationClient(root_window_.get()));
test_stacking_client_.reset(
new aura::test::TestStackingClient(root_window_.get()));
#endif // USE_AURA
@@ -156,6 +168,7 @@ class AccessibilityEventRouterViewsTest
virtual void TearDown() {
#if defined(USE_AURA)
test_stacking_client_.reset();
+ test_activation_client_.reset();
root_window_.reset();
#endif
delete views::ViewsDelegate::views_delegate;
@@ -193,7 +206,9 @@ class AccessibilityEventRouterViewsTest
std::string last_control_context_;
#if defined(USE_AURA)
scoped_ptr<aura::RootWindow> root_window_;
+ scoped_ptr<aura::test::TestActivationClient> test_activation_client_;
scoped_ptr<aura::test::TestStackingClient> test_stacking_client_;
+ scoped_ptr<ui::InputMethod> test_input_method_;
#endif
};
@@ -217,6 +232,8 @@ TEST_F(AccessibilityEventRouterViewsTest, TestFocusNotification) {
// Put the view in a window.
views::Widget* window = CreateWindowWithContents(contents);
+ window->Show();
+ window->Activate();
// Set focus to the first button initially.
button1->RequestFocus();
diff --git a/ui/base/test/dummy_input_method.cc b/ui/base/test/dummy_input_method.cc
new file mode 100644
index 0000000..34bdc36
--- /dev/null
+++ b/ui/base/test/dummy_input_method.cc
@@ -0,0 +1,70 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/base/test/dummy_input_method.h"
+
+namespace ui {
+namespace test {
+
+DummyInputMethod::DummyInputMethod() {
+}
+
+DummyInputMethod::~DummyInputMethod() {
+}
+
+void DummyInputMethod::SetDelegate(internal::InputMethodDelegate* delegate) {
+}
+
+void DummyInputMethod::Init(bool focused) {
+}
+
+void DummyInputMethod::OnFocus() {
+}
+
+void DummyInputMethod::OnBlur() {
+}
+
+void DummyInputMethod::SetFocusedTextInputClient(TextInputClient* client) {
+}
+
+TextInputClient* DummyInputMethod::GetTextInputClient() const {
+ return NULL;
+}
+
+void DummyInputMethod::DispatchKeyEvent(
+ const base::NativeEvent& native_key_event) {
+}
+
+void DummyInputMethod::OnTextInputTypeChanged(const TextInputClient* client) {
+}
+
+void DummyInputMethod::OnCaretBoundsChanged(const TextInputClient* client) {
+}
+
+void DummyInputMethod::CancelComposition(const TextInputClient* client) {
+}
+
+std::string DummyInputMethod::GetInputLocale() {
+ return "";
+}
+
+base::i18n::TextDirection DummyInputMethod::GetInputTextDirection() {
+ return base::i18n::UNKNOWN_DIRECTION;
+}
+
+bool DummyInputMethod::IsActive() {
+ return true;
+}
+
+TextInputType DummyInputMethod::GetTextInputType() const {
+ return TEXT_INPUT_TYPE_NONE;
+}
+
+bool DummyInputMethod::CanComposeInline() const {
+ return true;
+}
+
+} // namespace test
+} // namespace ui
+
diff --git a/ui/base/test/dummy_input_method.h b/ui/base/test/dummy_input_method.h
new file mode 100644
index 0000000..bb32566
--- /dev/null
+++ b/ui/base/test/dummy_input_method.h
@@ -0,0 +1,45 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef UI_BASE_TEST_DUMMY_INPUT_METHOD_H_
+#define UI_BASE_TEST_DUMMY_INPUT_METHOD_H_
+
+#include "ui/base/ime/input_method.h"
+
+namespace ui {
+namespace test {
+
+class DummyInputMethod : public InputMethod {
+ public:
+ DummyInputMethod();
+ virtual ~DummyInputMethod();
+
+ // InputMethod overrides:
+ virtual void SetDelegate(
+ internal::InputMethodDelegate* delegate) OVERRIDE;
+ virtual void Init(bool focused) OVERRIDE;
+ virtual void OnFocus() OVERRIDE;
+ virtual void OnBlur() OVERRIDE;
+ virtual void SetFocusedTextInputClient(TextInputClient* client) OVERRIDE;
+ virtual TextInputClient* GetTextInputClient() const OVERRIDE;
+ virtual void DispatchKeyEvent(
+ const base::NativeEvent& native_key_event) OVERRIDE;
+ virtual void OnTextInputTypeChanged(const TextInputClient* client) OVERRIDE;
+ virtual void OnCaretBoundsChanged(const TextInputClient* client) OVERRIDE;
+ virtual void CancelComposition(const TextInputClient* client) OVERRIDE;
+ virtual std::string GetInputLocale() OVERRIDE;
+ virtual base::i18n::TextDirection GetInputTextDirection() OVERRIDE;
+ virtual bool IsActive() OVERRIDE;
+ virtual TextInputType GetTextInputType() const OVERRIDE;
+ virtual bool CanComposeInline() const OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(DummyInputMethod);
+};
+
+} // namespace test
+} // namespace ui
+
+#endif // UI_BASE_TEST_DUMMY_INPUT_METHOD_H_
+
diff --git a/ui/ui_unittests.gypi b/ui/ui_unittests.gypi
index 2a0a121..d36c559 100644
--- a/ui/ui_unittests.gypi
+++ b/ui/ui_unittests.gypi
@@ -6,6 +6,7 @@
'targets': [
{
'target_name': 'ui_test_support',
+ 'type': 'static_library',
'dependencies': [
'../base/base.gyp:base',
'../testing/gtest.gyp:gtest',
@@ -15,17 +16,12 @@
'base/test/cocoa_test_event_utils.mm',
'base/test/ui_cocoa_test_helper.h',
'base/test/ui_cocoa_test_helper.mm',
+ 'base/test/dummy_input_method.cc',
+ 'base/test/dummy_input_method.h',
],
'include_dirs': [
'../',
],
- 'conditions': [
- ['OS=="mac"', {
- 'type': 'static_library',
- }, { # OS != "mac"
- 'type': 'none',
- }],
- ],
},
{
'target_name': 'ui_unittests',
diff --git a/ui/views/accessible_pane_view_unittest.cc b/ui/views/accessible_pane_view_unittest.cc
index 467f143..f7551d6 100644
--- a/ui/views/accessible_pane_view_unittest.cc
+++ b/ui/views/accessible_pane_view_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -84,6 +84,7 @@ TEST_F(AccessiblePaneViewTest, SimpleSetPaneFocus) {
View* root = widget->GetRootView();
root->AddChildView(test_view);
widget->Show();
+ widget->Activate();
// Set pane focus succeeds, focus on child.
EXPECT_TRUE(test_view->SetPaneFocusAndFocusDefault());
@@ -113,6 +114,7 @@ TEST_F(AccessiblePaneViewTest, TwoSetPaneFocus) {
root->AddChildView(test_view);
root->AddChildView(test_view_2);
widget->Show();
+ widget->Activate();
// Set pane focus succeeds, focus on child.
EXPECT_TRUE(test_view->SetPaneFocusAndFocusDefault());
@@ -142,6 +144,7 @@ TEST_F(AccessiblePaneViewTest, PaneFocusTraversal) {
root->AddChildView(original_test_view);
root->AddChildView(test_view);
widget->Show();
+ widget->Activate();
// Set pane focus on first view.
EXPECT_TRUE(original_test_view->SetPaneFocus(
diff --git a/ui/views/test/views_test_base.cc b/ui/views/test/views_test_base.cc
index 00a7cb3..4932616 100644
--- a/ui/views/test/views_test_base.cc
+++ b/ui/views/test/views_test_base.cc
@@ -15,47 +15,8 @@
#include "ui/aura/test/test_screen.h"
#include "ui/aura/test/test_stacking_client.h"
#include "ui/base/ime/input_method.h"
+#include "ui/base/test/dummy_input_method.h"
#include "ui/gfx/screen.h"
-
-namespace {
-
-class DummyInputMethod : public ui::InputMethod {
- public:
- DummyInputMethod() {}
- virtual ~DummyInputMethod() {}
-
- // ui::InputMethod overrides:
- virtual void SetDelegate(
- ui::internal::InputMethodDelegate* delegate) OVERRIDE {}
- virtual void Init(bool focused) OVERRIDE {}
- virtual void OnFocus() OVERRIDE {}
- virtual void OnBlur() OVERRIDE {}
- virtual void SetFocusedTextInputClient(
- ui::TextInputClient* client) OVERRIDE {}
- virtual ui::TextInputClient* GetTextInputClient() const OVERRIDE {
- return NULL;
- }
- virtual void DispatchKeyEvent(
- const base::NativeEvent& native_key_event) OVERRIDE {}
- virtual void OnTextInputTypeChanged(
- const ui::TextInputClient* client) OVERRIDE {}
- virtual void OnCaretBoundsChanged(
- const ui::TextInputClient* client) OVERRIDE {}
- virtual void CancelComposition(const ui::TextInputClient* client) OVERRIDE {}
- virtual std::string GetInputLocale() OVERRIDE { return ""; }
- virtual base::i18n::TextDirection GetInputTextDirection() OVERRIDE {
- return base::i18n::UNKNOWN_DIRECTION;
- }
- virtual bool IsActive() OVERRIDE { return true; }
- virtual ui::TextInputType GetTextInputType() const OVERRIDE {
- return ui::TEXT_INPUT_TYPE_NONE;
- }
- virtual bool CanComposeInline() const OVERRIDE {
- return true;
- }
-};
-
-} // namespace
#endif
namespace views {
@@ -64,7 +25,7 @@ ViewsTestBase::ViewsTestBase()
: setup_called_(false),
teardown_called_(false) {
#if defined(USE_AURA)
- test_input_method_.reset(new DummyInputMethod);
+ test_input_method_.reset(new ui::test::DummyInputMethod);
#endif
}
diff --git a/ui/views/views.gyp b/ui/views/views.gyp
index 60e0a61..a25a265 100644
--- a/ui/views/views.gyp
+++ b/ui/views/views.gyp
@@ -499,6 +499,7 @@
'../ui.gyp:ui',
'../ui.gyp:ui_resources',
'../ui.gyp:ui_resources_standard',
+ '../ui.gyp:ui_test_support',
'test_support_views',
'views',
],
diff --git a/ui/views/widget/native_widget_win.cc b/ui/views/widget/native_widget_win.cc
index bb4e1f33..fe4c6b1 100644
--- a/ui/views/widget/native_widget_win.cc
+++ b/ui/views/widget/native_widget_win.cc
@@ -38,6 +38,7 @@
#include "ui/views/drag_utils.h"
#include "ui/views/focus/accelerator_handler.h"
#include "ui/views/focus/view_storage.h"
+#include "ui/views/focus/widget_focus_manager.h"
#include "ui/views/ime/input_method_win.h"
#include "ui/views/views_delegate.h"
#include "ui/views/widget/aero_tooltip_manager.h"
@@ -1332,6 +1333,7 @@ LRESULT NativeWidgetWin::OnCreate(CREATESTRUCT* create_struct) {
// Get access to a modifiable copy of the system menu.
GetSystemMenu(hwnd(), false);
+
return 0;
}
@@ -2255,6 +2257,18 @@ void NativeWidgetWin::PostProcessActivateMessage(NativeWidgetWin* widget,
widget->restore_focus_when_enabled_ = true;
return;
}
+
+ // Mysteriously, this only appears to be needed support restoration of focus
+ // to a child hwnd when restoring its top level window from the minimized
+ // state. If we don't do this, then ::SetFocus() to that child HWND returns
+ // ERROR_INVALID_PARAMETER, despite both HWNDs being of the same thread.
+ // See http://crbug.com/125976
+ {
+ // Since this is a synthetic reset, we don't need to tell anyone about it.
+ AutoNativeNotificationDisabler disabler;
+ focus_manager->ClearFocus();
+ }
+
focus_manager->RestoreFocusedView();
}
}