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/background.h" |
10 #include "ui/views/controls/button/custom_button.h" | 10 #include "ui/views/controls/button/custom_button.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 return gfx::Size(0, kContentsSwitcherSeparatorHeight); | 29 return gfx::Size(0, kContentsSwitcherSeparatorHeight); |
30 }; | 30 }; |
31 | 31 |
32 private: | 32 private: |
33 DISALLOW_COPY_AND_ASSIGN(ContentsPageIndicatorView); | 33 DISALLOW_COPY_AND_ASSIGN(ContentsPageIndicatorView); |
34 }; | 34 }; |
35 | 35 |
36 } // namespace | 36 } // namespace |
37 | 37 |
38 ContentsSwitcherView::ContentsSwitcherView(ContentsView* contents_view) | 38 ContentsSwitcherView::ContentsSwitcherView(ContentsView* contents_view) |
39 : contents_view_(contents_view), buttons_(new views::View) { | 39 : contents_view_(contents_view) { |
40 AddChildView(buttons_); | 40 views::BoxLayout* layout = new views::BoxLayout( |
41 | 41 views::BoxLayout::kHorizontal, 0, 0, kButtonSpacing); |
42 buttons_->SetLayoutManager(new views::BoxLayout( | 42 layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); |
43 views::BoxLayout::kHorizontal, 0, 0, kButtonSpacing)); | 43 SetLayoutManager(layout); |
44 } | 44 } |
45 | 45 |
46 ContentsSwitcherView::~ContentsSwitcherView() {} | 46 ContentsSwitcherView::~ContentsSwitcherView() {} |
47 | 47 |
48 void ContentsSwitcherView::AddSwitcherButton(int resource_id, int page_index) { | 48 void ContentsSwitcherView::AddSwitcherButton(int resource_id, int page_index) { |
49 views::ImageButton* button = new views::ImageButton(this); | 49 views::ImageButton* button = new views::ImageButton(this); |
50 button->SetPreferredSize(gfx::Size(kButtonImageSize, kButtonImageSize)); | 50 button->SetPreferredSize(gfx::Size(kButtonImageSize, kButtonImageSize)); |
51 if (resource_id) { | 51 if (resource_id) { |
52 button->SetImage( | 52 button->SetImage( |
53 views::CustomButton::STATE_NORMAL, | 53 views::CustomButton::STATE_NORMAL, |
(...skipping 16 matching lines...) Expand all Loading... |
70 indicator_container->SetLayoutManager(new views::FillLayout()); | 70 indicator_container->SetLayoutManager(new views::FillLayout()); |
71 indicator_container->AddChildView(indicator); | 71 indicator_container->AddChildView(indicator); |
72 | 72 |
73 // View containing the indicator view and image button. | 73 // View containing the indicator view and image button. |
74 views::View* button_container = new views::View(); | 74 views::View* button_container = new views::View(); |
75 button_container->SetLayoutManager( | 75 button_container->SetLayoutManager( |
76 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 76 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
77 button_container->AddChildView(indicator_container); | 77 button_container->AddChildView(indicator_container); |
78 button_container->AddChildView(button); | 78 button_container->AddChildView(button); |
79 | 79 |
80 buttons_->AddChildView(button_container); | 80 AddChildView(button_container); |
81 } | |
82 | |
83 gfx::Size ContentsSwitcherView::GetPreferredSize() const { | |
84 return gfx::Size(buttons_->GetPreferredSize().width(), | |
85 kButtonImageSize + kContentsSwitcherSeparatorHeight); | |
86 } | |
87 | |
88 void ContentsSwitcherView::Layout() { | |
89 gfx::Rect rect(GetContentsBounds()); | |
90 | |
91 // Makes |buttons_| horizontally center and vertically fill. | |
92 gfx::Size buttons_size(buttons_->GetPreferredSize()); | |
93 gfx::Rect buttons_bounds(rect.CenterPoint().x() - buttons_size.width() / 2, | |
94 rect.y(), | |
95 buttons_size.width(), | |
96 rect.height()); | |
97 buttons_->SetBoundsRect(gfx::IntersectRects(rect, buttons_bounds)); | |
98 } | 81 } |
99 | 82 |
100 void ContentsSwitcherView::ButtonPressed(views::Button* sender, | 83 void ContentsSwitcherView::ButtonPressed(views::Button* sender, |
101 const ui::Event& event) { | 84 const ui::Event& event) { |
102 contents_view_->SetActivePage(sender->tag()); | 85 contents_view_->SetActivePage(sender->tag()); |
103 } | 86 } |
104 | 87 |
105 void ContentsSwitcherView::TotalPagesChanged() { | 88 void ContentsSwitcherView::TotalPagesChanged() { |
106 } | 89 } |
107 | 90 |
(...skipping 20 matching lines...) Expand all Loading... |
128 if (pm.IsRevertingCurrentTransition()) { | 111 if (pm.IsRevertingCurrentTransition()) { |
129 // Swap the direction if the transition is reversed. | 112 // Swap the direction if the transition is reversed. |
130 old_selected = pm.transition().target_page; | 113 old_selected = pm.transition().target_page; |
131 new_selected = pm.selected_page(); | 114 new_selected = pm.selected_page(); |
132 } | 115 } |
133 | 116 |
134 SelectedPageChanged(old_selected, new_selected); | 117 SelectedPageChanged(old_selected, new_selected); |
135 } | 118 } |
136 | 119 |
137 } // namespace app_list | 120 } // namespace app_list |
OLD | NEW |