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.
5 #include "ui/app_list/views/contents_switcher_view.h"
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"
17 const int kButtonSpacing = 4;
18 const int kMinimumHeight = 40;
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);
31 ContentsSwitcherView::~ContentsSwitcherView() {}
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);
39 views::CustomButton::STATE_NORMAL,
40 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id));
41 button->set_tag(page_index);
46 void ContentsSwitcherView::ButtonPressed(views::Button* sender,
47 const ui::Event& event) {
48 contents_view_->SetActivePage(sender->tag());
51 void ContentsSwitcherView::TotalPagesChanged() {
54 void ContentsSwitcherView::SelectedPageChanged(int old_selected,
56 // TODO(mgiuca): Visually indicate which page is now selected.
59 void ContentsSwitcherView::TransitionStarted() {
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();
73 SelectedPageChanged(old_selected, new_selected);
76 } // namespace app_list