Index: ui/app_list/views/contents_switcher_view.cc |
diff --git a/ui/app_list/views/contents_switcher_view.cc b/ui/app_list/views/contents_switcher_view.cc |
index 95669439fdb2f06df7d6ed6533d0e8d832cb101b..03f0d6383651df6ef50ea00fff88e8f306b6c668 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 kPageIndicatorHeight = 1; |
+const int kButtonImageSize = 32; |
+const int kPreferredHeight = kButtonImageSize + kPageIndicatorHeight; |
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, kPageIndicatorHeight); |
+ }; |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(ContentsPageIndicatorView); |
+}; |
+ |
} // namespace |
ContentsSwitcherView::ContentsSwitcherView(ContentsView* contents_view) |
@@ -31,13 +49,40 @@ 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(); |
+ views::BoxLayout* layout_manager = |
+ new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); |
+ layout_manager->set_main_axis_alignment( |
+ views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); |
+ button_container->SetLayoutManager(layout_manager); |
+ button_container->AddChildView(indicator_container); |
+ button_container->AddChildView(button); |
+ |
+ buttons_->AddChildView(button_container); |
} |
gfx::Size ContentsSwitcherView::GetPreferredSize() const { |
@@ -61,4 +106,40 @@ 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 at the beginning of the transition animation. |
+ const PaginationModel& pm = contents_view_->pagination_model(); |
+ int old_selected = pm.selected_page(); |
+ int new_selected = pm.transition().target_page; |
+ if (pm.IsRevertingCurrentTransition()) { |
+ old_selected = pm.transition().target_page; |
+ new_selected = pm.selected_page(); |
+ } |
+ 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); |
+} |
+ |
} // namespace app_list |