Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/app_list/views/contents_switcher_view.h" | 5 #include "ui/app_list/views/contents_switcher_view.h" |
| 6 | 6 |
| 7 #include "ui/app_list/app_list_constants.h" | 7 #include "ui/app_list/app_list_constants.h" |
| 8 #include "ui/app_list/views/contents_view.h" | 8 #include "ui/app_list/views/contents_view.h" |
| 9 #include "ui/views/background.h" | |
| 9 #include "ui/views/controls/button/custom_button.h" | 10 #include "ui/views/controls/button/custom_button.h" |
| 10 #include "ui/views/controls/button/image_button.h" | 11 #include "ui/views/controls/button/image_button.h" |
| 11 #include "ui/views/layout/box_layout.h" | 12 #include "ui/views/layout/box_layout.h" |
| 13 #include "ui/views/layout/fill_layout.h" | |
| 12 | 14 |
| 13 namespace app_list { | 15 namespace app_list { |
| 14 | 16 |
| 15 namespace { | 17 namespace { |
| 16 | 18 |
| 17 const int kPreferredHeight = 32; | 19 const int kPageIndicatorHeight = 1; |
| 20 const int kPreferredHeight = 32 + kPageIndicatorHeight; | |
|
calamity
2014/07/09 05:50:19
Pull out 32 into kButtonImageSize.
kcarattini
2014/07/09 06:45:22
Done.
| |
| 18 const int kButtonSpacing = 4; | 21 const int kButtonSpacing = 4; |
| 19 | 22 |
| 23 class ContentsPageIndicatorView : public views::View { | |
| 24 public: | |
| 25 ContentsPageIndicatorView() {}; | |
| 26 virtual ~ContentsPageIndicatorView() {}; | |
| 27 | |
| 28 // Overridden from views::View: | |
| 29 virtual gfx::Size GetPreferredSize() const OVERRIDE { | |
| 30 return gfx::Size(0, kPageIndicatorHeight); | |
| 31 }; | |
| 32 | |
| 33 private: | |
| 34 DISALLOW_COPY_AND_ASSIGN(ContentsPageIndicatorView); | |
| 35 }; | |
| 36 | |
| 20 } // namespace | 37 } // namespace |
| 21 | 38 |
| 22 ContentsSwitcherView::ContentsSwitcherView(ContentsView* contents_view) | 39 ContentsSwitcherView::ContentsSwitcherView(ContentsView* contents_view) |
| 23 : contents_view_(contents_view), buttons_(new views::View) { | 40 : contents_view_(contents_view), buttons_(new views::View) { |
| 24 AddChildView(buttons_); | 41 AddChildView(buttons_); |
| 25 | 42 |
| 26 buttons_->SetLayoutManager(new views::BoxLayout( | 43 buttons_->SetLayoutManager(new views::BoxLayout( |
| 27 views::BoxLayout::kHorizontal, 0, 0, kButtonSpacing)); | 44 views::BoxLayout::kHorizontal, 0, 0, kButtonSpacing)); |
| 28 } | 45 } |
| 29 | 46 |
| 30 ContentsSwitcherView::~ContentsSwitcherView() {} | 47 ContentsSwitcherView::~ContentsSwitcherView() {} |
| 31 | 48 |
| 32 void ContentsSwitcherView::AddSwitcherButton(int resource_id, int page_index) { | 49 void ContentsSwitcherView::AddSwitcherButton(int resource_id, int page_index) { |
| 33 views::ImageButton* button = new views::ImageButton(this); | 50 views::ImageButton* button = new views::ImageButton(this); |
|
calamity
2014/07/09 05:50:18
We should have
button->SetPreferredSize(gfx::Size
kcarattini
2014/07/09 06:45:21
Done.
| |
| 34 if (resource_id) { | 51 if (resource_id) { |
| 35 button->SetImage( | 52 button->SetImage( |
| 36 views::CustomButton::STATE_NORMAL, | 53 views::CustomButton::STATE_NORMAL, |
| 37 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id)); | 54 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id)); |
| 38 } | 55 } |
| 39 button->set_tag(page_index); | 56 button->set_tag(page_index); |
| 40 buttons_->AddChildView(button); | 57 |
| 58 // Add an indicator for the current launcher page. | |
| 59 app_list::ContentsPageIndicatorView* indicator = | |
| 60 new app_list::ContentsPageIndicatorView(); | |
| 61 indicator->set_background( | |
| 62 views::Background::CreateSolidBackground(0, 0, 255)); | |
|
calamity
2014/07/09 05:50:19
Use app_list::kPagerSelectedColor.
kcarattini
2014/07/09 06:45:21
Done.
| |
| 63 indicator->SetFillsBoundsOpaquely(true); | |
|
calamity
2014/07/09 05:50:19
I don't think this does anything. This is an optio
kcarattini
2014/07/09 06:45:22
Done.
| |
| 64 indicator->SetVisible(false); | |
| 65 | |
| 66 views::View* indicator_container = new views::View(); | |
|
calamity
2014/07/09 05:50:19
// A container view that will consume space when i
kcarattini
2014/07/09 06:45:21
Done.
| |
| 67 indicator_container->SetLayoutManager(new views::FillLayout()); | |
| 68 indicator_container->AddChildView(indicator); | |
| 69 | |
| 70 views::View* button_indicator_container = new views::View(); | |
|
calamity
2014/07/09 05:50:19
Maybe button_container? Either way, this should ha
kcarattini
2014/07/09 06:45:22
Done.
| |
| 71 views::BoxLayout* layout_manager = | |
| 72 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); | |
| 73 layout_manager->set_main_axis_alignment( | |
| 74 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); | |
| 75 button_indicator_container->SetLayoutManager(layout_manager); | |
| 76 button_indicator_container->AddChildView(indicator_container); | |
| 77 button_indicator_container->AddChildView(button); | |
| 78 | |
| 79 buttons_->AddChildView(button_indicator_container); | |
| 41 } | 80 } |
| 42 | 81 |
| 43 gfx::Size ContentsSwitcherView::GetPreferredSize() const { | 82 gfx::Size ContentsSwitcherView::GetPreferredSize() const { |
| 44 return gfx::Size(buttons_->GetPreferredSize().width(), kPreferredHeight); | 83 return gfx::Size(buttons_->GetPreferredSize().width(), kPreferredHeight); |
| 45 } | 84 } |
| 46 | 85 |
| 47 void ContentsSwitcherView::Layout() { | 86 void ContentsSwitcherView::Layout() { |
|
calamity
2014/07/09 05:50:18
Ooh, I should update this to use BoxLayout with MA
kcarattini
2014/07/09 06:45:21
Ack. Did you want me to add a TODO for you?
calamity
2014/07/09 08:02:54
Nah, it's cool.
| |
| 48 gfx::Rect rect(GetContentsBounds()); | 87 gfx::Rect rect(GetContentsBounds()); |
| 49 | 88 |
| 50 // Makes |buttons_| horizontally center and vertically fill. | 89 // Makes |buttons_| horizontally center and vertically fill. |
| 51 gfx::Size buttons_size(buttons_->GetPreferredSize()); | 90 gfx::Size buttons_size(buttons_->GetPreferredSize()); |
| 52 gfx::Rect buttons_bounds(rect.CenterPoint().x() - buttons_size.width() / 2, | 91 gfx::Rect buttons_bounds(rect.CenterPoint().x() - buttons_size.width() / 2, |
| 53 rect.y(), | 92 rect.y(), |
| 54 buttons_size.width(), | 93 buttons_size.width(), |
| 55 rect.height()); | 94 rect.height()); |
| 56 buttons_->SetBoundsRect(gfx::IntersectRects(rect, buttons_bounds)); | 95 buttons_->SetBoundsRect(gfx::IntersectRects(rect, buttons_bounds)); |
| 57 } | 96 } |
| 58 | 97 |
| 59 void ContentsSwitcherView::ButtonPressed(views::Button* sender, | 98 void ContentsSwitcherView::ButtonPressed(views::Button* sender, |
| 60 const ui::Event& event) { | 99 const ui::Event& event) { |
| 61 contents_view_->SetActivePage(sender->tag()); | 100 contents_view_->SetActivePage(sender->tag()); |
| 62 } | 101 } |
| 63 | 102 |
| 103 void ContentsSwitcherView::SelectedPageChanged(int old_selected, | |
| 104 int new_selected) { | |
| 105 if (old_selected >= 0 && old_selected < buttons_->child_count()) { | |
| 106 buttons_->child_at(old_selected)->child_at(0)->child_at(0)->SetVisible( | |
| 107 false); | |
| 108 } | |
| 109 if (new_selected >= 0 && new_selected < buttons_->child_count()) { | |
| 110 buttons_->child_at(new_selected)->child_at(0)->child_at(0)->SetVisible( | |
| 111 true); | |
|
calamity
2014/07/09 05:50:18
It would be better to make a private member
// Ow
kcarattini
2014/07/09 06:45:21
Done.
| |
| 112 } | |
| 113 } | |
| 114 | |
| 64 } // namespace app_list | 115 } // namespace app_list |
| OLD | NEW |