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

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

Issue 2225073002: [Chrome OS] Change layout of the launcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
« ui/app_list/search/mixer.cc ('K') | « ui/app_list/search/mixer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <algorithm>
7 #include <string> 8 #include <string>
8 9
9 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
10 #include "base/macros.h" 11 #include "base/macros.h"
11 #include "base/metrics/histogram_macros.h" 12 #include "base/metrics/histogram_macros.h"
12 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
13 #include "ui/accessibility/ax_view_state.h" 14 #include "ui/accessibility/ax_view_state.h"
14 #include "ui/app_list/app_list_constants.h" 15 #include "ui/app_list/app_list_constants.h"
15 #include "ui/app_list/app_list_item.h" 16 #include "ui/app_list/app_list_item.h"
16 #include "ui/app_list/app_list_model.h" 17 #include "ui/app_list/app_list_model.h"
17 #include "ui/app_list/app_list_view_delegate.h" 18 #include "ui/app_list/app_list_view_delegate.h"
18 #include "ui/app_list/search_result.h" 19 #include "ui/app_list/search_result.h"
19 #include "ui/app_list/views/all_apps_tile_item_view.h" 20 #include "ui/app_list/views/all_apps_tile_item_view.h"
20 #include "ui/app_list/views/app_list_main_view.h" 21 #include "ui/app_list/views/app_list_main_view.h"
21 #include "ui/app_list/views/contents_view.h" 22 #include "ui/app_list/views/contents_view.h"
22 #include "ui/app_list/views/custom_launcher_page_view.h" 23 #include "ui/app_list/views/custom_launcher_page_view.h"
23 #include "ui/app_list/views/search_box_view.h" 24 #include "ui/app_list/views/search_box_view.h"
24 #include "ui/app_list/views/search_result_container_view.h" 25 #include "ui/app_list/views/search_result_container_view.h"
25 #include "ui/app_list/views/search_result_tile_item_view.h" 26 #include "ui/app_list/views/search_result_tile_item_view.h"
26 #include "ui/app_list/views/tile_item_view.h" 27 #include "ui/app_list/views/tile_item_view.h"
27 #include "ui/gfx/canvas.h" 28 #include "ui/gfx/canvas.h"
28 #include "ui/views/background.h" 29 #include "ui/views/background.h"
29 #include "ui/views/controls/image_view.h" 30 #include "ui/views/controls/image_view.h"
30 #include "ui/views/controls/label.h" 31 #include "ui/views/controls/label.h"
31 #include "ui/views/controls/textfield/textfield.h" 32 #include "ui/views/controls/textfield/textfield.h"
32 #include "ui/views/layout/box_layout.h" 33 #include "ui/views/layout/box_layout.h"
34 #include "ui/views/layout/grid_layout.h"
33 #include "ui/views/widget/widget.h" 35 #include "ui/views/widget/widget.h"
34 36
35 namespace app_list { 37 namespace app_list {
36 38
37 namespace { 39 namespace {
38 40
39 // Layout constants. 41 // Layout constants.
40 const int kInstantContainerSpacing = 24; 42 const int kInstantContainerSpacing = 24;
41 const int kSearchBoxAndTilesSpacing = 35; 43 const int kSearchBoxAndTilesSpacing = 35;
42 const int kStartPageSearchBoxWidth = 480; 44 const int kStartPageSearchBoxWidth = 480;
43 45
44 // WebView constants. 46 // WebView constants.
45 const int kWebViewWidth = 700; 47 const int kWebViewWidth = 700;
46 const int kWebViewHeight = 244; 48 const int kWebViewHeight = 244;
47 49
48 // Tile container constants. 50 // Tile container constants.
49 const size_t kNumStartPageTiles = 4; 51 const int kNumStartPageTiles = 9;
xiyuan 2016/08/08 18:02:15 nit: do we have to replace size_t with int?
xdai1 2016/08/08 21:25:38 Reverted it back. Not necessarily... I just though
50 const int kTileSpacing = 7; 52 const int kTileSpacing = 7;
53 const int kNumStartPageTilesCols = 5;
54 const int kTilesHorizontalMarginLeft = 145;
51 55
52 const int kLauncherPageBackgroundWidth = 400; 56 const int kLauncherPageBackgroundWidth = 400;
53 57
54 // An invisible placeholder view which fills the space for the search box view 58 // An invisible placeholder view which fills the space for the search box view
55 // in a box layout. The search box view itself is a child of the AppListView 59 // in a box layout. The search box view itself is a child of the AppListView
56 // (because it is visible on many different pages). 60 // (because it is visible on many different pages).
57 class SearchBoxSpacerView : public views::View { 61 class SearchBoxSpacerView : public views::View {
58 public: 62 public:
59 explicit SearchBoxSpacerView(const gfx::Size& search_box_size) 63 explicit SearchBoxSpacerView(const gfx::Size& search_box_size)
60 : size_(kStartPageSearchBoxWidth, search_box_size.height()) {} 64 : size_(kStartPageSearchBoxWidth, search_box_size.height()) {}
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 128
125 // Overridden from SearchResultContainerView: 129 // Overridden from SearchResultContainerView:
126 int Update() override; 130 int Update() override;
127 void UpdateSelectedIndex(int old_selected, int new_selected) override; 131 void UpdateSelectedIndex(int old_selected, int new_selected) override;
128 void OnContainerSelected(bool from_bottom, 132 void OnContainerSelected(bool from_bottom,
129 bool directional_movement) override; 133 bool directional_movement) override;
130 void NotifyFirstResultYIndex(int y_index) override; 134 void NotifyFirstResultYIndex(int y_index) override;
131 int GetYSize() override; 135 int GetYSize() override;
132 136
133 private: 137 private:
138 void CreateAppsGrid(int apps_num);
139
134 ContentsView* contents_view_; 140 ContentsView* contents_view_;
141 AppListViewDelegate* view_delegate_;
135 142
136 std::vector<SearchResultTileItemView*> search_result_tile_views_; 143 std::vector<SearchResultTileItemView*> search_result_tile_views_;
137 AllAppsTileItemView* all_apps_button_; 144 AllAppsTileItemView* all_apps_button_;
138 145
139 DISALLOW_COPY_AND_ASSIGN(StartPageTilesContainer); 146 DISALLOW_COPY_AND_ASSIGN(StartPageTilesContainer);
140 }; 147 };
141 148
142 StartPageView::StartPageTilesContainer::StartPageTilesContainer( 149 StartPageView::StartPageTilesContainer::StartPageTilesContainer(
143 ContentsView* contents_view, 150 ContentsView* contents_view,
144 AllAppsTileItemView* all_apps_button, 151 AllAppsTileItemView* all_apps_button,
145 AppListViewDelegate* view_delegate) 152 AppListViewDelegate* view_delegate)
146 : contents_view_(contents_view), all_apps_button_(all_apps_button) { 153 : contents_view_(contents_view),
147 views::BoxLayout* tiles_layout_manager = 154 view_delegate_(view_delegate),
148 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, kTileSpacing); 155 all_apps_button_(all_apps_button) {
149 tiles_layout_manager->set_main_axis_alignment(
150 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER);
151 SetLayoutManager(tiles_layout_manager);
152 set_background( 156 set_background(
153 views::Background::CreateSolidBackground(kLabelBackgroundColor)); 157 views::Background::CreateSolidBackground(kLabelBackgroundColor));
154 158 CreateAppsGrid(kNumStartPageTiles);
155 // Add SearchResultTileItemViews to the container.
156 for (size_t i = 0; i < kNumStartPageTiles; ++i) {
157 SearchResultTileItemView* tile_item =
158 new SearchResultTileItemView(this, view_delegate);
159 AddChildView(tile_item);
160 tile_item->SetParentBackgroundColor(kLabelBackgroundColor);
161 tile_item->SetHoverStyle(TileItemView::HOVER_STYLE_ANIMATE_SHADOW);
162 search_result_tile_views_.push_back(tile_item);
163 }
164
165 // Also add a special "all apps" button to the end of the container.
166 all_apps_button_->SetHoverStyle(TileItemView::HOVER_STYLE_ANIMATE_SHADOW);
167 all_apps_button_->UpdateIcon();
168 all_apps_button_->SetParentBackgroundColor(kLabelBackgroundColor);
169 AddChildView(all_apps_button_);
170 } 159 }
171 160
172 StartPageView::StartPageTilesContainer::~StartPageTilesContainer() { 161 StartPageView::StartPageTilesContainer::~StartPageTilesContainer() {
173 } 162 }
174 163
175 TileItemView* StartPageView::StartPageTilesContainer::GetTileItemView( 164 TileItemView* StartPageView::StartPageTilesContainer::GetTileItemView(
176 int index) { 165 int index) {
177 DCHECK_GT(num_results(), index); 166 DCHECK_GT(num_results(), index);
178 if (index == num_results() - 1) 167 if (index == num_results() - 1)
179 return all_apps_button_; 168 return all_apps_button_;
180 169
181 return search_result_tile_views_[index]; 170 return search_result_tile_views_[index];
182 } 171 }
183 172
184 int StartPageView::StartPageTilesContainer::Update() { 173 int StartPageView::StartPageTilesContainer::Update() {
185 // Ignore updates and disable buttons when transitioning to a different 174 // Ignore updates and disable buttons when transitioning to a different
186 // state. 175 // state.
187 if (contents_view_->GetActiveState() != AppListModel::STATE_START) { 176 if (contents_view_->GetActiveState() != AppListModel::STATE_START) {
188 for (auto* view : search_result_tile_views_) 177 for (auto* view : search_result_tile_views_)
189 view->SetEnabled(false); 178 view->SetEnabled(false);
190 179
191 return num_results(); 180 return num_results();
192 } 181 }
193 182
194 std::vector<SearchResult*> display_results = 183 std::vector<SearchResult*> display_results =
195 AppListModel::FilterSearchResultsByDisplayType( 184 AppListModel::FilterSearchResultsByDisplayType(
196 results(), SearchResult::DISPLAY_RECOMMENDATION, kNumStartPageTiles); 185 results(), SearchResult::DISPLAY_RECOMMENDATION, kNumStartPageTiles);
186 if (display_results.size() < kNumStartPageTiles &&
187 display_results.size() > 0) {
xiyuan 2016/08/08 18:02:15 Think we need to update the gird when display_resu
xdai1 2016/08/08 21:25:38 Done.
188 // We should recreate the grid layout in this case.
189 for (size_t i = 0; i < search_result_tile_views_.size(); i++)
190 RemoveChildView(search_result_tile_views_[i]);
191 search_result_tile_views_.clear();
xiyuan 2016/08/08 18:02:15 Would this leak? That is, RemoveChildView() does n
xdai1 2016/08/08 21:25:38 You're right. I think we should manually delete th
192 RemoveChildView(all_apps_button_);
193 CreateAppsGrid(display_results.size());
194 }
197 195
198 // Update the tile item results. 196 // Update the tile item results.
199 for (size_t i = 0; i < search_result_tile_views_.size(); ++i) { 197 for (size_t i = 0; i < search_result_tile_views_.size(); ++i) {
200 SearchResult* item = NULL; 198 SearchResult* item = nullptr;
201 if (i < display_results.size()) 199 if (i < display_results.size())
202 item = display_results[i]; 200 item = display_results[i];
203 search_result_tile_views_[i]->SetSearchResult(item); 201 search_result_tile_views_[i]->SetSearchResult(item);
204 search_result_tile_views_[i]->SetEnabled(true); 202 search_result_tile_views_[i]->SetEnabled(true);
205 } 203 }
206 204
207 Layout(); 205 Layout();
208 parent()->Layout(); 206 parent()->Layout();
209 // Add 1 to the results size to account for the all apps button. 207 // Add 1 to the results size to account for the all apps button.
210 return display_results.size() + 1; 208 return display_results.size() + 1;
(...skipping 18 matching lines...) Expand all
229 void StartPageView::StartPageTilesContainer::NotifyFirstResultYIndex( 227 void StartPageView::StartPageTilesContainer::NotifyFirstResultYIndex(
230 int /*y_index*/) { 228 int /*y_index*/) {
231 NOTREACHED(); 229 NOTREACHED();
232 } 230 }
233 231
234 int StartPageView::StartPageTilesContainer::GetYSize() { 232 int StartPageView::StartPageTilesContainer::GetYSize() {
235 NOTREACHED(); 233 NOTREACHED();
236 return 0; 234 return 0;
237 } 235 }
238 236
237 void StartPageView::StartPageTilesContainer::CreateAppsGrid(int apps_num) {
238 views::GridLayout* tiles_layout_manager = new views::GridLayout(this);
xiyuan 2016/08/08 18:02:15 nit: DCHECK(search_result_tile_views_.empty()) to
xdai1 2016/08/08 21:25:38 Done.
239 SetLayoutManager(tiles_layout_manager);
240
241 views::ColumnSet* column_set = tiles_layout_manager->AddColumnSet(0);
242 column_set->AddPaddingColumn(0, kTilesHorizontalMarginLeft);
243 for (int col = 0; col < kNumStartPageTilesCols; col++) {
244 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0,
245 views::GridLayout::USE_PREF, 0, 0);
246 column_set->AddPaddingColumn(0, kTileSpacing);
247 }
248
249 // Add SearchResultTileItemViews to the container.
250 int i = 0;
251 for (; i < apps_num; i++) {
252 SearchResultTileItemView* tile_item =
253 new SearchResultTileItemView(this, view_delegate_);
254 if (i % kNumStartPageTilesCols == 0)
255 tiles_layout_manager->StartRow(0, 0);
256 tiles_layout_manager->AddView(tile_item);
257 AddChildView(tile_item);
258 tile_item->SetParentBackgroundColor(kLabelBackgroundColor);
259 tile_item->SetHoverStyle(TileItemView::HOVER_STYLE_ANIMATE_SHADOW);
260 search_result_tile_views_.push_back(tile_item);
261 }
262
263 // Also add a special "all apps" button to the end of the container.
264 all_apps_button_->SetHoverStyle(TileItemView::HOVER_STYLE_ANIMATE_SHADOW);
265 all_apps_button_->UpdateIcon();
266 all_apps_button_->SetParentBackgroundColor(kLabelBackgroundColor);
xiyuan 2016/08/08 18:02:15 nit: hover style in line 264 and this background c
xdai1 2016/08/08 21:25:38 Done.
267 if (i % kNumStartPageTilesCols == 0)
268 tiles_layout_manager->StartRow(0, 0);
269 tiles_layout_manager->AddView(all_apps_button_);
270 AddChildView(all_apps_button_);
271 }
272
239 //////////////////////////////////////////////////////////////////////////////// 273 ////////////////////////////////////////////////////////////////////////////////
240 // StartPageView implementation: 274 // StartPageView implementation:
241 StartPageView::StartPageView(AppListMainView* app_list_main_view, 275 StartPageView::StartPageView(AppListMainView* app_list_main_view,
242 AppListViewDelegate* view_delegate) 276 AppListViewDelegate* view_delegate)
243 : app_list_main_view_(app_list_main_view), 277 : app_list_main_view_(app_list_main_view),
244 view_delegate_(view_delegate), 278 view_delegate_(view_delegate),
245 search_box_spacer_view_(new SearchBoxSpacerView( 279 search_box_spacer_view_(new SearchBoxSpacerView(
246 app_list_main_view->search_box_view()->GetPreferredSize())), 280 app_list_main_view->search_box_view()->GetPreferredSize())),
247 instant_container_(new views::View), 281 instant_container_(new views::View),
248 custom_launcher_page_background_(new CustomLauncherPageBackgroundView( 282 custom_launcher_page_background_(new CustomLauncherPageBackgroundView(
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 // is enabled). 530 // is enabled).
497 if (event->type() == ui::ET_SCROLL && event->y_offset() < 0) 531 if (event->type() == ui::ET_SCROLL && event->y_offset() < 0)
498 MaybeOpenCustomLauncherPage(); 532 MaybeOpenCustomLauncherPage();
499 } 533 }
500 534
501 TileItemView* StartPageView::GetTileItemView(size_t index) { 535 TileItemView* StartPageView::GetTileItemView(size_t index) {
502 return tiles_container_->GetTileItemView(index); 536 return tiles_container_->GetTileItemView(index);
503 } 537 }
504 538
505 } // namespace app_list 539 } // namespace app_list
OLDNEW
« ui/app_list/search/mixer.cc ('K') | « ui/app_list/search/mixer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698