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

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

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

Powered by Google App Engine
This is Rietveld 408576698