From 89a7a78de73f177430b37fc57ed9824fa50538d7 Mon Sep 17 00:00:00 2001 From: "calamity@chromium.org" Date: Wed, 16 Jul 2014 15:51:53 +0000 Subject: [PATCH] Make app list return to previous page after search. This CL makes the app list return to the previously displayed page when the search box query is cleared. BUG=349727 Review URL: https://codereview.chromium.org/377783006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283403 0039d316-1c4b-4281-b951-d872f2087c98 --- ui/app_list/views/app_list_view_unittest.cc | 20 ++++++++------------ ui/app_list/views/contents_view.cc | 15 ++++++++++----- ui/app_list/views/contents_view.h | 9 ++++++++- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/ui/app_list/views/app_list_view_unittest.cc b/ui/app_list/views/app_list_view_unittest.cc index f507ca9ab8f4..c2d3079076e3 100644 --- a/ui/app_list/views/app_list_view_unittest.cc +++ b/ui/app_list/views/app_list_view_unittest.cc @@ -443,7 +443,6 @@ void AppListViewTestContext::RunSearchResultsTest() { ContentsView* contents_view = main_view->contents_view(); ShowContentsViewPageAndVerify( contents_view->GetPageIndexForNamedPage(ContentsView::NAMED_PAGE_APPS)); - EXPECT_TRUE(IsViewAtOrigin(contents_view->apps_container_view())); EXPECT_TRUE(main_view->search_box_view()->visible()); // Show the search results. @@ -466,19 +465,16 @@ void AppListViewTestContext::RunSearchResultsTest() { contents_view->ShowSearchResults(false); contents_view->Layout(); EXPECT_FALSE(contents_view->IsShowingSearchResults()); - if (test_type_ == EXPERIMENTAL) { - EXPECT_TRUE( - contents_view->IsNamedPageActive(ContentsView::NAMED_PAGE_START)); - EXPECT_TRUE(IsViewAtOrigin(contents_view->start_page_view())); - EXPECT_FALSE(main_view->search_box_view()->visible()); - } else { - EXPECT_TRUE( - contents_view->IsNamedPageActive(ContentsView::NAMED_PAGE_APPS)); - EXPECT_TRUE(IsViewAtOrigin(contents_view->apps_container_view())); - EXPECT_TRUE(main_view->search_box_view()->visible()); - } + + // Check that we return to the page that we were on before the search. + EXPECT_TRUE(contents_view->IsNamedPageActive(ContentsView::NAMED_PAGE_APPS)); + EXPECT_TRUE(IsViewAtOrigin(contents_view->apps_container_view())); + EXPECT_TRUE(main_view->search_box_view()->visible()); if (test_type_ == EXPERIMENTAL) { + ShowContentsViewPageAndVerify(contents_view->GetPageIndexForNamedPage( + ContentsView::NAMED_PAGE_START)); + // Check that typing into the dummy search box triggers the search page. base::string16 search_text = base::UTF8ToUTF16("test"); SearchBoxView* dummy_search_box = diff --git a/ui/app_list/views/contents_view.cc b/ui/app_list/views/contents_view.cc index 01dccd9dccd4..9057abc8524f 100644 --- a/ui/app_list/views/contents_view.cc +++ b/ui/app_list/views/contents_view.cc @@ -40,7 +40,8 @@ ContentsView::ContentsView(AppListMainView* app_list_main_view) start_page_view_(NULL), app_list_main_view_(app_list_main_view), contents_switcher_view_(NULL), - view_model_(new views::ViewModel) { + view_model_(new views::ViewModel), + page_before_search_(0) { pagination_model_.AddObserver(this); } @@ -77,6 +78,7 @@ void ContentsView::InitNamedPages(AppListModel* model, if (app_list::switches::IsExperimentalAppListEnabled()) initial_page_index = GetPageIndexForNamedPage(NAMED_PAGE_START); + page_before_search_ = initial_page_index; pagination_model_.SelectPage(initial_page_index, false); // Needed to update the main search box visibility. @@ -143,6 +145,8 @@ int ContentsView::NumLauncherPages() const { void ContentsView::SetActivePageInternal(int page_index, bool show_search_results) { + if (!show_search_results) + page_before_search_ = page_index; // Start animating to the new page. pagination_model_.SelectPage(page_index, true); ActivePageChanged(show_search_results); @@ -169,11 +173,12 @@ void ContentsView::ActivePageChanged(bool show_search_results) { } void ContentsView::ShowSearchResults(bool show) { - NamedPage new_named_page = show ? NAMED_PAGE_SEARCH_RESULTS : NAMED_PAGE_APPS; - if (app_list::switches::IsExperimentalAppListEnabled()) - new_named_page = NAMED_PAGE_START; + int search_page = GetPageIndexForNamedPage( + app_list::switches::IsExperimentalAppListEnabled() + ? NAMED_PAGE_START + : NAMED_PAGE_SEARCH_RESULTS); - SetActivePageInternal(GetPageIndexForNamedPage(new_named_page), show); + SetActivePageInternal(show ? search_page : page_before_search_, show); } bool ContentsView::IsShowingSearchResults() const { diff --git a/ui/app_list/views/contents_view.h b/ui/app_list/views/contents_view.h index e57a0d2a3495..b828490ad942 100644 --- a/ui/app_list/views/contents_view.h +++ b/ui/app_list/views/contents_view.h @@ -67,10 +67,14 @@ class APP_LIST_EXPORT ContentsView : public views::View, void SetContentsSwitcherView(ContentsSwitcherView* contents_switcher_view); + // Shows/hides the search results. Hiding the search results will cause the + // app list to return to the page that was displayed before + // ShowSearchResults(true) was invoked. void ShowSearchResults(bool show); - void ShowFolderContent(AppListFolderItem* folder); bool IsShowingSearchResults() const; + void ShowFolderContent(AppListFolderItem* folder); + // Sets the active launcher page and animates the pages into place. void SetActivePage(int page_index); @@ -156,6 +160,9 @@ class APP_LIST_EXPORT ContentsView : public views::View, // Maps NamedPage onto |view_model_| indices. std::map named_page_to_view_; + // The page that was showing before ShowSearchResults(true) was invoked. + int page_before_search_; + // Manages the pagination for the launcher pages. PaginationModel pagination_model_; -- 2.11.4.GIT