Skip to content

Commit

Permalink
Experimental app list: Added a current page indicator to the launcher.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kcarattini@chromium.org committed Jul 11, 2014
1 parent c7ceb96 commit 6c4617f
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 11 deletions.
4 changes: 4 additions & 0 deletions ui/app_list/app_list_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions ui/app_list/app_list_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion ui/app_list/views/app_list_background.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion ui/app_list/views/app_list_main_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
Expand Down
79 changes: 76 additions & 3 deletions ui/app_list/views/contents_switcher_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,33 @@

#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 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)
Expand All @@ -31,17 +47,42 @@ 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 {
return gfx::Size(buttons_->GetPreferredSize().width(), kPreferredHeight);
return gfx::Size(buttons_->GetPreferredSize().width(),
kButtonImageSize + kContentsSwitcherSeparatorHeight);
}

void ContentsSwitcherView::Layout() {
Expand All @@ -61,4 +102,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
13 changes: 12 additions & 1 deletion ui/app_list/views/contents_switcher_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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();
Expand All @@ -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);
};
Expand Down
12 changes: 11 additions & 1 deletion ui/app_list/views/contents_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
8 changes: 4 additions & 4 deletions ui/app_list/views/contents_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 6c4617f

Please sign in to comment.