Chromium Code Reviews| Index: ui/app_list/views/start_page_view.cc |
| diff --git a/ui/app_list/views/start_page_view.cc b/ui/app_list/views/start_page_view.cc |
| index e1c0e2f40538521edc6a71f6b49ddc63a214d37c..c9737087c781913ed284049b5298f8c516ac5da6 100644 |
| --- a/ui/app_list/views/start_page_view.cc |
| +++ b/ui/app_list/views/start_page_view.cc |
| @@ -4,11 +4,18 @@ |
| #include "ui/app_list/views/start_page_view.h" |
| +#include "base/strings/utf_string_conversions.h" |
| #include "content/public/browser/web_contents.h" |
| #include "ui/app_list/app_list_constants.h" |
| +#include "ui/app_list/app_list_item.h" |
| +#include "ui/app_list/app_list_model.h" |
| +#include "ui/app_list/app_list_view_delegate.h" |
| #include "ui/app_list/views/app_list_main_view.h" |
| +#include "ui/app_list/views/tile_item_view.h" |
| #include "ui/gfx/canvas.h" |
| #include "ui/views/controls/button/custom_button.h" |
| +#include "ui/views/controls/image_view.h" |
| +#include "ui/views/controls/label.h" |
| #include "ui/views/controls/webview/webview.h" |
| #include "ui/views/layout/box_layout.h" |
| @@ -16,15 +23,18 @@ namespace app_list { |
| namespace { |
| -const int kTopMargin = 20; |
| +const int kTopMargin = 30; |
| const int kWebViewWidth = 200; |
| -const int kWebViewHeight = 95; |
| +const int kWebViewHeight = 105; |
| -const int kInstantContainerSpacing = 15; |
| -const int kBarPlaceholderWidth = 350; |
| +const int kInstantContainerSpacing = 20; |
| +const int kBarPlaceholderWidth = 490; |
| const int kBarPlaceholderHeight = 30; |
| +const size_t kNumStartPageTiles = 5; |
| +const int kTileSpacing = 10; |
| + |
| // A button that is the placeholder for the search bar in the start page view. |
| class BarPlaceholderButton : public views::CustomButton { |
| public: |
| @@ -64,14 +74,26 @@ class BarPlaceholderButton : public views::CustomButton { |
| } // namespace |
| StartPageView::StartPageView(AppListMainView* app_list_main_view, |
| - content::WebContents* start_page_web_contents) |
| + AppListViewDelegate* view_delegate) |
| : app_list_main_view_(app_list_main_view), |
| - instant_container_(new views::View) { |
| - AddChildView(instant_container_); |
| - SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
| - instant_container_->SetLayoutManager(new views::BoxLayout( |
| + view_delegate_(view_delegate), |
| + instant_container_(new views::View), |
| + tiles_container_(new views::View) { |
| + view_delegate->AddObserver(this); |
| + |
| + SetLayoutManager(new views::BoxLayout( |
| views::BoxLayout::kVertical, 0, kTopMargin, kInstantContainerSpacing)); |
| + // The view containing the start page WebContents and the BarPlaceholder. |
| + AddChildView(instant_container_); |
| + views::BoxLayout* instant_layout_manager = new views::BoxLayout( |
| + views::BoxLayout::kVertical, 0, 0, kInstantContainerSpacing); |
| + instant_layout_manager->set_main_axis_alignment( |
| + views::BoxLayout::MAIN_AXIS_ALIGNMENT_END); |
| + instant_container_->SetLayoutManager(instant_layout_manager); |
| + |
| + content::WebContents* start_page_web_contents = |
| + view_delegate->GetStartPageContents(); |
| views::WebView* web_view = |
| new views::WebView(start_page_web_contents->GetBrowserContext()); |
| web_view->SetPreferredSize(gfx::Size(kWebViewWidth, kWebViewHeight)); |
| @@ -79,13 +101,42 @@ StartPageView::StartPageView(AppListMainView* app_list_main_view, |
| instant_container_->AddChildView(web_view); |
| instant_container_->AddChildView(new BarPlaceholderButton(this)); |
| + |
| + // The view containing the start page tiles. |
| + AddChildView(tiles_container_); |
| + views::BoxLayout* tiles_layout_manager = |
| + new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, kTileSpacing); |
| + tiles_layout_manager->set_main_axis_alignment( |
| + views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); |
| + tiles_container_->SetLayoutManager(tiles_layout_manager); |
| + for (size_t i = 0; i < kNumStartPageTiles; ++i) |
| + tiles_container_->AddChildView(new TileItemView()); |
| + |
| + Reset(); |
| } |
| StartPageView::~StartPageView() { |
| + view_delegate_->RemoveObserver(this); |
| +} |
| + |
| +TileItemView* StartPageView::GetTileViewAt(int index) { |
| + return static_cast<TileItemView*>(tiles_container_->child_at(index)); |
| } |
| void StartPageView::Reset() { |
| instant_container_->SetVisible(true); |
| + AppListModel* model = view_delegate_->GetModel(); |
| + if (!model || !model->top_level_item_list()) |
| + return; |
| + |
| + for (size_t i = 0; i < kNumStartPageTiles; ++i) { |
| + AppListItem* item = NULL; |
| + if (i < model->top_level_item_list()->item_count()) |
| + item = model->top_level_item_list()->item_at(i); |
| + GetTileViewAt(i)->SetAppListItem(item); |
| + } |
| + |
| + Layout(); |
|
tapted
2014/05/22 04:56:11
I'm guessing this will left-align tiles when there
calamity
2014/05/27 04:29:11
This center aligns due to BOX_ALIGN_CENTER. To cha
|
| } |
| void StartPageView::ButtonPressed(views::Button* sender, |
| @@ -94,4 +145,8 @@ void StartPageView::ButtonPressed(views::Button* sender, |
| instant_container_->SetVisible(false); |
| } |
| +void StartPageView::OnProfilesChanged() { |
| + Reset(); |
| +} |
| + |
| } // namespace app_list |