Chromium Code Reviews| Index: ui/app_list/views/contents_switcher_view.cc |
| diff --git a/ui/app_list/views/contents_switcher_view.cc b/ui/app_list/views/contents_switcher_view.cc |
| index 994a1fe5e44af71398c266ce9cde0d448097a50f..1d114aeb37c9193b7b158a6c25699058f36f681c 100644 |
| --- a/ui/app_list/views/contents_switcher_view.cc |
| +++ b/ui/app_list/views/contents_switcher_view.cc |
| @@ -4,10 +4,8 @@ |
| #include "ui/app_list/views/contents_switcher_view.h" |
| -#include "grit/ui_resources.h" |
| #include "ui/app_list/app_list_constants.h" |
| #include "ui/app_list/views/contents_view.h" |
| -#include "ui/base/resource/resource_bundle.h" |
| #include "ui/views/controls/button/custom_button.h" |
| #include "ui/views/controls/button/image_button.h" |
| #include "ui/views/layout/box_layout.h" |
| @@ -21,29 +19,29 @@ const int kButtonSpacing = 4; |
| } // namespace |
| -ContentsSwitcherView::ContentsSwitcherView(ContentsView* contents_view) |
| - : contents_view_(contents_view), buttons_(new views::View) { |
| +ContentsSwitcherView::ContentsSwitcherView() |
| + : contents_view_(NULL), buttons_(new views::View) { |
| AddChildView(buttons_); |
| buttons_->SetLayoutManager(new views::BoxLayout( |
| views::BoxLayout::kHorizontal, 0, 0, kButtonSpacing)); |
| - // TODO(mgiuca): Dynamically generate these buttons from the subviews of |
| - // |contents_view|. |
| - AddSwitcherButton( |
| - IDR_APP_LIST_SEARCH_ICON, |
| - contents_view->GetPageIndexForNamedPage(ContentsView::NAMED_PAGE_START)); |
| - AddSwitcherButton( |
| - IDR_APP_LIST_APPS_ICON, |
| - contents_view->GetPageIndexForNamedPage(ContentsView::NAMED_PAGE_APPS)); |
| } |
| ContentsSwitcherView::~ContentsSwitcherView() {} |
| +void ContentsSwitcherView::Init(ContentsView* contents_view) { |
| + contents_view_ = contents_view; |
| +} |
| + |
| void ContentsSwitcherView::AddSwitcherButton(int resource_id, int page_index) { |
| + // Must not be NULL at this point, because it might trigger ButtonPressed(). |
| + DCHECK(contents_view_); |
| + |
| views::ImageButton* button = new views::ImageButton(this); |
| - button->SetImage( |
| - views::CustomButton::STATE_NORMAL, |
| - ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id)); |
| + if (resource_id) |
|
calamity
2014/06/18 05:22:29
nit: Braces around multiline statement.
Matt Giuca
2014/06/18 06:47:02
Done.
|
| + button->SetImage( |
| + views::CustomButton::STATE_NORMAL, |
| + ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id)); |
| button->set_tag(page_index); |
| buttons_->AddChildView(button); |
| } |