summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-23 18:59:34 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-23 18:59:34 +0000
commitcd609cbecfa081ec5aff94eb99022a3433827e1b (patch)
treeadbe85c3357bd7b28b01d0c69a5fbe460ae30ed4 /ash
parent35ed30fa9a773145869b85424077cd01a0d02ed0 (diff)
downloadchromium_src-cd609cbecfa081ec5aff94eb99022a3433827e1b.zip
chromium_src-cd609cbecfa081ec5aff94eb99022a3433827e1b.tar.gz
chromium_src-cd609cbecfa081ec5aff94eb99022a3433827e1b.tar.bz2
ash: Focus a focusable parent window if a window itself cannot be focused on click/touch.
BUG=115428 TEST=aura_shell_unittests:RootWindowEventFilterTest.ActivateOnMouse Review URL: https://chromiumcodereview.appspot.com/9454007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@123287 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r--ash/wm/root_window_event_filter.cc14
-rw-r--r--ash/wm/root_window_event_filter_unittest.cc36
2 files changed, 46 insertions, 4 deletions
diff --git a/ash/wm/root_window_event_filter.cc b/ash/wm/root_window_event_filter.cc
index 9d0d989..ef7b43d 100644
--- a/ash/wm/root_window_event_filter.cc
+++ b/ash/wm/root_window_event_filter.cc
@@ -17,6 +17,8 @@
namespace ash {
namespace internal {
+namespace {
+
// Returns the default cursor for a window component.
gfx::NativeCursor CursorForWindowComponent(int window_component) {
switch (window_component) {
@@ -41,6 +43,14 @@ gfx::NativeCursor CursorForWindowComponent(int window_component) {
}
}
+aura::Window* FindFocusableWindowFor(aura::Window* window) {
+ while (window && !window->CanFocus())
+ window = window->parent();
+ return window;
+}
+
+} // namespace
+
////////////////////////////////////////////////////////////////////////////////
// RootWindowEventFilter, public:
@@ -109,7 +119,7 @@ bool RootWindowEventFilter::PreHandleMouseEvent(aura::Window* target,
return true;
if (event->type() == ui::ET_MOUSE_PRESSED && GetActiveWindow() != target)
- target->GetFocusManager()->SetFocusedWindow(target);
+ target->GetFocusManager()->SetFocusedWindow(FindFocusableWindowFor(target));
return false;
}
@@ -125,7 +135,7 @@ ui::TouchStatus RootWindowEventFilter::PreHandleTouchEvent(
if (update_cursor_visibility_)
SetCursorVisible(target, event, false);
- target->GetFocusManager()->SetFocusedWindow(target);
+ target->GetFocusManager()->SetFocusedWindow(FindFocusableWindowFor(target));
}
return ui::TOUCH_STATUS_UNKNOWN;
}
diff --git a/ash/wm/root_window_event_filter_unittest.cc b/ash/wm/root_window_event_filter_unittest.cc
index 5107360..f557119 100644
--- a/ash/wm/root_window_event_filter_unittest.cc
+++ b/ash/wm/root_window_event_filter_unittest.cc
@@ -46,6 +46,18 @@ class RootWindowEventFilterTest : public aura::test::AuraTestBase {
DISALLOW_COPY_AND_ASSIGN(RootWindowEventFilterTest);
};
+class NonFocusableDelegate : public aura::test::TestWindowDelegate {
+ public:
+ NonFocusableDelegate() {}
+
+ private:
+ virtual bool CanFocus() OVERRIDE {
+ return false;
+ }
+
+ DISALLOW_COPY_AND_ASSIGN(NonFocusableDelegate);
+};
+
class HitTestWindowDelegate : public aura::test::TestWindowDelegate {
public:
HitTestWindowDelegate()
@@ -238,9 +250,9 @@ TEST_F(RootWindowEventFilterTest, ActivateOnMouse) {
// Clicking an active window with a child shouldn't steal the
// focus from the child.
- scoped_ptr<aura::Window> w11(CreateTestWindowWithDelegate(
- &wd, -1, gfx::Rect(10, 10, 10, 10), w1.get()));
{
+ scoped_ptr<aura::Window> w11(CreateTestWindowWithDelegate(
+ &wd, -1, gfx::Rect(10, 10, 10, 10), w1.get()));
aura::test::EventGenerator generator(Shell::GetRootWindow(), w11.get());
// First set the focus to the child |w11|.
generator.ClickLeftButton();
@@ -256,6 +268,26 @@ TEST_F(RootWindowEventFilterTest, ActivateOnMouse) {
EXPECT_EQ(w11.get(), focus_manager->GetFocusedWindow());
EXPECT_EQ(w1.get(), GetActiveWindow());
}
+
+ // Clicking on a non-focusable window inside a background window should still
+ // give focus to the background window.
+ {
+ NonFocusableDelegate nfd;
+ scoped_ptr<aura::Window> w11(CreateTestWindowWithDelegate(
+ &nfd, -1, gfx::Rect(10, 10, 10, 10), w1.get()));
+ // Move focus to |w2| first.
+ scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate(
+ &wd, -1, gfx::Rect(70, 70, 50, 50), NULL));
+ aura::test::EventGenerator generator(Shell::GetRootWindow(), w2.get());
+ generator.ClickLeftButton();
+ EXPECT_EQ(w2.get(), focus_manager->GetFocusedWindow());
+ EXPECT_FALSE(w11->CanFocus());
+
+ // Click on |w11|. This should focus w1.
+ generator.MoveMouseToCenterOf(w11.get());
+ generator.ClickLeftButton();
+ EXPECT_EQ(w1.get(), focus_manager->GetFocusedWindow());
+ }
}
// Essentially the same as ActivateOnMouse, but for touch events.