diff options
author | kcarattini@chromium.org <kcarattini@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-10 16:02:50 +0000 |
---|---|---|
committer | kcarattini@chromium.org <kcarattini@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-10 16:02:50 +0000 |
commit | ee4d73028c4320ab5877c13f8fb61b2068464219 (patch) | |
tree | dade2386ffb27ecbb31b574f30c68653073e2745 /ui/app_list | |
parent | 7bc445332eaa7996d818669873a85701407a0713 (diff) | |
download | chromium_src-ee4d73028c4320ab5877c13f8fb61b2068464219.zip chromium_src-ee4d73028c4320ab5877c13f8fb61b2068464219.tar.gz chromium_src-ee4d73028c4320ab5877c13f8fb61b2068464219.tar.bz2 |
Experimental app list: Added a current page indicator to the launcher.
Adds a current page indicator to the launcher when the experimental app launcher is enabled.
BUG=391642
Review URL: https://codereview.chromium.org/380613002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282335 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/app_list')
-rw-r--r-- | ui/app_list/app_list_constants.cc | 4 | ||||
-rw-r--r-- | ui/app_list/app_list_constants.h | 2 | ||||
-rw-r--r-- | ui/app_list/views/app_list_background.cc | 5 | ||||
-rw-r--r-- | ui/app_list/views/app_list_main_view.cc | 2 | ||||
-rw-r--r-- | ui/app_list/views/contents_switcher_view.cc | 78 | ||||
-rw-r--r-- | ui/app_list/views/contents_switcher_view.h | 13 | ||||
-rw-r--r-- | ui/app_list/views/contents_view.cc | 12 | ||||
-rw-r--r-- | ui/app_list/views/contents_view.h | 8 |
8 files changed, 114 insertions, 10 deletions
diff --git a/ui/app_list/app_list_constants.cc b/ui/app_list/app_list_constants.cc index 46ce92e..94d196f 100644 --- a/ui/app_list/app_list_constants.cc +++ b/ui/app_list/app_list_constants.cc @@ -74,6 +74,10 @@ const int kExperimentalPreferredRows = 3; // Radius of the circle, in which if entered, show re-order preview. const int kReorderDroppingCircleRadius = 35; +// Height of separator between the main view and contents switcher and of +// the launcher page indicator. +const int kContentsSwitcherSeparatorHeight = 1; + // Max items allowed in a folder. size_t kMaxFolderItems = 16; diff --git a/ui/app_list/app_list_constants.h b/ui/app_list/app_list_constants.h index a1937d5..f6477ed 100644 --- a/ui/app_list/app_list_constants.h +++ b/ui/app_list/app_list_constants.h @@ -56,6 +56,8 @@ APP_LIST_EXPORT extern const int kExperimentalPreferredRows; APP_LIST_EXPORT extern const int kReorderDroppingCircleRadius; +APP_LIST_EXPORT extern const int kContentsSwitcherSeparatorHeight; + APP_LIST_EXPORT extern size_t kMaxFolderItems; APP_LIST_EXPORT extern const size_t kNumFolderTopItems; APP_LIST_EXPORT extern const size_t kMaxFolderNameChars; diff --git a/ui/app_list/views/app_list_background.cc b/ui/app_list/views/app_list_background.cc index 19085e6..aca3f75 100644 --- a/ui/app_list/views/app_list_background.cc +++ b/ui/app_list/views/app_list_background.cc @@ -88,7 +88,10 @@ void AppListBackground::Paint(gfx::Canvas* canvas, const gfx::Rect contents_view_view_bounds = contents_view->ConvertRectToWidget(contents_view->GetLocalBounds()); gfx::Rect separator_rect(contents_rect); - separator_rect.set_y(contents_view_view_bounds.bottom()); + // Extra kContentsSwitcherSeparatorHeight pixels so the launcher page + // indicator overlays the separator rect. + separator_rect.set_y(contents_view_view_bounds.bottom() + + kContentsSwitcherSeparatorHeight); separator_rect.set_height(kBottomSeparatorSize); canvas->FillRect(separator_rect, kBottomSeparatorColor); int contents_switcher_top = separator_rect.bottom(); diff --git a/ui/app_list/views/app_list_main_view.cc b/ui/app_list/views/app_list_main_view.cc index 06cbc6a..2cbe4f6 100644 --- a/ui/app_list/views/app_list_main_view.cc +++ b/ui/app_list/views/app_list_main_view.cc @@ -139,7 +139,7 @@ void AppListMainView::AddContentsViews() { contents_view_ = new ContentsView(this); if (app_list::switches::IsExperimentalAppListEnabled()) { contents_switcher_view_ = new ContentsSwitcherView(contents_view_); - contents_view_->set_contents_switcher_view(contents_switcher_view_); + contents_view_->SetContentsSwitcherView(contents_switcher_view_); } contents_view_->InitNamedPages(model_, delegate_); AddChildView(contents_view_); diff --git a/ui/app_list/views/contents_switcher_view.cc b/ui/app_list/views/contents_switcher_view.cc index 9566943..c975065 100644 --- a/ui/app_list/views/contents_switcher_view.cc +++ b/ui/app_list/views/contents_switcher_view.cc @@ -6,17 +6,35 @@ #include "ui/app_list/app_list_constants.h" #include "ui/app_list/views/contents_view.h" +#include "ui/views/background.h" #include "ui/views/controls/button/custom_button.h" #include "ui/views/controls/button/image_button.h" #include "ui/views/layout/box_layout.h" +#include "ui/views/layout/fill_layout.h" namespace app_list { namespace { -const int kPreferredHeight = 32; +const int kButtonImageSize = 32; +const int kPreferredHeight = + kButtonImageSize + kContentsSwitcherSeparatorHeight; const int kButtonSpacing = 4; +class ContentsPageIndicatorView : public views::View { + public: + ContentsPageIndicatorView() {}; + virtual ~ContentsPageIndicatorView() {}; + + // Overridden from views::View: + virtual gfx::Size GetPreferredSize() const OVERRIDE { + return gfx::Size(0, kContentsSwitcherSeparatorHeight); + }; + + private: + DISALLOW_COPY_AND_ASSIGN(ContentsPageIndicatorView); +}; + } // namespace ContentsSwitcherView::ContentsSwitcherView(ContentsView* contents_view) @@ -31,13 +49,37 @@ ContentsSwitcherView::~ContentsSwitcherView() {} void ContentsSwitcherView::AddSwitcherButton(int resource_id, int page_index) { views::ImageButton* button = new views::ImageButton(this); + button->SetPreferredSize(gfx::Size(kButtonImageSize, kButtonImageSize)); if (resource_id) { button->SetImage( views::CustomButton::STATE_NORMAL, ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id)); } button->set_tag(page_index); - buttons_->AddChildView(button); + + // Add an indicator for the current launcher page. + app_list::ContentsPageIndicatorView* indicator = + new app_list::ContentsPageIndicatorView(); + indicator->set_background( + views::Background::CreateSolidBackground(app_list::kPagerSelectedColor)); + indicator->SetVisible(false); + page_active_indicators_.push_back(indicator); + + // A container view that will consume space when its child is not visible. + // TODO(calamity): Remove this once BoxLayout supports space-consuming + // invisible views. + views::View* indicator_container = new views::View(); + indicator_container->SetLayoutManager(new views::FillLayout()); + indicator_container->AddChildView(indicator); + + // View containing the indicator view and image button. + views::View* button_container = new views::View(); + button_container->SetLayoutManager( + new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); + button_container->AddChildView(indicator_container); + button_container->AddChildView(button); + + buttons_->AddChildView(button_container); } gfx::Size ContentsSwitcherView::GetPreferredSize() const { @@ -61,4 +103,36 @@ void ContentsSwitcherView::ButtonPressed(views::Button* sender, contents_view_->SetActivePage(sender->tag()); } +void ContentsSwitcherView::TotalPagesChanged() { +} + +void ContentsSwitcherView::SelectedPageChanged(int old_selected, + int new_selected) { + // Makes the indicator visible when it is first drawn and when the + // selected page is changed. + int num_indicators = static_cast<int>(page_active_indicators_.size()); + if (old_selected >= 0 && old_selected < num_indicators) + page_active_indicators_[old_selected]->SetVisible(false); + + if (new_selected >= 0 && new_selected < num_indicators) + page_active_indicators_[new_selected]->SetVisible(true); +} + +void ContentsSwitcherView::TransitionStarted() { +} + +void ContentsSwitcherView::TransitionChanged() { + // Change the indicator during a launcher page transition. + const PaginationModel& pm = contents_view_->pagination_model(); + int old_selected = pm.selected_page(); + int new_selected = pm.transition().target_page; + if (pm.IsRevertingCurrentTransition()) { + // Swap the direction if the transition is reversed. + old_selected = pm.transition().target_page; + new_selected = pm.selected_page(); + } + + SelectedPageChanged(old_selected, new_selected); +} + } // namespace app_list diff --git a/ui/app_list/views/contents_switcher_view.h b/ui/app_list/views/contents_switcher_view.h index 3f1bbf4..38ba280 100644 --- a/ui/app_list/views/contents_switcher_view.h +++ b/ui/app_list/views/contents_switcher_view.h @@ -6,6 +6,7 @@ #define UI_APP_LIST_VIEWS_CONTENTS_SWITCHER_VIEW_H_ #include "base/basictypes.h" +#include "ui/app_list/pagination_model_observer.h" #include "ui/views/controls/button/button.h" #include "ui/views/view.h" @@ -15,7 +16,9 @@ class ContentsView; // A view that contains buttons to switch the displayed view in the given // ContentsView. -class ContentsSwitcherView : public views::View, public views::ButtonListener { +class ContentsSwitcherView : public views::View, + public views::ButtonListener, + public PaginationModelObserver { public: explicit ContentsSwitcherView(ContentsView* contents_view); virtual ~ContentsSwitcherView(); @@ -36,8 +39,16 @@ class ContentsSwitcherView : public views::View, public views::ButtonListener { virtual void ButtonPressed(views::Button* sender, const ui::Event& event) OVERRIDE; + // Overridden from PaginationModelObserver: + virtual void TotalPagesChanged() OVERRIDE; + virtual void SelectedPageChanged(int old_selected, int new_selected) OVERRIDE; + virtual void TransitionStarted() OVERRIDE; + virtual void TransitionChanged() OVERRIDE; + ContentsView* contents_view_; // Owned by views hierarchy. views::View* buttons_; // Owned by views hierarchy. + // Stores Views owned by views hierarchy. + std::vector<views::View*> page_active_indicators_; DISALLOW_COPY_AND_ASSIGN(ContentsSwitcherView); }; diff --git a/ui/app_list/views/contents_view.cc b/ui/app_list/views/contents_view.cc index 452e4fd..01dccd9 100644 --- a/ui/app_list/views/contents_view.cc +++ b/ui/app_list/views/contents_view.cc @@ -46,6 +46,8 @@ ContentsView::ContentsView(AppListMainView* app_list_main_view) ContentsView::~ContentsView() { pagination_model_.RemoveObserver(this); + if (contents_switcher_view_) + pagination_model_.RemoveObserver(contents_switcher_view_); } void ContentsView::InitNamedPages(AppListModel* model, @@ -97,6 +99,14 @@ void ContentsView::SetDragAndDropHostOfCurrentAppList( apps_container_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); } +void ContentsView::SetContentsSwitcherView( + ContentsSwitcherView* contents_switcher_view) { + DCHECK(!contents_switcher_view_); + contents_switcher_view_ = contents_switcher_view; + if (contents_switcher_view_) + pagination_model_.AddObserver(contents_switcher_view_); +} + void ContentsView::SetActivePage(int page_index) { if (GetActivePageIndex() == page_index) return; @@ -244,9 +254,9 @@ int ContentsView::AddLauncherPage(views::View* view, int resource_id) { int page_index = view_model_->view_size(); AddChildView(view); view_model_->Add(view, page_index); - pagination_model_.SetTotalPages(view_model_->view_size()); if (contents_switcher_view_) contents_switcher_view_->AddSwitcherButton(resource_id, page_index); + pagination_model_.SetTotalPages(view_model_->view_size()); return page_index; } diff --git a/ui/app_list/views/contents_view.h b/ui/app_list/views/contents_view.h index ed2abb3..e57a0d2 100644 --- a/ui/app_list/views/contents_view.h +++ b/ui/app_list/views/contents_view.h @@ -65,10 +65,7 @@ class APP_LIST_EXPORT ContentsView : public views::View, void SetDragAndDropHostOfCurrentAppList( ApplicationDragAndDropHost* drag_and_drop_host); - void set_contents_switcher_view( - ContentsSwitcherView* contents_switcher_view) { - contents_switcher_view_ = contents_switcher_view; - } + void SetContentsSwitcherView(ContentsSwitcherView* contents_switcher_view); void ShowSearchResults(bool show); void ShowFolderContent(AppListFolderItem* folder); @@ -110,6 +107,9 @@ class APP_LIST_EXPORT ContentsView : public views::View, virtual void TransitionStarted() OVERRIDE; virtual void TransitionChanged() OVERRIDE; + // Returns the pagination model for the ContentsView. + const PaginationModel& pagination_model() { return pagination_model_; } + private: // Sets the active launcher page, accounting for whether the change is for // search results. |