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

Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=282335

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282586 0039d316-1c4b-4281-b951-d872f2087c98
parent c7ceb96f
...@@ -74,6 +74,10 @@ const int kExperimentalPreferredRows = 3; ...@@ -74,6 +74,10 @@ const int kExperimentalPreferredRows = 3;
// Radius of the circle, in which if entered, show re-order preview. // Radius of the circle, in which if entered, show re-order preview.
const int kReorderDroppingCircleRadius = 35; 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. // Max items allowed in a folder.
size_t kMaxFolderItems = 16; size_t kMaxFolderItems = 16;
......
...@@ -56,6 +56,8 @@ APP_LIST_EXPORT extern const int kExperimentalPreferredRows; ...@@ -56,6 +56,8 @@ APP_LIST_EXPORT extern const int kExperimentalPreferredRows;
APP_LIST_EXPORT extern const int kReorderDroppingCircleRadius; 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 size_t kMaxFolderItems;
APP_LIST_EXPORT extern const size_t kNumFolderTopItems; APP_LIST_EXPORT extern const size_t kNumFolderTopItems;
APP_LIST_EXPORT extern const size_t kMaxFolderNameChars; APP_LIST_EXPORT extern const size_t kMaxFolderNameChars;
......
...@@ -88,7 +88,10 @@ void AppListBackground::Paint(gfx::Canvas* canvas, ...@@ -88,7 +88,10 @@ void AppListBackground::Paint(gfx::Canvas* canvas,
const gfx::Rect contents_view_view_bounds = const gfx::Rect contents_view_view_bounds =
contents_view->ConvertRectToWidget(contents_view->GetLocalBounds()); contents_view->ConvertRectToWidget(contents_view->GetLocalBounds());
gfx::Rect separator_rect(contents_rect); 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); separator_rect.set_height(kBottomSeparatorSize);
canvas->FillRect(separator_rect, kBottomSeparatorColor); canvas->FillRect(separator_rect, kBottomSeparatorColor);
int contents_switcher_top = separator_rect.bottom(); int contents_switcher_top = separator_rect.bottom();
......
...@@ -139,7 +139,7 @@ void AppListMainView::AddContentsViews() { ...@@ -139,7 +139,7 @@ void AppListMainView::AddContentsViews() {
contents_view_ = new ContentsView(this); contents_view_ = new ContentsView(this);
if (app_list::switches::IsExperimentalAppListEnabled()) { if (app_list::switches::IsExperimentalAppListEnabled()) {
contents_switcher_view_ = new ContentsSwitcherView(contents_view_); 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_); contents_view_->InitNamedPages(model_, delegate_);
AddChildView(contents_view_); AddChildView(contents_view_);
......
...@@ -6,17 +6,33 @@ ...@@ -6,17 +6,33 @@
#include "ui/app_list/app_list_constants.h" #include "ui/app_list/app_list_constants.h"
#include "ui/app_list/views/contents_view.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/custom_button.h"
#include "ui/views/controls/button/image_button.h" #include "ui/views/controls/button/image_button.h"
#include "ui/views/layout/box_layout.h" #include "ui/views/layout/box_layout.h"
#include "ui/views/layout/fill_layout.h"
namespace app_list { namespace app_list {
namespace { namespace {
const int kPreferredHeight = 32; const int kButtonImageSize = 32;
const int kButtonSpacing = 4; 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 } // namespace
ContentsSwitcherView::ContentsSwitcherView(ContentsView* contents_view) ContentsSwitcherView::ContentsSwitcherView(ContentsView* contents_view)
...@@ -31,17 +47,42 @@ ContentsSwitcherView::~ContentsSwitcherView() {} ...@@ -31,17 +47,42 @@ ContentsSwitcherView::~ContentsSwitcherView() {}
void ContentsSwitcherView::AddSwitcherButton(int resource_id, int page_index) { void ContentsSwitcherView::AddSwitcherButton(int resource_id, int page_index) {
views::ImageButton* button = new views::ImageButton(this); views::ImageButton* button = new views::ImageButton(this);
button->SetPreferredSize(gfx::Size(kButtonImageSize, kButtonImageSize));
if (resource_id) { if (resource_id) {
button->SetImage( button->SetImage(
views::CustomButton::STATE_NORMAL, views::CustomButton::STATE_NORMAL,
ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id)); ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id));
} }
button->set_tag(page_index); 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 { gfx::Size ContentsSwitcherView::GetPreferredSize() const {
return gfx::Size(buttons_->GetPreferredSize().width(), kPreferredHeight); return gfx::Size(buttons_->GetPreferredSize().width(),
kButtonImageSize + kContentsSwitcherSeparatorHeight);
} }
void ContentsSwitcherView::Layout() { void ContentsSwitcherView::Layout() {
...@@ -61,4 +102,36 @@ void ContentsSwitcherView::ButtonPressed(views::Button* sender, ...@@ -61,4 +102,36 @@ void ContentsSwitcherView::ButtonPressed(views::Button* sender,
contents_view_->SetActivePage(sender->tag()); 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 } // namespace app_list
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define UI_APP_LIST_VIEWS_CONTENTS_SWITCHER_VIEW_H_ #define UI_APP_LIST_VIEWS_CONTENTS_SWITCHER_VIEW_H_
#include "base/basictypes.h" #include "base/basictypes.h"
#include "ui/app_list/pagination_model_observer.h"
#include "ui/views/controls/button/button.h" #include "ui/views/controls/button/button.h"
#include "ui/views/view.h" #include "ui/views/view.h"
...@@ -15,7 +16,9 @@ class ContentsView; ...@@ -15,7 +16,9 @@ class ContentsView;
// A view that contains buttons to switch the displayed view in the given // A view that contains buttons to switch the displayed view in the given
// ContentsView. // ContentsView.
class ContentsSwitcherView : public views::View, public views::ButtonListener { class ContentsSwitcherView : public views::View,
public views::ButtonListener,
public PaginationModelObserver {
public: public:
explicit ContentsSwitcherView(ContentsView* contents_view); explicit ContentsSwitcherView(ContentsView* contents_view);
virtual ~ContentsSwitcherView(); virtual ~ContentsSwitcherView();
...@@ -36,8 +39,16 @@ class ContentsSwitcherView : public views::View, public views::ButtonListener { ...@@ -36,8 +39,16 @@ class ContentsSwitcherView : public views::View, public views::ButtonListener {
virtual void ButtonPressed(views::Button* sender, virtual void ButtonPressed(views::Button* sender,
const ui::Event& event) OVERRIDE; 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. ContentsView* contents_view_; // Owned by views hierarchy.
views::View* buttons_; // 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); DISALLOW_COPY_AND_ASSIGN(ContentsSwitcherView);
}; };
......
...@@ -46,6 +46,8 @@ ContentsView::ContentsView(AppListMainView* app_list_main_view) ...@@ -46,6 +46,8 @@ ContentsView::ContentsView(AppListMainView* app_list_main_view)
ContentsView::~ContentsView() { ContentsView::~ContentsView() {
pagination_model_.RemoveObserver(this); pagination_model_.RemoveObserver(this);
if (contents_switcher_view_)
pagination_model_.RemoveObserver(contents_switcher_view_);
} }
void ContentsView::InitNamedPages(AppListModel* model, void ContentsView::InitNamedPages(AppListModel* model,
...@@ -97,6 +99,14 @@ void ContentsView::SetDragAndDropHostOfCurrentAppList( ...@@ -97,6 +99,14 @@ void ContentsView::SetDragAndDropHostOfCurrentAppList(
apps_container_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); 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) { void ContentsView::SetActivePage(int page_index) {
if (GetActivePageIndex() == page_index) if (GetActivePageIndex() == page_index)
return; return;
...@@ -244,9 +254,9 @@ int ContentsView::AddLauncherPage(views::View* view, int resource_id) { ...@@ -244,9 +254,9 @@ int ContentsView::AddLauncherPage(views::View* view, int resource_id) {
int page_index = view_model_->view_size(); int page_index = view_model_->view_size();
AddChildView(view); AddChildView(view);
view_model_->Add(view, page_index); view_model_->Add(view, page_index);
pagination_model_.SetTotalPages(view_model_->view_size());
if (contents_switcher_view_) if (contents_switcher_view_)
contents_switcher_view_->AddSwitcherButton(resource_id, page_index); contents_switcher_view_->AddSwitcherButton(resource_id, page_index);
pagination_model_.SetTotalPages(view_model_->view_size());
return page_index; return page_index;
} }
......
...@@ -65,10 +65,7 @@ class APP_LIST_EXPORT ContentsView : public views::View, ...@@ -65,10 +65,7 @@ class APP_LIST_EXPORT ContentsView : public views::View,
void SetDragAndDropHostOfCurrentAppList( void SetDragAndDropHostOfCurrentAppList(
ApplicationDragAndDropHost* drag_and_drop_host); ApplicationDragAndDropHost* drag_and_drop_host);
void set_contents_switcher_view( void SetContentsSwitcherView(ContentsSwitcherView* contents_switcher_view);
ContentsSwitcherView* contents_switcher_view) {
contents_switcher_view_ = contents_switcher_view;
}
void ShowSearchResults(bool show); void ShowSearchResults(bool show);
void ShowFolderContent(AppListFolderItem* folder); void ShowFolderContent(AppListFolderItem* folder);
...@@ -110,6 +107,9 @@ class APP_LIST_EXPORT ContentsView : public views::View, ...@@ -110,6 +107,9 @@ class APP_LIST_EXPORT ContentsView : public views::View,
virtual void TransitionStarted() OVERRIDE; virtual void TransitionStarted() OVERRIDE;
virtual void TransitionChanged() OVERRIDE; virtual void TransitionChanged() OVERRIDE;
// Returns the pagination model for the ContentsView.
const PaginationModel& pagination_model() { return pagination_model_; }
private: private:
// Sets the active launcher page, accounting for whether the change is for // Sets the active launcher page, accounting for whether the change is for
// search results. // search results.
......
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