Fix pressing enter key crashes overview mode without a

selection. 
This change adds a check before trying to select 
the window with the enter key that verifies that the 
selection is active. If it is not, pressing it has no 
effect.

BUG=381811
TEST=WindowSelectorTest.SelectWindowWithReturnKey

Review URL: https://codereview.chromium.org/324493004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275604 0039d316-1c4b-4281-b951-d872f2087c98
parent b63bfd43
...@@ -200,7 +200,6 @@ void WindowSelector::OnKeyEvent(ui::KeyEvent* event) { ...@@ -200,7 +200,6 @@ void WindowSelector::OnKeyEvent(ui::KeyEvent* event) {
if (event->type() != ui::ET_KEY_PRESSED) if (event->type() != ui::ET_KEY_PRESSED)
return; return;
bool handled = true;
switch (event->key_code()) { switch (event->key_code()) {
case ui::VKEY_ESCAPE: case ui::VKEY_ESCAPE:
CancelSelection(); CancelSelection();
...@@ -218,17 +217,17 @@ void WindowSelector::OnKeyEvent(ui::KeyEvent* event) { ...@@ -218,17 +217,17 @@ void WindowSelector::OnKeyEvent(ui::KeyEvent* event) {
Move(WindowSelector::LEFT); Move(WindowSelector::LEFT);
break; break;
case ui::VKEY_RETURN: case ui::VKEY_RETURN:
wm::GetWindowState( // Ignore if no item is selected.
grid_list_[selected_grid_index_]-> if (!grid_list_[selected_grid_index_]->is_selecting())
SelectedWindow()->SelectionWindow())->Activate(); return;
wm::GetWindowState(grid_list_[selected_grid_index_]->
SelectedWindow()->SelectionWindow())->Activate();
break; break;
default: default:
// Not a key we are interested in. // Not a key we are interested in.
handled = false; return;
break;
} }
if (handled) event->StopPropagation();
event->SetHandled();
} }
void WindowSelector::OnDisplayAdded(const gfx::Display& display) { void WindowSelector::OnDisplayAdded(const gfx::Display& display) {
......
...@@ -861,4 +861,30 @@ TEST_F(WindowSelectorTest, BasicMultiMonitorArrowKeyNavigation) { ...@@ -861,4 +861,30 @@ TEST_F(WindowSelectorTest, BasicMultiMonitorArrowKeyNavigation) {
EXPECT_EQ(GetSelectedWindow(), window4.get()); EXPECT_EQ(GetSelectedWindow(), window4.get());
} }
// Tests selecting a window in overview mode with the return key.
TEST_F(WindowSelectorTest, SelectWindowWithReturnKey) {
gfx::Rect bounds(0, 0, 100, 100);
scoped_ptr<aura::Window> window2(CreateWindow(bounds));
scoped_ptr<aura::Window> window1(CreateWindow(bounds));
ToggleOverview();
// Pressing the return key without a selection widget should not do anything.
SendKey(ui::VKEY_RETURN);
EXPECT_TRUE(IsSelecting());
// Select the first window.
SendKey(ui::VKEY_RIGHT);
SendKey(ui::VKEY_RETURN);
ASSERT_FALSE(IsSelecting());
EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
// Select the second window.
ToggleOverview();
SendKey(ui::VKEY_RIGHT);
SendKey(ui::VKEY_RIGHT);
SendKey(ui::VKEY_RETURN);
EXPECT_FALSE(IsSelecting());
EXPECT_TRUE(wm::IsActiveWindow(window2.get()));
}
} // namespace ash } // namespace ash
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment