Chromium Code Reviews| 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..d755b59c4ee60e8f894bbf517eb61a78d8759682 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)); |
|
Matt Giuca
2014/07/09 07:01:20
What does setting this do? (Why is it needed now a
calamity
2014/07/09 08:02:54
It should have been there before. It has no effect
|
| 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,14 @@ void ContentsSwitcherView::ButtonPressed(views::Button* sender, |
| contents_view_->SetActivePage(sender->tag()); |
| } |
| +void ContentsSwitcherView::SelectedPageChanged(int old_selected, |
| + int new_selected) { |
| + 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 |