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) {
contents_view()->search_results_page_view()->first_result_view());
}
// Tests that hitting Enter key when focus is on search box opens the first
// result when it exists.
// Tests hitting Enter key when focus is on search box.
// 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) {
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
// fake list results. Then hit Enter key.
search_box_view()->search_box()->InsertText(base::UTF8ToUTF16("test"));
......
......@@ -862,21 +862,28 @@ bool SearchBoxView::HandleKeyEvent(views::Textfield* sender,
const ui::KeyEvent& key_event) {
if (is_app_list_focus_enabled_) {
if (key_event.type() == ui::ET_KEY_PRESSED &&
key_event.key_code() == ui::VKEY_RETURN &&
!IsSearchBoxTrimmedQueryEmpty()) {
// Hitting Enter when focus is on search box opens the first result.
ui::KeyEvent event(key_event);
views::View* first_result_view =
static_cast<ContentsView*>(contents_view_)
->search_results_page_view()
->first_result_view();
if (first_result_view)
first_result_view->OnKeyEvent(&event);
key_event.key_code() == ui::VKEY_RETURN) {
if (!IsSearchBoxTrimmedQueryEmpty()) {
// Hitting Enter when focus is on search box opens the first result.
ui::KeyEvent event(key_event);
views::View* first_result_view =
static_cast<ContentsView*>(contents_view_)
->search_results_page_view()
->first_result_view();
if (first_result_view)
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;
}
// TODO(weidongg/766807) Remove everything below when the flag is enabled by
// default.
if (key_event.type() == ui::ET_KEY_PRESSED) {
if (key_event.key_code() == ui::VKEY_TAB &&
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