| 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 "grit/ui_resources.h" | |
| 8 #include "ui/app_list/app_list_constants.h" | 7 #include "ui/app_list/app_list_constants.h" |
| 9 #include "ui/app_list/views/contents_view.h" | 8 #include "ui/app_list/views/contents_view.h" |
| 10 #include "ui/base/resource/resource_bundle.h" | |
| 11 #include "ui/views/controls/button/custom_button.h" | 9 #include "ui/views/controls/button/custom_button.h" |
| 12 #include "ui/views/controls/button/image_button.h" | 10 #include "ui/views/controls/button/image_button.h" |
| 13 #include "ui/views/layout/box_layout.h" | 11 #include "ui/views/layout/box_layout.h" |
| 14 | 12 |
| 15 namespace app_list { | 13 namespace app_list { |
| 16 | 14 |
| 17 namespace { | 15 namespace { |
| 18 | 16 |
| 19 const int kPreferredHeight = 32; | 17 const int kPreferredHeight = 32; |
| 20 const int kButtonSpacing = 4; | 18 const int kButtonSpacing = 4; |
| 21 | 19 |
| 22 } // namespace | 20 } // namespace |
| 23 | 21 |
| 24 ContentsSwitcherView::ContentsSwitcherView(ContentsView* contents_view) | 22 ContentsSwitcherView::ContentsSwitcherView(ContentsView* contents_view) |
| 25 : contents_view_(contents_view), buttons_(new views::View) { | 23 : contents_view_(contents_view), buttons_(new views::View) { |
| 26 AddChildView(buttons_); | 24 AddChildView(buttons_); |
| 27 | 25 |
| 28 buttons_->SetLayoutManager(new views::BoxLayout( | 26 buttons_->SetLayoutManager(new views::BoxLayout( |
| 29 views::BoxLayout::kHorizontal, 0, 0, kButtonSpacing)); | 27 views::BoxLayout::kHorizontal, 0, 0, kButtonSpacing)); |
| 30 // TODO(mgiuca): Dynamically generate these buttons from the subviews of | |
| 31 // |contents_view|. | |
| 32 AddSwitcherButton( | |
| 33 IDR_APP_LIST_SEARCH_ICON, | |
| 34 contents_view->GetPageIndexForNamedPage(ContentsView::NAMED_PAGE_START)); | |
| 35 AddSwitcherButton( | |
| 36 IDR_APP_LIST_APPS_ICON, | |
| 37 contents_view->GetPageIndexForNamedPage(ContentsView::NAMED_PAGE_APPS)); | |
| 38 } | 28 } |
| 39 | 29 |
| 40 ContentsSwitcherView::~ContentsSwitcherView() {} | 30 ContentsSwitcherView::~ContentsSwitcherView() {} |
| 41 | 31 |
| 42 void ContentsSwitcherView::AddSwitcherButton(int resource_id, int page_index) { | 32 void ContentsSwitcherView::AddSwitcherButton(int resource_id, int page_index) { |
| 43 views::ImageButton* button = new views::ImageButton(this); | 33 views::ImageButton* button = new views::ImageButton(this); |
| 44 button->SetImage( | 34 if (resource_id) { |
| 45 views::CustomButton::STATE_NORMAL, | 35 button->SetImage( |
| 46 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id)); | 36 views::CustomButton::STATE_NORMAL, |
| 37 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id)); |
| 38 } |
| 47 button->set_tag(page_index); | 39 button->set_tag(page_index); |
| 48 buttons_->AddChildView(button); | 40 buttons_->AddChildView(button); |
| 49 } | 41 } |
| 50 | 42 |
| 51 gfx::Size ContentsSwitcherView::GetPreferredSize() const { | 43 gfx::Size ContentsSwitcherView::GetPreferredSize() const { |
| 52 return gfx::Size(buttons_->GetPreferredSize().width(), kPreferredHeight); | 44 return gfx::Size(buttons_->GetPreferredSize().width(), kPreferredHeight); |
| 53 } | 45 } |
| 54 | 46 |
| 55 void ContentsSwitcherView::Layout() { | 47 void ContentsSwitcherView::Layout() { |
| 56 gfx::Rect rect(GetContentsBounds()); | 48 gfx::Rect rect(GetContentsBounds()); |
| 57 | 49 |
| 58 // Makes |buttons_| horizontally center and vertically fill. | 50 // Makes |buttons_| horizontally center and vertically fill. |
| 59 gfx::Size buttons_size(buttons_->GetPreferredSize()); | 51 gfx::Size buttons_size(buttons_->GetPreferredSize()); |
| 60 gfx::Rect buttons_bounds(rect.CenterPoint().x() - buttons_size.width() / 2, | 52 gfx::Rect buttons_bounds(rect.CenterPoint().x() - buttons_size.width() / 2, |
| 61 rect.y(), | 53 rect.y(), |
| 62 buttons_size.width(), | 54 buttons_size.width(), |
| 63 rect.height()); | 55 rect.height()); |
| 64 buttons_->SetBoundsRect(gfx::IntersectRects(rect, buttons_bounds)); | 56 buttons_->SetBoundsRect(gfx::IntersectRects(rect, buttons_bounds)); |
| 65 } | 57 } |
| 66 | 58 |
| 67 void ContentsSwitcherView::ButtonPressed(views::Button* sender, | 59 void ContentsSwitcherView::ButtonPressed(views::Button* sender, |
| 68 const ui::Event& event) { | 60 const ui::Event& event) { |
| 69 contents_view_->SetActivePage(sender->tag()); | 61 contents_view_->SetActivePage(sender->tag()); |
| 70 } | 62 } |
| 71 | 63 |
| 72 } // namespace app_list | 64 } // namespace app_list |
| OLD | NEW |