Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(277)

Side by Side Diff: ui/app_list/views/contents_switcher_view.cc

Issue 384803003: Revert of Experimental app list: Added a current page indicator to the launcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/app_list/views/contents_switcher_view.h ('k') | ui/app_list/views/contents_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
10 #include "ui/views/controls/button/custom_button.h" 9 #include "ui/views/controls/button/custom_button.h"
11 #include "ui/views/controls/button/image_button.h" 10 #include "ui/views/controls/button/image_button.h"
12 #include "ui/views/layout/box_layout.h" 11 #include "ui/views/layout/box_layout.h"
13 #include "ui/views/layout/fill_layout.h"
14 12
15 namespace app_list { 13 namespace app_list {
16 14
17 namespace { 15 namespace {
18 16
19 const int kButtonImageSize = 32; 17 const int kPreferredHeight = 32;
20 const int kPreferredHeight =
21 kButtonImageSize + kContentsSwitcherSeparatorHeight;
22 const int kButtonSpacing = 4; 18 const int kButtonSpacing = 4;
23 19
24 class ContentsPageIndicatorView : public views::View {
25 public:
26 ContentsPageIndicatorView() {};
27 virtual ~ContentsPageIndicatorView() {};
28
29 // Overridden from views::View:
30 virtual gfx::Size GetPreferredSize() const OVERRIDE {
31 return gfx::Size(0, kContentsSwitcherSeparatorHeight);
32 };
33
34 private:
35 DISALLOW_COPY_AND_ASSIGN(ContentsPageIndicatorView);
36 };
37
38 } // namespace 20 } // namespace
39 21
40 ContentsSwitcherView::ContentsSwitcherView(ContentsView* contents_view) 22 ContentsSwitcherView::ContentsSwitcherView(ContentsView* contents_view)
41 : contents_view_(contents_view), buttons_(new views::View) { 23 : contents_view_(contents_view), buttons_(new views::View) {
42 AddChildView(buttons_); 24 AddChildView(buttons_);
43 25
44 buttons_->SetLayoutManager(new views::BoxLayout( 26 buttons_->SetLayoutManager(new views::BoxLayout(
45 views::BoxLayout::kHorizontal, 0, 0, kButtonSpacing)); 27 views::BoxLayout::kHorizontal, 0, 0, kButtonSpacing));
46 } 28 }
47 29
48 ContentsSwitcherView::~ContentsSwitcherView() {} 30 ContentsSwitcherView::~ContentsSwitcherView() {}
49 31
50 void ContentsSwitcherView::AddSwitcherButton(int resource_id, int page_index) { 32 void ContentsSwitcherView::AddSwitcherButton(int resource_id, int page_index) {
51 views::ImageButton* button = new views::ImageButton(this); 33 views::ImageButton* button = new views::ImageButton(this);
52 button->SetPreferredSize(gfx::Size(kButtonImageSize, kButtonImageSize));
53 if (resource_id) { 34 if (resource_id) {
54 button->SetImage( 35 button->SetImage(
55 views::CustomButton::STATE_NORMAL, 36 views::CustomButton::STATE_NORMAL,
56 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id)); 37 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id));
57 } 38 }
58 button->set_tag(page_index); 39 button->set_tag(page_index);
59 40 buttons_->AddChildView(button);
60 // Add an indicator for the current launcher page.
61 app_list::ContentsPageIndicatorView* indicator =
62 new app_list::ContentsPageIndicatorView();
63 indicator->set_background(
64 views::Background::CreateSolidBackground(app_list::kPagerSelectedColor));
65 indicator->SetVisible(false);
66 page_active_indicators_.push_back(indicator);
67
68 // A container view that will consume space when its child is not visible.
69 // TODO(calamity): Remove this once BoxLayout supports space-consuming
70 // invisible views.
71 views::View* indicator_container = new views::View();
72 indicator_container->SetLayoutManager(new views::FillLayout());
73 indicator_container->AddChildView(indicator);
74
75 // View containing the indicator view and image button.
76 views::View* button_container = new views::View();
77 button_container->SetLayoutManager(
78 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
79 button_container->AddChildView(indicator_container);
80 button_container->AddChildView(button);
81
82 buttons_->AddChildView(button_container);
83 } 41 }
84 42
85 gfx::Size ContentsSwitcherView::GetPreferredSize() const { 43 gfx::Size ContentsSwitcherView::GetPreferredSize() const {
86 return gfx::Size(buttons_->GetPreferredSize().width(), kPreferredHeight); 44 return gfx::Size(buttons_->GetPreferredSize().width(), kPreferredHeight);
87 } 45 }
88 46
89 void ContentsSwitcherView::Layout() { 47 void ContentsSwitcherView::Layout() {
90 gfx::Rect rect(GetContentsBounds()); 48 gfx::Rect rect(GetContentsBounds());
91 49
92 // Makes |buttons_| horizontally center and vertically fill. 50 // Makes |buttons_| horizontally center and vertically fill.
93 gfx::Size buttons_size(buttons_->GetPreferredSize()); 51 gfx::Size buttons_size(buttons_->GetPreferredSize());
94 gfx::Rect buttons_bounds(rect.CenterPoint().x() - buttons_size.width() / 2, 52 gfx::Rect buttons_bounds(rect.CenterPoint().x() - buttons_size.width() / 2,
95 rect.y(), 53 rect.y(),
96 buttons_size.width(), 54 buttons_size.width(),
97 rect.height()); 55 rect.height());
98 buttons_->SetBoundsRect(gfx::IntersectRects(rect, buttons_bounds)); 56 buttons_->SetBoundsRect(gfx::IntersectRects(rect, buttons_bounds));
99 } 57 }
100 58
101 void ContentsSwitcherView::ButtonPressed(views::Button* sender, 59 void ContentsSwitcherView::ButtonPressed(views::Button* sender,
102 const ui::Event& event) { 60 const ui::Event& event) {
103 contents_view_->SetActivePage(sender->tag()); 61 contents_view_->SetActivePage(sender->tag());
104 } 62 }
105 63
106 void ContentsSwitcherView::TotalPagesChanged() {
107 }
108
109 void ContentsSwitcherView::SelectedPageChanged(int old_selected,
110 int new_selected) {
111 // Makes the indicator visible when it is first drawn and when the
112 // selected page is changed.
113 int num_indicators = static_cast<int>(page_active_indicators_.size());
114 if (old_selected >= 0 && old_selected < num_indicators)
115 page_active_indicators_[old_selected]->SetVisible(false);
116
117 if (new_selected >= 0 && new_selected < num_indicators)
118 page_active_indicators_[new_selected]->SetVisible(true);
119 }
120
121 void ContentsSwitcherView::TransitionStarted() {
122 }
123
124 void ContentsSwitcherView::TransitionChanged() {
125 // Change the indicator during a launcher page transition.
126 const PaginationModel& pm = contents_view_->pagination_model();
127 int old_selected = pm.selected_page();
128 int new_selected = pm.transition().target_page;
129 if (pm.IsRevertingCurrentTransition()) {
130 // Swap the direction if the transition is reversed.
131 old_selected = pm.transition().target_page;
132 new_selected = pm.selected_page();
133 }
134
135 SelectedPageChanged(old_selected, new_selected);
136 }
137
138 } // namespace app_list 64 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/views/contents_switcher_view.h ('k') | ui/app_list/views/contents_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698