Commit 30f9a0e2 authored by mgiuca's avatar mgiuca Committed by Commit bot

Fixed experimental app list pagination indicator.

Was previously highlighting the wrong page (regressed in r293066) due to
the page indices not starting from 0.

ContentsSwitcherView now uses a map, not a vector, so buttons can have
arbitrary indices.

BUG=411769

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

Cr-Commit-Position: refs/heads/master@{#293884}
parent dba8ee61
......@@ -61,7 +61,7 @@ void ContentsSwitcherView::AddSwitcherButton(int resource_id, int page_index) {
indicator->set_background(
views::Background::CreateSolidBackground(app_list::kPagerSelectedColor));
indicator->SetVisible(false);
page_active_indicators_.push_back(indicator);
page_active_indicators_[page_index] = indicator;
// A container view that will consume space when its child is not visible.
// TODO(calamity): Remove this once BoxLayout supports space-consuming
......@@ -92,12 +92,14 @@ 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);
std::map<int, views::View*>::const_iterator it =
page_active_indicators_.find(old_selected);
if (it != page_active_indicators_.end())
it->second->SetVisible(false);
it = page_active_indicators_.find(new_selected);
if (it != page_active_indicators_.end())
it->second->SetVisible(true);
}
void ContentsSwitcherView::TransitionStarted() {
......
......@@ -5,6 +5,8 @@
#ifndef UI_APP_LIST_VIEWS_CONTENTS_SWITCHER_VIEW_H_
#define UI_APP_LIST_VIEWS_CONTENTS_SWITCHER_VIEW_H_
#include <map>
#include "base/basictypes.h"
#include "ui/app_list/pagination_model_observer.h"
#include "ui/views/controls/button/button.h"
......@@ -43,8 +45,8 @@ class ContentsSwitcherView : public views::View,
ContentsView* contents_view_; // Owned by views hierarchy.
// Stores Views owned by views hierarchy.
std::vector<views::View*> page_active_indicators_;
// Maps page indices to Views owned by views hierarchy.
std::map<int, views::View*> page_active_indicators_;
DISALLOW_COPY_AND_ASSIGN(ContentsSwitcherView);
};
......
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