Commit a5e8abcf authored by Weidong Guo's avatar Weidong Guo Committed by Commit Bot

applist-focus: Hitting Enter should activate the search box

Changes:
Hitting Enter when search box is not active and search box is focused
activates the search box.

BUG=780339
TEST=AppListViewFocusTest.HittingEnterWhenFocusOnSearchBox

Change-Id: I16d3b32d0d163badc11fc921926b2b174480c11e
Reviewed-on: https://chromium-review.googlesource.com/748164Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Weidong Guo <weidongg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#513189}
parent f5a01229
...@@ -887,11 +887,18 @@ TEST_F(AppListViewFocusTest, FirstResultSelectedAfterSearchResultsUpdated) { ...@@ -887,11 +887,18 @@ TEST_F(AppListViewFocusTest, FirstResultSelectedAfterSearchResultsUpdated) {
contents_view()->search_results_page_view()->first_result_view()); contents_view()->search_results_page_view()->first_result_view());
} }
// Tests that hitting Enter key when focus is on search box opens the first // Tests hitting Enter key when focus is on search box.
// result when it exists. // There are two behaviors:
// 1. Activate the search box when it is inactive.
// 2. Open the first result when query exists.
TEST_F(AppListViewFocusTest, HittingEnterWhenFocusOnSearchBox) { TEST_F(AppListViewFocusTest, HittingEnterWhenFocusOnSearchBox) {
Show(); Show();
// Initially the search box is inactive, hitting Enter to activate it.
EXPECT_FALSE(search_box_view()->is_search_box_active());
SimulateKeyPress(ui::VKEY_RETURN, false);
EXPECT_TRUE(search_box_view()->is_search_box_active());
// Type something in search box to transition to HALF state and populate // Type something in search box to transition to HALF state and populate
// fake list results. Then hit Enter key. // fake list results. Then hit Enter key.
search_box_view()->search_box()->InsertText(base::UTF8ToUTF16("test")); search_box_view()->search_box()->InsertText(base::UTF8ToUTF16("test"));
......
...@@ -862,8 +862,8 @@ bool SearchBoxView::HandleKeyEvent(views::Textfield* sender, ...@@ -862,8 +862,8 @@ bool SearchBoxView::HandleKeyEvent(views::Textfield* sender,
const ui::KeyEvent& key_event) { const ui::KeyEvent& key_event) {
if (is_app_list_focus_enabled_) { if (is_app_list_focus_enabled_) {
if (key_event.type() == ui::ET_KEY_PRESSED && if (key_event.type() == ui::ET_KEY_PRESSED &&
key_event.key_code() == ui::VKEY_RETURN && key_event.key_code() == ui::VKEY_RETURN) {
!IsSearchBoxTrimmedQueryEmpty()) { if (!IsSearchBoxTrimmedQueryEmpty()) {
// Hitting Enter when focus is on search box opens the first result. // Hitting Enter when focus is on search box opens the first result.
ui::KeyEvent event(key_event); ui::KeyEvent event(key_event);
views::View* first_result_view = views::View* first_result_view =
...@@ -872,11 +872,18 @@ bool SearchBoxView::HandleKeyEvent(views::Textfield* sender, ...@@ -872,11 +872,18 @@ bool SearchBoxView::HandleKeyEvent(views::Textfield* sender,
->first_result_view(); ->first_result_view();
if (first_result_view) if (first_result_view)
first_result_view->OnKeyEvent(&event); first_result_view->OnKeyEvent(&event);
return true;
}
if (!is_search_box_active()) {
SetSearchBoxActive(true);
return true;
}
} }
// TODO(weidongg/766807) Remove this function when the flag is enabled by
// default.
return false; return false;
} }
// TODO(weidongg/766807) Remove everything below when the flag is enabled by
// default.
if (key_event.type() == ui::ET_KEY_PRESSED) { if (key_event.type() == ui::ET_KEY_PRESSED) {
if (key_event.key_code() == ui::VKEY_TAB && if (key_event.key_code() == ui::VKEY_TAB &&
focused_view_ != FOCUS_CONTENTS_VIEW && focused_view_ != FOCUS_CONTENTS_VIEW &&
......
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