Commit 3eeb1dfe authored by calamity@chromium.org's avatar calamity@chromium.org

Add search results to experimental app list start page.

This CL moves the SearchResultListView into the StartPageView for
the experimental app list.

BUG=349727

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@276655 0039d316-1c4b-4281-b951-d872f2087c98
parent 36a807c4
......@@ -168,9 +168,10 @@ void AppListMainView::ModelChanged() {
Layout();
}
void AppListMainView::OnContentsViewActivePageChanged() {
void AppListMainView::UpdateSearchBoxVisibility() {
search_box_view_->SetVisible(
!contents_view_->IsNamedPageActive(ContentsView::NAMED_PAGE_START));
!contents_view_->IsNamedPageActive(ContentsView::NAMED_PAGE_START) ||
contents_view_->IsShowingSearchResults());
}
void AppListMainView::OnStartPageSearchButtonPressed() {
......@@ -266,6 +267,7 @@ void AppListMainView::QueryChanged(SearchBoxView* sender) {
base::TrimWhitespace(model_->search_box()->text(), base::TRIM_ALL, &query);
bool should_show_search = !query.empty();
contents_view_->ShowSearchResults(should_show_search);
UpdateSearchBoxVisibility();
if (should_show_search)
delegate_->StartSearch();
......
......@@ -53,7 +53,7 @@ class APP_LIST_EXPORT AppListMainView : public views::View,
void ModelChanged();
void OnContentsViewActivePageChanged();
void UpdateSearchBoxVisibility();
void OnStartPageSearchButtonPressed();
......
......@@ -18,6 +18,7 @@
#include "ui/app_list/views/apps_grid_view.h"
#include "ui/app_list/views/contents_view.h"
#include "ui/app_list/views/search_box_view.h"
#include "ui/app_list/views/search_result_list_view.h"
#include "ui/app_list/views/start_page_view.h"
#include "ui/app_list/views/test/apps_grid_view_test_api.h"
#include "ui/app_list/views/tile_item_view.h"
......@@ -76,9 +77,12 @@ class AppListViewTestContext {
// Tests displaying of the experimental app list and shows the start page.
void RunStartPageTest();
// Tests that changing the App List profile.
// Tests changing the App List profile.
void RunProfileChangeTest();
// Tests displaying of the search results.
void RunSearchResultsTest();
// A standard set of checks on a view, e.g., ensuring it is drawn and visible.
static void CheckView(views::View* subview);
......@@ -355,6 +359,56 @@ void AppListViewTestContext::RunProfileChangeTest() {
Close();
}
void AppListViewTestContext::RunSearchResultsTest() {
EXPECT_FALSE(view_->GetWidget()->IsVisible());
EXPECT_EQ(-1, GetPaginationModel()->total_pages());
AppListTestModel* model = delegate_->GetTestModel();
model->PopulateApps(3);
Show();
AppListMainView* main_view = view_->app_list_main_view();
ContentsView* contents_view = main_view->contents_view();
contents_view->SetActivePage(
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.
contents_view->ShowSearchResults(true);
contents_view->Layout();
EXPECT_TRUE(contents_view->IsShowingSearchResults());
EXPECT_TRUE(main_view->search_box_view()->visible());
if (test_type_ == EXPERIMENTAL) {
EXPECT_TRUE(
contents_view->IsNamedPageActive(ContentsView::NAMED_PAGE_START));
EXPECT_TRUE(IsViewAtOrigin(contents_view->start_page_view()));
} else {
EXPECT_TRUE(contents_view->IsNamedPageActive(
ContentsView::NAMED_PAGE_SEARCH_RESULTS));
EXPECT_TRUE(IsViewAtOrigin(contents_view->search_results_view()));
}
// Hide the search results.
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());
}
Close();
}
class AppListViewTestAura : public views::ViewsTestBase,
public ::testing::WithParamInterface<int> {
public:
......@@ -477,6 +531,15 @@ TEST_P(AppListViewTestDesktop, ProfileChangeTest) {
EXPECT_NO_FATAL_FAILURE(test_context_->RunProfileChangeTest());
}
// Tests that the correct views are displayed for showing search results.
TEST_P(AppListViewTestAura, SearchResultsTest) {
EXPECT_NO_FATAL_FAILURE(test_context_->RunSearchResultsTest());
}
TEST_P(AppListViewTestDesktop, SearchResultsTest) {
EXPECT_NO_FATAL_FAILURE(test_context_->RunSearchResultsTest());
}
INSTANTIATE_TEST_CASE_P(AppListViewTestAuraInstance,
AppListViewTestAura,
::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END));
......
......@@ -37,25 +37,26 @@ const double kFinishTransitionThreshold = 0.33;
ContentsView::ContentsView(AppListMainView* app_list_main_view,
AppListModel* model,
AppListViewDelegate* view_delegate)
: start_page_view_(NULL),
: search_results_view_(NULL),
start_page_view_(NULL),
app_list_main_view_(app_list_main_view),
view_model_(new views::ViewModel),
bounds_animator_(new views::BoundsAnimator(this)) {
DCHECK(model);
search_results_view_ =
new SearchResultListView(app_list_main_view, view_delegate);
AddLauncherPage(search_results_view_, NAMED_PAGE_SEARCH_RESULTS);
if (app_list::switches::IsExperimentalAppListEnabled()) {
start_page_view_ = new StartPageView(app_list_main_view, view_delegate);
AddLauncherPage(start_page_view_, NAMED_PAGE_START);
} else {
search_results_view_ =
new SearchResultListView(app_list_main_view, view_delegate);
AddLauncherPage(search_results_view_, NAMED_PAGE_SEARCH_RESULTS);
search_results_view_->SetResults(model->results());
}
apps_container_view_ = new AppsContainerView(app_list_main_view, model);
active_page_ = AddLauncherPage(apps_container_view_, NAMED_PAGE_APPS);
search_results_view_->SetResults(model->results());
}
ContentsView::~ContentsView() {
......@@ -109,17 +110,41 @@ void ContentsView::ActivePageChanged() {
search_results_view_->visible()) {
search_results_view_->SetSelectedIndex(0);
}
search_results_view_->UpdateAutoLaunchState();
// Notify parent AppListMainView of the page change.
app_list_main_view_->OnContentsViewActivePageChanged();
if (search_results_view_)
search_results_view_->UpdateAutoLaunchState();
if (IsNamedPageActive(NAMED_PAGE_START))
start_page_view_->Reset();
// Notify parent AppListMainView of the page change.
app_list_main_view_->UpdateSearchBoxVisibility();
AnimateToIdealBounds();
}
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;
SetActivePage(GetPageIndexForNamedPage(new_named_page));
if (app_list::switches::IsExperimentalAppListEnabled()) {
if (show)
start_page_view_->ShowSearchResults();
else
start_page_view_->Reset();
app_list_main_view_->UpdateSearchBoxVisibility();
}
}
bool ContentsView::IsShowingSearchResults() const {
return app_list::switches::IsExperimentalAppListEnabled()
? IsNamedPageActive(NAMED_PAGE_START) &&
start_page_view_->IsShowingSearchResults()
: IsNamedPageActive(NAMED_PAGE_SEARCH_RESULTS);
}
void ContentsView::CalculateIdealBounds() {
gfx::Rect rect(GetContentsBounds());
if (rect.IsEmpty())
......@@ -169,11 +194,6 @@ PaginationModel* ContentsView::GetAppsPaginationModel() {
return apps_container_view_->apps_grid_view()->pagination_model();
}
void ContentsView::ShowSearchResults(bool show) {
NamedPage new_named_page = show ? NAMED_PAGE_SEARCH_RESULTS : NAMED_PAGE_APPS;
SetActivePage(GetPageIndexForNamedPage(new_named_page));
}
void ContentsView::ShowFolderContent(AppListFolderItem* item) {
apps_container_view_->ShowActiveFolder(item);
}
......@@ -200,7 +220,9 @@ int ContentsView::AddLauncherPage(views::View* view, NamedPage named_page) {
gfx::Size ContentsView::GetPreferredSize() const {
const gfx::Size container_size =
apps_container_view_->apps_grid_view()->GetPreferredSize();
const gfx::Size results_size = search_results_view_->GetPreferredSize();
const gfx::Size results_size = search_results_view_
? search_results_view_->GetPreferredSize()
: gfx::Size();
int width = std::max(container_size.width(), results_size.width());
int height = std::max(container_size.height(), results_size.height());
......
......@@ -61,6 +61,7 @@ class APP_LIST_EXPORT ContentsView : public views::View {
void ShowSearchResults(bool show);
void ShowFolderContent(AppListFolderItem* folder);
bool IsShowingSearchResults() const;
// Sets the active launcher page and animates the pages into place.
void SetActivePage(int page_index);
......@@ -78,6 +79,7 @@ class APP_LIST_EXPORT ContentsView : public views::View {
AppsContainerView* apps_container_view() { return apps_container_view_; }
StartPageView* start_page_view() { return start_page_view_; }
SearchResultListView* search_results_view() { return search_results_view_; }
// Overridden from views::View:
virtual gfx::Size GetPreferredSize() const OVERRIDE;
......
......@@ -10,6 +10,7 @@
#include "base/message_loop/message_loop.h"
#include "base/time/time.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/app_list/app_list_switches.h"
#include "ui/app_list/app_list_view_delegate.h"
#include "ui/app_list/views/search_result_list_view_delegate.h"
#include "ui/app_list/views/search_result_view.h"
......@@ -21,6 +22,7 @@
namespace {
const int kMaxResults = 6;
const int kExperimentAppListMaxResults = 3;
const int kTimeoutIndicatorHeight = 2;
const int kTimeoutFramerate = 60;
const SkColor kTimeoutIndicatorColor = SkColorSetRGB(30, 144, 255);
......@@ -43,7 +45,11 @@ SearchResultListView::SearchResultListView(
results_container_->SetLayoutManager(
new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
for (int i = 0; i < kMaxResults; ++i)
int max_results = kMaxResults;
if (app_list::switches::IsExperimentalAppListEnabled())
max_results = kExperimentAppListMaxResults;
for (int i = 0; i < max_results; ++i)
results_container_->AddChildView(new SearchResultView(this));
AddChildView(results_container_);
......
......@@ -10,6 +10,7 @@
#include "ui/app_list/app_list_model.h"
#include "ui/app_list/app_list_view_delegate.h"
#include "ui/app_list/views/app_list_main_view.h"
#include "ui/app_list/views/search_result_list_view.h"
#include "ui/app_list/views/tile_item_view.h"
#include "ui/gfx/canvas.h"
#include "ui/views/controls/button/custom_button.h"
......@@ -76,15 +77,17 @@ StartPageView::StartPageView(AppListMainView* app_list_main_view,
: app_list_main_view_(app_list_main_view),
model_(NULL),
view_delegate_(view_delegate),
results_view_(
new SearchResultListView(app_list_main_view, view_delegate)),
instant_container_(new views::View),
tiles_container_(new views::View) {
SetLayoutManager(new views::BoxLayout(
views::BoxLayout::kVertical, 0, kTopMargin, kInstantContainerSpacing));
tiles_container_(new views::View),
show_state_(SHOW_START_PAGE) {
// The view containing the start page WebContents and the BarPlaceholder.
AddChildView(instant_container_);
views::BoxLayout* instant_layout_manager = new views::BoxLayout(
views::BoxLayout::kVertical, 0, 0, kInstantContainerSpacing);
instant_layout_manager->set_inside_border_insets(
gfx::Insets(kTopMargin, 0, kInstantContainerSpacing, 0));
instant_layout_manager->set_main_axis_alignment(
views::BoxLayout::MAIN_AXIS_ALIGNMENT_END);
instant_container_->SetLayoutManager(instant_layout_manager);
......@@ -95,6 +98,9 @@ StartPageView::StartPageView(AppListMainView* app_list_main_view,
instant_container_->AddChildView(web_view);
instant_container_->AddChildView(new BarPlaceholderButton(this));
// The view containing the search results.
AddChildView(results_view_);
// The view containing the start page tiles.
AddChildView(tiles_container_);
views::BoxLayout* tiles_layout_manager =
......@@ -124,11 +130,12 @@ void StartPageView::SetModel(AppListModel* model) {
model_->RemoveObserver(this);
model_ = model;
model_->AddObserver(this);
results_view_->SetResults(model_->results());
Reset();
}
void StartPageView::Reset() {
instant_container_->SetVisible(true);
SetShowState(SHOW_START_PAGE);
if (!model_ || !model_->top_level_item_list())
return;
......@@ -138,14 +145,53 @@ void StartPageView::Reset() {
item = model_->top_level_item_list()->item_at(i);
tile_views_[i]->SetAppListItem(item);
}
}
void StartPageView::ShowSearchResults() {
SetShowState(SHOW_SEARCH_RESULTS);
}
void StartPageView::SetShowState(ShowState show_state) {
instant_container_->SetVisible(show_state == SHOW_START_PAGE);
results_view_->SetVisible(show_state == SHOW_SEARCH_RESULTS);
if (show_state_ == show_state)
return;
show_state_ = show_state;
results_view_->UpdateAutoLaunchState();
if (show_state == SHOW_SEARCH_RESULTS)
results_view_->SetSelectedIndex(0);
}
bool StartPageView::IsShowingSearchResults() const {
return show_state_ == SHOW_SEARCH_RESULTS;
}
bool StartPageView::OnKeyPressed(const ui::KeyEvent& event) {
if (show_state_ == SHOW_SEARCH_RESULTS)
return results_view_->OnKeyPressed(event);
return false;
}
Layout();
void StartPageView::Layout() {
// Instant and search results take up the height of the instant container.
gfx::Rect bounds(GetContentsBounds());
bounds.set_height(instant_container_->GetHeightForWidth(bounds.width()));
instant_container_->SetBoundsRect(bounds);
results_view_->SetBoundsRect(bounds);
// Tiles begin where the instant container ends.
bounds.set_y(bounds.bottom());
bounds.set_height(tiles_container_->GetHeightForWidth(bounds.width()));
tiles_container_->SetBoundsRect(bounds);
}
void StartPageView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
app_list_main_view_->OnStartPageSearchButtonPressed();
instant_container_->SetVisible(false);
}
void StartPageView::OnProfilesChanged() {
......
......@@ -16,6 +16,7 @@ namespace app_list {
class AppListMainView;
class AppListModel;
class AppListViewDelegate;
class SearchResultListView;
class TileItemView;
// The start page for the experimental app list.
......@@ -29,10 +30,23 @@ class StartPageView : public views::View,
virtual ~StartPageView();
void Reset();
void ShowSearchResults();
bool IsShowingSearchResults() const;
const std::vector<TileItemView*>& tile_views() const { return tile_views_; }
// Overridden from views::View:
virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE;
virtual void Layout() OVERRIDE;
private:
enum ShowState {
SHOW_SEARCH_RESULTS,
SHOW_START_PAGE,
};
void SetShowState(ShowState show_state);
void SetModel(AppListModel* model);
// Overridden from views::ButtonListener:
......@@ -55,11 +69,14 @@ class StartPageView : public views::View,
AppListViewDelegate* view_delegate_; // Owned by AppListView.
SearchResultListView* results_view_; // Owned by views hierarchy.
views::View* instant_container_; // Owned by views hierarchy.
views::View* tiles_container_; // Owned by views hierarchy.
std::vector<TileItemView*> tile_views_;
ShowState show_state_;
DISALLOW_COPY_AND_ASSIGN(StartPageView);
};
......
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