diff options
author | mukai <mukai@chromium.org> | 2014-11-10 20:40:33 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-11-11 04:40:52 +0000 |
commit | fdd138cf6959045e59ca3d77b37f1b37d9a92e83 (patch) | |
tree | 44acfa3510cc818555995448bc3eda0b4d002772 | |
parent | fc0e875101b73e2f2f31c34aacf029c3181b5cf0 (diff) | |
download | chromium_src-fdd138cf6959045e59ca3d77b37f1b37d9a92e83.zip chromium_src-fdd138cf6959045e59ca3d77b37f1b37d9a92e83.tar.gz chromium_src-fdd138cf6959045e59ca3d77b37f1b37d9a92e83.tar.bz2 |
Synchronizes the app_list state and the home card state.
- "all apps" from BOTTOM state should switch to CENTERED state
- switching to BOTTOM state should switch to the start page
BUG=425724, 425717
R=oshima@chromium.org
TEST=the new test covers
Export HomeCardView into a separate file.
HomeCardView gets fairly complicated and it's worth exporting into
a different file.
Review URL: https://codereview.chromium.org/712133002
Cr-Commit-Position: refs/heads/master@{#303593}
-rw-r--r-- | athena/home/home_card_impl.cc | 16 | ||||
-rw-r--r-- | athena/home/home_card_impl.h | 12 | ||||
-rw-r--r-- | athena/home/home_card_unittest.cc | 38 | ||||
-rw-r--r-- | athena/home/home_card_view.cc | 6 | ||||
-rw-r--r-- | athena/home/home_card_view.h | 6 |
5 files changed, 76 insertions, 2 deletions
diff --git a/athena/home/home_card_impl.cc b/athena/home/home_card_impl.cc index 2e7cdd1..da75954 100644 --- a/athena/home/home_card_impl.cc +++ b/athena/home/home_card_impl.cc @@ -134,6 +134,7 @@ HomeCardImpl::~HomeCardImpl() { // Reset the view delegate first as it access search provider during // shutdown. + view_delegate_->GetModel()->RemoveObserver(this); view_delegate_.reset(); instance = nullptr; } @@ -151,6 +152,7 @@ void HomeCardImpl::Init() { view_delegate_.reset( new AppListViewDelegate(model_builder_.get(), search_factory_.get())); + view_delegate_->GetModel()->AddObserver(this); home_card_view_ = new HomeCardView(view_delegate_.get(), this); home_card_widget_ = new views::Widget(); views::Widget::InitParams widget_params( @@ -305,6 +307,20 @@ void HomeCardImpl::OnSplitViewModeEnter() { void HomeCardImpl::OnSplitViewModeExit() { } +void HomeCardImpl::OnAppListModelStateChanged( + app_list::AppListModel::State old_state, + app_list::AppListModel::State new_state) { + // State change should not happen in minimized mode. + DCHECK_NE(VISIBLE_MINIMIZED, state_); + + if (state_ == VISIBLE_BOTTOM) { + if (old_state == app_list::AppListModel::STATE_START) + SetState(VISIBLE_CENTERED); + else + DCHECK_EQ(app_list::AppListModel::STATE_START, new_state); + } +} + // static HomeCard* HomeCard::Create(scoped_ptr<AppModelBuilder> model_builder, scoped_ptr<SearchControllerFactory> search_factory) { diff --git a/athena/home/home_card_impl.h b/athena/home/home_card_impl.h index a35c31b5..08e56c5 100644 --- a/athena/home/home_card_impl.h +++ b/athena/home/home_card_impl.h @@ -11,6 +11,8 @@ #include "athena/home/public/search_controller_factory.h" #include "athena/input/public/accelerator_manager.h" #include "athena/wm/public/window_manager_observer.h" +#include "base/gtest_prod_util.h" +#include "ui/app_list/app_list_model_observer.h" namespace app_list { class AppListViewDelegate; @@ -40,7 +42,8 @@ class HomeCardView; class ATHENA_EXPORT HomeCardImpl : public HomeCard, public AcceleratorHandler, public HomeCardGestureManager::Delegate, - public WindowManagerObserver { + public WindowManagerObserver, + public app_list::AppListModelObserver { public: HomeCardImpl(scoped_ptr<AppModelBuilder> model_builder, scoped_ptr<SearchControllerFactory> search_factory); @@ -51,6 +54,8 @@ class ATHENA_EXPORT HomeCardImpl : public HomeCard, aura::Window* GetHomeCardWindowForTest() const; private: + FRIEND_TEST_ALL_PREFIXES(HomeCardTest, AppListStates); + enum Command { COMMAND_SHOW_HOME_CARD, }; @@ -80,6 +85,11 @@ class ATHENA_EXPORT HomeCardImpl : public HomeCard, void OnSplitViewModeEnter() override; void OnSplitViewModeExit() override; + // app_list::AppListModelObserver: + void OnAppListModelStateChanged( + app_list::AppListModel::State old_state, + app_list::AppListModel::State new_state) override; + scoped_ptr<AppModelBuilder> model_builder_; scoped_ptr<SearchControllerFactory> search_factory_; diff --git a/athena/home/home_card_unittest.cc b/athena/home/home_card_unittest.cc index 8afa0ae..46ffccd 100644 --- a/athena/home/home_card_unittest.cc +++ b/athena/home/home_card_unittest.cc @@ -7,9 +7,14 @@ #include "athena/activity/public/activity_factory.h" #include "athena/home/home_card_constants.h" #include "athena/home/home_card_impl.h" +#include "athena/home/home_card_view.h" #include "athena/test/base/athena_test_base.h" #include "athena/test/base/test_windows.h" #include "athena/wm/public/window_manager.h" +#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/contents_view.h" #include "ui/aura/test/test_window_delegate.h" #include "ui/aura/window.h" #include "ui/events/test/event_generator.h" @@ -281,4 +286,37 @@ TEST_F(HomeCardTest, DontMinimizeWithModalWindow) { EXPECT_TRUE(wm::IsActiveWindow(home_card)); } +TEST_F(HomeCardTest, AppListStates) { + app_list::AppListModel* model = + static_cast<HomeCardImpl*>(HomeCard::Get())->view_delegate_->GetModel(); + + WindowManager::Get()->EnterOverview(); + ASSERT_EQ(HomeCard::VISIBLE_BOTTOM, HomeCard::Get()->GetState()); + ASSERT_EQ(app_list::AppListModel::STATE_START, model->state()); + + // Changes the contents of the home card to "apps" view, which should change + // the home card state to VISIBLE_CENTERED. + app_list::ContentsView* contents_view = + static_cast<HomeCardImpl*>(HomeCard::Get()) + ->home_card_view_->main_view_->contents_view(); + contents_view->SetActivePage( + contents_view->GetPageIndexForState(app_list::AppListModel::STATE_APPS)); + EXPECT_EQ(HomeCard::VISIBLE_CENTERED, HomeCard::Get()->GetState()); + EXPECT_EQ(app_list::AppListModel::STATE_APPS, model->state()); + + // VISIBLE_BOTTOM state should always show the start page. + HomeCard::Get()->SetState(HomeCard::VISIBLE_BOTTOM); + EXPECT_EQ(app_list::AppListModel::STATE_START, model->state()); + + // VISIBLE_CENTERED with apps mode state to minimized -- and then back to + // VISIBLE_BOTTOM. + contents_view->SetActivePage( + contents_view->GetPageIndexForState(app_list::AppListModel::STATE_APPS)); + EXPECT_EQ(app_list::AppListModel::STATE_APPS, model->state()); + WindowManager::Get()->ExitOverview(); + WindowManager::Get()->EnterOverview(); + EXPECT_EQ(HomeCard::VISIBLE_BOTTOM, HomeCard::Get()->GetState()); + EXPECT_EQ(app_list::AppListModel::STATE_START, model->state()); +} + } // namespace athena diff --git a/athena/home/home_card_view.cc b/athena/home/home_card_view.cc index 95ca508..120cb90 100644 --- a/athena/home/home_card_view.cc +++ b/athena/home/home_card_view.cc @@ -8,6 +8,7 @@ #include "athena/wm/public/window_manager.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/contents_view.h" #include "ui/app_list/views/search_box_view.h" #include "ui/aura/window.h" #include "ui/compositor/closure_animation_observer.h" @@ -179,6 +180,11 @@ void HomeCardView::SetStateWithAnimation( } main_view_->UpdateSearchBoxVisibility(); + if (state == HomeCard::VISIBLE_BOTTOM) { + app_list::ContentsView* contents_view = main_view_->contents_view(); + contents_view->SetActivePage(contents_view->GetPageIndexForState( + app_list::AppListModel::STATE_START)); + } } void HomeCardView::ClearGesture() { diff --git a/athena/home/home_card_view.h b/athena/home/home_card_view.h index ffd8144..7504d2e 100644 --- a/athena/home/home_card_view.h +++ b/athena/home/home_card_view.h @@ -5,8 +5,10 @@ #ifndef ATHENA_HOME_HOME_CARD_VIEW_H_ #define ATHENA_HOME_HOME_CARD_VIEW_H_ +#include "athena/athena_export.h" #include "athena/home/home_card_gesture_manager.h" #include "base/callback_forward.h" +#include "base/gtest_prod_util.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "ui/gfx/animation/tween.h" @@ -29,7 +31,7 @@ class View; namespace athena { // The container view of home card contents. -class HomeCardView : public views::WidgetDelegateView { +class ATHENA_EXPORT HomeCardView : public views::WidgetDelegateView { public: HomeCardView(app_list::AppListViewDelegate* view_delegate, HomeCardGestureManager::Delegate* gesture_delegate); @@ -53,6 +55,8 @@ class HomeCardView : public views::WidgetDelegateView { void Layout() override; private: + FRIEND_TEST_ALL_PREFIXES(HomeCardTest, AppListStates); + gfx::Rect GetDragIndicatorBounds(HomeCard::State state); gfx::Rect GetMainViewBounds(HomeCard::State state); |