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

Unified Diff: ui/app_list/views/start_page_view.cc

Issue 297643002: Add tiles to the experimental app list start page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments, add model observer and tests Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
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 164cee1a58fa59aba9eb2d0864fa07dcb83983e0..59e4e2d8f5716caaa970e18eb7a9a4003f3523f6 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,25 @@ 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(
+ model_(NULL),
+ view_delegate_(view_delegate),
+ instant_container_(new views::View),
+ tiles_container_(new views::View) {
+ 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 ? start_page_web_contents->GetBrowserContext()
: NULL);
@@ -80,13 +101,54 @@ 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) {
+ TileItemView* tile_item = new TileItemView();
+ tiles_container_->AddChildView(tile_item);
+ tile_views_.push_back(tile_item);
+ }
+
+ SetModel(view_delegate_->GetModel());
+ view_delegate->AddObserver(this);
tapted 2014/05/27 05:10:10 nit view_delegate -> view_delegate_, just so it's
calamity 2014/05/27 06:21:08 Done.
}
StartPageView::~StartPageView() {
+ view_delegate_->RemoveObserver(this);
+}
+
+TileItemView* StartPageView::GetTileViewAt(int index) {
+ return static_cast<TileItemView*>(tiles_container_->child_at(index));
tapted 2014/05/27 05:10:10 This can probably use |tile_views_| now. Or perhap
calamity 2014/05/27 06:21:08 Done.
+}
+
+void StartPageView::SetModel(AppListModel* model) {
+ if (model_)
tapted 2014/05/27 05:10:10 nit: maybe DCHECK(model); before this, since this
calamity 2014/05/27 06:21:08 Done.
+ model_->RemoveObserver(this);
+ model_ = model;
+ model_->AddObserver(this);
+ Reset();
}
void StartPageView::Reset() {
instant_container_->SetVisible(true);
+ AppListModel* model = model_;
tapted 2014/05/27 05:10:10 nit: I don't think you need this temporary
calamity 2014/05/27 06:21:08 Done.
+ 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();
}
void StartPageView::ButtonPressed(views::Button* sender,
@@ -95,4 +157,24 @@ void StartPageView::ButtonPressed(views::Button* sender,
instant_container_->SetVisible(false);
}
+void StartPageView::OnProfilesChanged() {
+ SetModel(view_delegate_->GetModel());
+}
+
+void StartPageView::OnAppListModelStatusChanged() {
+ Reset();
+}
+
+void StartPageView::OnAppListItemAdded(AppListItem* item) {
+ Reset();
+}
+
+void StartPageView::OnAppListItemDeleted() {
+ Reset();
+}
+
+void StartPageView::OnAppListItemUpdated(AppListItem* item) {
+ Reset();
+}
+
} // namespace app_list

Powered by Google App Engine
This is Rietveld 408576698