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

Side by Side 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, 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/start_page_view.h" 5 #include "ui/app_list/views/start_page_view.h"
6 6
7 #include "base/strings/utf_string_conversions.h"
7 #include "content/public/browser/web_contents.h" 8 #include "content/public/browser/web_contents.h"
8 #include "ui/app_list/app_list_constants.h" 9 #include "ui/app_list/app_list_constants.h"
10 #include "ui/app_list/app_list_item.h"
11 #include "ui/app_list/app_list_model.h"
12 #include "ui/app_list/app_list_view_delegate.h"
9 #include "ui/app_list/views/app_list_main_view.h" 13 #include "ui/app_list/views/app_list_main_view.h"
14 #include "ui/app_list/views/tile_item_view.h"
10 #include "ui/gfx/canvas.h" 15 #include "ui/gfx/canvas.h"
11 #include "ui/views/controls/button/custom_button.h" 16 #include "ui/views/controls/button/custom_button.h"
17 #include "ui/views/controls/image_view.h"
18 #include "ui/views/controls/label.h"
12 #include "ui/views/controls/webview/webview.h" 19 #include "ui/views/controls/webview/webview.h"
13 #include "ui/views/layout/box_layout.h" 20 #include "ui/views/layout/box_layout.h"
14 21
15 namespace app_list { 22 namespace app_list {
16 23
17 namespace { 24 namespace {
18 25
19 const int kTopMargin = 20; 26 const int kTopMargin = 30;
20 27
21 const int kWebViewWidth = 200; 28 const int kWebViewWidth = 200;
22 const int kWebViewHeight = 95; 29 const int kWebViewHeight = 105;
23 30
24 const int kInstantContainerSpacing = 15; 31 const int kInstantContainerSpacing = 20;
25 const int kBarPlaceholderWidth = 350; 32 const int kBarPlaceholderWidth = 490;
26 const int kBarPlaceholderHeight = 30; 33 const int kBarPlaceholderHeight = 30;
27 34
35 const size_t kNumStartPageTiles = 5;
36 const int kTileSpacing = 10;
37
28 // A button that is the placeholder for the search bar in the start page view. 38 // A button that is the placeholder for the search bar in the start page view.
29 class BarPlaceholderButton : public views::CustomButton { 39 class BarPlaceholderButton : public views::CustomButton {
30 public: 40 public:
31 explicit BarPlaceholderButton(views::ButtonListener* listener) 41 explicit BarPlaceholderButton(views::ButtonListener* listener)
32 : views::CustomButton(listener) {} 42 : views::CustomButton(listener) {}
33 43
34 virtual ~BarPlaceholderButton() {} 44 virtual ~BarPlaceholderButton() {}
35 45
36 // Overridden from views::View: 46 // Overridden from views::View:
37 virtual gfx::Size GetPreferredSize() OVERRIDE { 47 virtual gfx::Size GetPreferredSize() OVERRIDE {
(...skipping 19 matching lines...) Expand all
57 paint.setColor(base_color); 67 paint.setColor(base_color);
58 canvas->DrawRect(rect, paint); 68 canvas->DrawRect(rect, paint);
59 } 69 }
60 70
61 DISALLOW_COPY_AND_ASSIGN(BarPlaceholderButton); 71 DISALLOW_COPY_AND_ASSIGN(BarPlaceholderButton);
62 }; 72 };
63 73
64 } // namespace 74 } // namespace
65 75
66 StartPageView::StartPageView(AppListMainView* app_list_main_view, 76 StartPageView::StartPageView(AppListMainView* app_list_main_view,
67 content::WebContents* start_page_web_contents) 77 AppListViewDelegate* view_delegate)
68 : app_list_main_view_(app_list_main_view), 78 : app_list_main_view_(app_list_main_view),
69 instant_container_(new views::View) { 79 model_(NULL),
70 AddChildView(instant_container_); 80 view_delegate_(view_delegate),
71 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); 81 instant_container_(new views::View),
72 instant_container_->SetLayoutManager(new views::BoxLayout( 82 tiles_container_(new views::View) {
83 SetLayoutManager(new views::BoxLayout(
73 views::BoxLayout::kVertical, 0, kTopMargin, kInstantContainerSpacing)); 84 views::BoxLayout::kVertical, 0, kTopMargin, kInstantContainerSpacing));
74 85
86 // The view containing the start page WebContents and the BarPlaceholder.
87 AddChildView(instant_container_);
88 views::BoxLayout* instant_layout_manager = new views::BoxLayout(
89 views::BoxLayout::kVertical, 0, 0, kInstantContainerSpacing);
90 instant_layout_manager->set_main_axis_alignment(
91 views::BoxLayout::MAIN_AXIS_ALIGNMENT_END);
92 instant_container_->SetLayoutManager(instant_layout_manager);
93
94 content::WebContents* start_page_web_contents =
95 view_delegate->GetStartPageContents();
75 views::WebView* web_view = new views::WebView( 96 views::WebView* web_view = new views::WebView(
76 start_page_web_contents ? start_page_web_contents->GetBrowserContext() 97 start_page_web_contents ? start_page_web_contents->GetBrowserContext()
77 : NULL); 98 : NULL);
78 web_view->SetPreferredSize(gfx::Size(kWebViewWidth, kWebViewHeight)); 99 web_view->SetPreferredSize(gfx::Size(kWebViewWidth, kWebViewHeight));
79 web_view->SetWebContents(start_page_web_contents); 100 web_view->SetWebContents(start_page_web_contents);
80 101
81 instant_container_->AddChildView(web_view); 102 instant_container_->AddChildView(web_view);
82 instant_container_->AddChildView(new BarPlaceholderButton(this)); 103 instant_container_->AddChildView(new BarPlaceholderButton(this));
104
105 // The view containing the start page tiles.
106 AddChildView(tiles_container_);
107 views::BoxLayout* tiles_layout_manager =
108 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, kTileSpacing);
109 tiles_layout_manager->set_main_axis_alignment(
110 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER);
111 tiles_container_->SetLayoutManager(tiles_layout_manager);
112 for (size_t i = 0; i < kNumStartPageTiles; ++i) {
113 TileItemView* tile_item = new TileItemView();
114 tiles_container_->AddChildView(tile_item);
115 tile_views_.push_back(tile_item);
116 }
117
118 SetModel(view_delegate_->GetModel());
119 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.
83 } 120 }
84 121
85 StartPageView::~StartPageView() { 122 StartPageView::~StartPageView() {
123 view_delegate_->RemoveObserver(this);
124 }
125
126 TileItemView* StartPageView::GetTileViewAt(int index) {
127 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.
128 }
129
130 void StartPageView::SetModel(AppListModel* model) {
131 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.
132 model_->RemoveObserver(this);
133 model_ = model;
134 model_->AddObserver(this);
135 Reset();
86 } 136 }
87 137
88 void StartPageView::Reset() { 138 void StartPageView::Reset() {
89 instant_container_->SetVisible(true); 139 instant_container_->SetVisible(true);
140 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.
141 if (!model || !model->top_level_item_list())
142 return;
143
144 for (size_t i = 0; i < kNumStartPageTiles; ++i) {
145 AppListItem* item = NULL;
146 if (i < model->top_level_item_list()->item_count())
147 item = model->top_level_item_list()->item_at(i);
148 GetTileViewAt(i)->SetAppListItem(item);
149 }
150
151 Layout();
90 } 152 }
91 153
92 void StartPageView::ButtonPressed(views::Button* sender, 154 void StartPageView::ButtonPressed(views::Button* sender,
93 const ui::Event& event) { 155 const ui::Event& event) {
94 app_list_main_view_->OnStartPageSearchButtonPressed(); 156 app_list_main_view_->OnStartPageSearchButtonPressed();
95 instant_container_->SetVisible(false); 157 instant_container_->SetVisible(false);
96 } 158 }
97 159
160 void StartPageView::OnProfilesChanged() {
161 SetModel(view_delegate_->GetModel());
162 }
163
164 void StartPageView::OnAppListModelStatusChanged() {
165 Reset();
166 }
167
168 void StartPageView::OnAppListItemAdded(AppListItem* item) {
169 Reset();
170 }
171
172 void StartPageView::OnAppListItemDeleted() {
173 Reset();
174 }
175
176 void StartPageView::OnAppListItemUpdated(AppListItem* item) {
177 Reset();
178 }
179
98 } // namespace app_list 180 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698