OLD | NEW |
---|---|
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 size_t kNumStartPageTiles = 9; |
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 Loading... | |
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 | |
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); | 158 all_apps_button_->SetHoverStyle(TileItemView::HOVER_STYLE_ANIMATE_SHADOW); |
167 all_apps_button_->UpdateIcon(); | |
168 all_apps_button_->SetParentBackgroundColor(kLabelBackgroundColor); | 159 all_apps_button_->SetParentBackgroundColor(kLabelBackgroundColor); |
169 AddChildView(all_apps_button_); | 160 CreateAppsGrid(kNumStartPageTiles); |
170 } | 161 } |
171 | 162 |
172 StartPageView::StartPageTilesContainer::~StartPageTilesContainer() { | 163 StartPageView::StartPageTilesContainer::~StartPageTilesContainer() { |
173 } | 164 } |
174 | 165 |
175 TileItemView* StartPageView::StartPageTilesContainer::GetTileItemView( | 166 TileItemView* StartPageView::StartPageTilesContainer::GetTileItemView( |
176 int index) { | 167 int index) { |
177 DCHECK_GT(num_results(), index); | 168 DCHECK_GT(num_results(), index); |
178 if (index == num_results() - 1) | 169 if (index == num_results() - 1) |
179 return all_apps_button_; | 170 return all_apps_button_; |
180 | 171 |
181 return search_result_tile_views_[index]; | 172 return search_result_tile_views_[index]; |
182 } | 173 } |
183 | 174 |
184 int StartPageView::StartPageTilesContainer::Update() { | 175 int StartPageView::StartPageTilesContainer::Update() { |
185 // Ignore updates and disable buttons when transitioning to a different | 176 // Ignore updates and disable buttons when transitioning to a different |
186 // state. | 177 // state. |
187 if (contents_view_->GetActiveState() != AppListModel::STATE_START) { | 178 if (contents_view_->GetActiveState() != AppListModel::STATE_START) { |
188 for (auto* view : search_result_tile_views_) | 179 for (auto* view : search_result_tile_views_) |
189 view->SetEnabled(false); | 180 view->SetEnabled(false); |
190 | 181 |
191 return num_results(); | 182 return num_results(); |
192 } | 183 } |
193 | 184 |
194 std::vector<SearchResult*> display_results = | 185 std::vector<SearchResult*> display_results = |
195 AppListModel::FilterSearchResultsByDisplayType( | 186 AppListModel::FilterSearchResultsByDisplayType( |
196 results(), SearchResult::DISPLAY_RECOMMENDATION, kNumStartPageTiles); | 187 results(), SearchResult::DISPLAY_RECOMMENDATION, kNumStartPageTiles); |
188 if (display_results.size() != search_result_tile_views_.size() && | |
189 display_results.size() > 0) { | |
xiyuan
2016/08/08 21:41:01
What happens if display_results.size() == 0? Shoul
| |
190 // We should recreate the grid layout in this case. | |
191 for (size_t i = 0; i < search_result_tile_views_.size(); i++) { | |
192 RemoveChildView(search_result_tile_views_[i]); | |
193 delete search_result_tile_views_[i]; | |
194 } | |
195 search_result_tile_views_.clear(); | |
196 RemoveChildView(all_apps_button_); | |
197 CreateAppsGrid(std::min(kNumStartPageTiles, display_results.size())); | |
198 } | |
197 | 199 |
198 // Update the tile item results. | 200 // Update the tile item results. |
199 for (size_t i = 0; i < search_result_tile_views_.size(); ++i) { | 201 for (size_t i = 0; i < search_result_tile_views_.size(); ++i) { |
200 SearchResult* item = NULL; | 202 SearchResult* item = nullptr; |
201 if (i < display_results.size()) | 203 if (i < display_results.size()) |
202 item = display_results[i]; | 204 item = display_results[i]; |
203 search_result_tile_views_[i]->SetSearchResult(item); | 205 search_result_tile_views_[i]->SetSearchResult(item); |
204 search_result_tile_views_[i]->SetEnabled(true); | 206 search_result_tile_views_[i]->SetEnabled(true); |
205 } | 207 } |
206 | 208 |
207 Layout(); | 209 Layout(); |
208 parent()->Layout(); | 210 parent()->Layout(); |
209 // Add 1 to the results size to account for the all apps button. | 211 // Add 1 to the results size to account for the all apps button. |
210 return display_results.size() + 1; | 212 return display_results.size() + 1; |
(...skipping 18 matching lines...) Expand all Loading... | |
229 void StartPageView::StartPageTilesContainer::NotifyFirstResultYIndex( | 231 void StartPageView::StartPageTilesContainer::NotifyFirstResultYIndex( |
230 int /*y_index*/) { | 232 int /*y_index*/) { |
231 NOTREACHED(); | 233 NOTREACHED(); |
232 } | 234 } |
233 | 235 |
234 int StartPageView::StartPageTilesContainer::GetYSize() { | 236 int StartPageView::StartPageTilesContainer::GetYSize() { |
235 NOTREACHED(); | 237 NOTREACHED(); |
236 return 0; | 238 return 0; |
237 } | 239 } |
238 | 240 |
241 void StartPageView::StartPageTilesContainer::CreateAppsGrid(int apps_num) { | |
242 DCHECK(search_result_tile_views_.empty()); | |
243 views::GridLayout* tiles_layout_manager = new views::GridLayout(this); | |
244 SetLayoutManager(tiles_layout_manager); | |
245 | |
246 views::ColumnSet* column_set = tiles_layout_manager->AddColumnSet(0); | |
247 column_set->AddPaddingColumn(0, kTilesHorizontalMarginLeft); | |
248 for (int col = 0; col < kNumStartPageTilesCols; col++) { | |
249 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, | |
250 views::GridLayout::USE_PREF, 0, 0); | |
251 column_set->AddPaddingColumn(0, kTileSpacing); | |
252 } | |
253 | |
254 // Add SearchResultTileItemViews to the container. | |
255 int i = 0; | |
256 for (; i < apps_num; i++) { | |
257 SearchResultTileItemView* tile_item = | |
258 new SearchResultTileItemView(this, view_delegate_); | |
259 if (i % kNumStartPageTilesCols == 0) | |
260 tiles_layout_manager->StartRow(0, 0); | |
261 tiles_layout_manager->AddView(tile_item); | |
262 AddChildView(tile_item); | |
263 tile_item->SetParentBackgroundColor(kLabelBackgroundColor); | |
264 tile_item->SetHoverStyle(TileItemView::HOVER_STYLE_ANIMATE_SHADOW); | |
265 search_result_tile_views_.push_back(tile_item); | |
266 } | |
267 | |
268 // Also add a special "all apps" button to the end of the container. | |
269 all_apps_button_->UpdateIcon(); | |
270 if (i % kNumStartPageTilesCols == 0) | |
271 tiles_layout_manager->StartRow(0, 0); | |
272 tiles_layout_manager->AddView(all_apps_button_); | |
273 AddChildView(all_apps_button_); | |
274 } | |
275 | |
239 //////////////////////////////////////////////////////////////////////////////// | 276 //////////////////////////////////////////////////////////////////////////////// |
240 // StartPageView implementation: | 277 // StartPageView implementation: |
241 StartPageView::StartPageView(AppListMainView* app_list_main_view, | 278 StartPageView::StartPageView(AppListMainView* app_list_main_view, |
242 AppListViewDelegate* view_delegate) | 279 AppListViewDelegate* view_delegate) |
243 : app_list_main_view_(app_list_main_view), | 280 : app_list_main_view_(app_list_main_view), |
244 view_delegate_(view_delegate), | 281 view_delegate_(view_delegate), |
245 search_box_spacer_view_(new SearchBoxSpacerView( | 282 search_box_spacer_view_(new SearchBoxSpacerView( |
246 app_list_main_view->search_box_view()->GetPreferredSize())), | 283 app_list_main_view->search_box_view()->GetPreferredSize())), |
247 instant_container_(new views::View), | 284 instant_container_(new views::View), |
248 custom_launcher_page_background_(new CustomLauncherPageBackgroundView( | 285 custom_launcher_page_background_(new CustomLauncherPageBackgroundView( |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
496 // is enabled). | 533 // is enabled). |
497 if (event->type() == ui::ET_SCROLL && event->y_offset() < 0) | 534 if (event->type() == ui::ET_SCROLL && event->y_offset() < 0) |
498 MaybeOpenCustomLauncherPage(); | 535 MaybeOpenCustomLauncherPage(); |
499 } | 536 } |
500 | 537 |
501 TileItemView* StartPageView::GetTileItemView(size_t index) { | 538 TileItemView* StartPageView::GetTileItemView(size_t index) { |
502 return tiles_container_->GetTileItemView(index); | 539 return tiles_container_->GetTileItemView(index); |
503 } | 540 } |
504 | 541 |
505 } // namespace app_list | 542 } // namespace app_list |
OLD | NEW |