diff options
-rw-r--r-- | ash/wm/window_manager_unittest.cc | 38 | ||||
-rw-r--r-- | ui/views/corewm/focus_controller.cc | 6 | ||||
-rw-r--r-- | ui/views/corewm/focus_controller_unittest.cc | 19 |
3 files changed, 58 insertions, 5 deletions
diff --git a/ash/wm/window_manager_unittest.cc b/ash/wm/window_manager_unittest.cc index 2fd6e67..e12c9db 100644 --- a/ash/wm/window_manager_unittest.cc +++ b/ash/wm/window_manager_unittest.cc @@ -347,6 +347,44 @@ TEST_F(WindowManagerTest, ActivateOnMouse) { } } +TEST_F(WindowManagerTest, PanelActivation) { + aura::test::TestWindowDelegate wd; + scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( + &wd, -1, gfx::Rect(10, 10, 50, 50))); + aura::test::TestWindowDelegate pd; + scoped_ptr<aura::Window> p1(CreateTestWindowInShellWithDelegateAndType( + &pd, aura::client::WINDOW_TYPE_PANEL, -1, gfx::Rect(10, 10, 50, 50))); + aura::client::FocusClient* focus_client = + aura::client::GetFocusClient(w1.get()); + + // Activate w1. + wm::ActivateWindow(w1.get()); + EXPECT_TRUE(wm::IsActiveWindow(w1.get())); + + // Activate p1. + wm::ActivateWindow(p1.get()); + EXPECT_TRUE(wm::IsActiveWindow(p1.get())); + EXPECT_EQ(p1.get(), focus_client->GetFocusedWindow()); + + // Activate w1. + wm::ActivateWindow(w1.get()); + EXPECT_TRUE(wm::IsActiveWindow(w1.get())); + EXPECT_EQ(w1.get(), focus_client->GetFocusedWindow()); + + // Clicking on a non-activatable window should not change the active window. + { + NonFocusableDelegate nfd; + scoped_ptr<aura::Window> w3(CreateTestWindowInShellWithDelegate( + &nfd, -1, gfx::Rect(70, 70, 50, 50))); + aura::test::EventGenerator generator3(Shell::GetPrimaryRootWindow(), + w3.get()); + wm::ActivateWindow(p1.get()); + EXPECT_TRUE(wm::IsActiveWindow(p1.get())); + generator3.ClickLeftButton(); + EXPECT_TRUE(wm::IsActiveWindow(p1.get())); + } +} + // Essentially the same as ActivateOnMouse, but for touch events. TEST_F(WindowManagerTest, ActivateOnTouch) { aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); diff --git a/ui/views/corewm/focus_controller.cc b/ui/views/corewm/focus_controller.cc index 1daba43..eaab151 100644 --- a/ui/views/corewm/focus_controller.cc +++ b/ui/views/corewm/focus_controller.cc @@ -336,7 +336,11 @@ void FocusController::WindowLostFocusFromDispositionChange( } void FocusController::WindowFocusedFromInputEvent(aura::Window* window) { - FocusWindow(window); + // Only focus |window| if it or any of its parents can be focused. Otherwise + // FocusWindow() will focus the topmost window, which may not be the + // currently focused one. + if (rules_->CanFocusWindow(GetToplevelWindow(window))) + FocusWindow(window); } } // namespace corewm diff --git a/ui/views/corewm/focus_controller_unittest.cc b/ui/views/corewm/focus_controller_unittest.cc index 6eaf81d..335bb6c 100644 --- a/ui/views/corewm/focus_controller_unittest.cc +++ b/ui/views/corewm/focus_controller_unittest.cc @@ -298,6 +298,9 @@ class FocusControllerDirectTestBase : public FocusControllerTestBase { virtual void ActivateWindowDirect(aura::Window* window) = 0; virtual void DeactivateWindowDirect(aura::Window* window) = 0; + // Input events do not change focus if the window can not be focused. + virtual bool IsInputEvent() = 0; + void FocusWindowById(int id) { aura::Window* window = root_window()->GetChildById(id); DCHECK(window); @@ -436,7 +439,10 @@ class FocusControllerDirectTestBase : public FocusControllerTestBase { test_focus_rules()->set_focus_restriction(root_window()->GetChildById(211)); FocusWindowById(12); - EXPECT_EQ(211, GetFocusedWindowId()); + // Input events leave focus unchanged; direct API calls will change focus + // to the restricted window. + int focused_window = IsInputEvent() ? 11 : 211; + EXPECT_EQ(focused_window, GetFocusedWindowId()); test_focus_rules()->set_focus_restriction(NULL); FocusWindowById(12); @@ -451,9 +457,11 @@ class FocusControllerDirectTestBase : public FocusControllerTestBase { test_focus_rules()->set_focus_restriction(w3); ActivateWindowById(2); - // FocusRules restricts focus and activation to 3. - EXPECT_EQ(3, GetActiveWindowId()); - EXPECT_EQ(3, GetFocusedWindowId()); + // Input events leave activation unchanged; direct API calls will activate + // the restricted window. + int active_window = IsInputEvent() ? 1 : 3; + EXPECT_EQ(active_window, GetActiveWindowId()); + EXPECT_EQ(active_window, GetFocusedWindowId()); test_focus_rules()->set_focus_restriction(NULL); ActivateWindowById(2); @@ -573,6 +581,7 @@ class FocusControllerApiTest : public FocusControllerDirectTestBase { virtual void DeactivateWindowDirect(aura::Window* window) OVERRIDE { DeactivateWindow(window); } + virtual bool IsInputEvent() OVERRIDE { return false; } DISALLOW_COPY_AND_ASSIGN(FocusControllerApiTest); }; @@ -598,6 +607,7 @@ class FocusControllerMouseEventTest : public FocusControllerDirectTestBase { aura::test::EventGenerator generator(root_window(), next_activatable); generator.ClickLeftButton(); } + virtual bool IsInputEvent() OVERRIDE { return true; } DISALLOW_COPY_AND_ASSIGN(FocusControllerMouseEventTest); }; @@ -622,6 +632,7 @@ class FocusControllerGestureEventTest : public FocusControllerDirectTestBase { aura::test::EventGenerator generator(root_window(), next_activatable); generator.GestureTapAt(window->bounds().CenterPoint()); } + virtual bool IsInputEvent() OVERRIDE { return true; } DISALLOW_COPY_AND_ASSIGN(FocusControllerGestureEventTest); }; |