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
3 // found in the LICENSE file.
4
5 #include "ui/app_list/views/contents_switcher_view.h"
6
7 #include "ui/app_list/views/contents_view.h"
8 #include "ui/base/resource/resource_bundle.h"
9 #include "ui/views/controls/button/custom_button.h"
10 #include "ui/views/controls/button/image_button.h"
11 #include "ui/views/layout/box_layout.h"
12
13 namespace app_list {
14
15 namespace {
16
17 const int kButtonSpacing = 4;
18 const int kMinimumHeight = 39;
19
20 } // namespace
21
ContentsSwitcherView(ContentsView * contents_view)22 ContentsSwitcherView::ContentsSwitcherView(ContentsView* contents_view)
23 : contents_view_(contents_view) {
24 views::BoxLayout* layout = new views::BoxLayout(
25 views::BoxLayout::kHorizontal, 0, 0, kButtonSpacing);
26 layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER);
27 layout->set_minimum_cross_axis_size(kMinimumHeight);
28 SetLayoutManager(layout);
29 }
30
~ContentsSwitcherView()31 ContentsSwitcherView::~ContentsSwitcherView() {}
32
AddSwitcherButton(int resource_id,int page_index)33 void ContentsSwitcherView::AddSwitcherButton(int resource_id, int page_index) {
34 views::ImageButton* button = new views::ImageButton(this);
35 button->SetMinimumImageSize(gfx::Size(kMinimumHeight, kMinimumHeight));
36 button->SetImageAlignment(views::ImageButton::ALIGN_CENTER,
37 views::ImageButton::ALIGN_MIDDLE);
38 button->SetImage(
39 views::CustomButton::STATE_NORMAL,
40 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id));
41 button->set_tag(page_index);
42
43 AddChildView(button);
44 }
45
ButtonPressed(views::Button * sender,const ui::Event & event)46 void ContentsSwitcherView::ButtonPressed(views::Button* sender,
47 const ui::Event& event) {
48 contents_view_->SetActivePage(sender->tag());
49 }
50
TotalPagesChanged()51 void ContentsSwitcherView::TotalPagesChanged() {
52 }
53
SelectedPageChanged(int old_selected,int new_selected)54 void ContentsSwitcherView::SelectedPageChanged(int old_selected,
55 int new_selected) {
56 // TODO(mgiuca): Visually indicate which page is now selected.
57 }
58
TransitionStarted()59 void ContentsSwitcherView::TransitionStarted() {
60 }
61
TransitionChanged()62 void ContentsSwitcherView::TransitionChanged() {
63 // Change the indicator during a launcher page transition.
64 const PaginationModel& pm = contents_view_->pagination_model();
65 int old_selected = pm.selected_page();
66 int new_selected = pm.transition().target_page;
67 if (pm.IsRevertingCurrentTransition()) {
68 // Swap the direction if the transition is reversed.
69 old_selected = pm.transition().target_page;
70 new_selected = pm.selected_page();
71 }
72
73 SelectedPageChanged(old_selected, new_selected);
74 }
75
76 } // namespace app_list
77