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 <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 | 119 |
120 TileItemView* GetTileItemView(int index); | 120 TileItemView* GetTileItemView(int index); |
121 | 121 |
122 const std::vector<SearchResultTileItemView*>& tile_views() const { | 122 const std::vector<SearchResultTileItemView*>& tile_views() const { |
123 return search_result_tile_views_; | 123 return search_result_tile_views_; |
124 } | 124 } |
125 | 125 |
126 AllAppsTileItemView* all_apps_button() { return all_apps_button_; } | 126 AllAppsTileItemView* all_apps_button() { return all_apps_button_; } |
127 | 127 |
128 // Overridden from SearchResultContainerView: | 128 // Overridden from SearchResultContainerView: |
129 int Update() override; | |
130 void UpdateSelectedIndex(int old_selected, int new_selected) override; | |
131 void OnContainerSelected(bool from_bottom, | 129 void OnContainerSelected(bool from_bottom, |
132 bool directional_movement) override; | 130 bool directional_movement) override; |
133 void NotifyFirstResultYIndex(int y_index) override; | 131 void NotifyFirstResultYIndex(int y_index) override; |
134 int GetYSize() override; | 132 int GetYSize() override; |
135 | 133 |
136 private: | 134 private: |
137 void CreateAppsGrid(int apps_num); | 135 void CreateAppsGrid(int apps_num); |
138 | 136 |
137 // Overridden from SearchResultContainerView: | |
138 int DoUpdate() override; | |
139 void UpdateSelectedIndex(int old_selected, int new_selected) override; | |
xiyuan
2017/01/04 00:12:09
nit: I don't have a strong preference of whether t
xdai1
2017/01/04 00:30:20
Just curious, why should we keep the overridden me
xiyuan
2017/01/04 00:36:27
Think that would make it easier to read. And style
xdai1
2017/01/04 23:18:41
Done. Thanks for the reference!
| |
140 | |
139 ContentsView* contents_view_; | 141 ContentsView* contents_view_; |
140 AppListViewDelegate* view_delegate_; | 142 AppListViewDelegate* view_delegate_; |
141 | 143 |
142 std::vector<SearchResultTileItemView*> search_result_tile_views_; | 144 std::vector<SearchResultTileItemView*> search_result_tile_views_; |
143 AllAppsTileItemView* all_apps_button_; | 145 AllAppsTileItemView* all_apps_button_; |
144 | 146 |
145 DISALLOW_COPY_AND_ASSIGN(StartPageTilesContainer); | 147 DISALLOW_COPY_AND_ASSIGN(StartPageTilesContainer); |
146 }; | 148 }; |
147 | 149 |
148 StartPageView::StartPageTilesContainer::StartPageTilesContainer( | 150 StartPageView::StartPageTilesContainer::StartPageTilesContainer( |
(...skipping 15 matching lines...) Expand all Loading... | |
164 | 166 |
165 TileItemView* StartPageView::StartPageTilesContainer::GetTileItemView( | 167 TileItemView* StartPageView::StartPageTilesContainer::GetTileItemView( |
166 int index) { | 168 int index) { |
167 DCHECK_GT(num_results(), index); | 169 DCHECK_GT(num_results(), index); |
168 if (index == num_results() - 1) | 170 if (index == num_results() - 1) |
169 return all_apps_button_; | 171 return all_apps_button_; |
170 | 172 |
171 return search_result_tile_views_[index]; | 173 return search_result_tile_views_[index]; |
172 } | 174 } |
173 | 175 |
174 int StartPageView::StartPageTilesContainer::Update() { | |
175 // Ignore updates and disable buttons when transitioning to a different | |
176 // state. | |
177 if (contents_view_->GetActiveState() != AppListModel::STATE_START) { | |
178 for (auto* view : search_result_tile_views_) | |
179 view->SetEnabled(false); | |
180 | |
181 return num_results(); | |
182 } | |
183 | |
184 std::vector<SearchResult*> display_results = | |
185 AppListModel::FilterSearchResultsByDisplayType( | |
186 results(), SearchResult::DISPLAY_RECOMMENDATION, kNumStartPageTiles); | |
187 if (display_results.size() != search_result_tile_views_.size()) { | |
188 // We should recreate the grid layout in this case. | |
189 for (size_t i = 0; i < search_result_tile_views_.size(); ++i) | |
190 delete search_result_tile_views_[i]; | |
191 search_result_tile_views_.clear(); | |
192 RemoveChildView(all_apps_button_); | |
193 CreateAppsGrid(std::min(kNumStartPageTiles, display_results.size())); | |
194 } | |
195 | |
196 // Update the tile item results. | |
197 for (size_t i = 0; i < search_result_tile_views_.size(); ++i) { | |
198 SearchResult* item = nullptr; | |
199 if (i < display_results.size()) | |
200 item = display_results[i]; | |
201 search_result_tile_views_[i]->SetSearchResult(item); | |
202 search_result_tile_views_[i]->SetEnabled(true); | |
203 } | |
204 | |
205 Layout(); | |
206 parent()->Layout(); | |
207 // Add 1 to the results size to account for the all apps button. | |
208 return display_results.size() + 1; | |
209 } | |
210 | |
211 void StartPageView::StartPageTilesContainer::UpdateSelectedIndex( | |
212 int old_selected, | |
213 int new_selected) { | |
214 if (old_selected >= 0) | |
215 GetTileItemView(old_selected)->SetSelected(false); | |
216 | |
217 if (new_selected >= 0) | |
218 GetTileItemView(new_selected)->SetSelected(true); | |
219 } | |
220 | |
221 void StartPageView::StartPageTilesContainer::OnContainerSelected( | 176 void StartPageView::StartPageTilesContainer::OnContainerSelected( |
222 bool /*from_bottom*/, | 177 bool /*from_bottom*/, |
223 bool /*directional_movement*/) { | 178 bool /*directional_movement*/) { |
224 NOTREACHED(); | 179 NOTREACHED(); |
225 } | 180 } |
226 | 181 |
227 void StartPageView::StartPageTilesContainer::NotifyFirstResultYIndex( | 182 void StartPageView::StartPageTilesContainer::NotifyFirstResultYIndex( |
228 int /*y_index*/) { | 183 int /*y_index*/) { |
229 NOTREACHED(); | 184 NOTREACHED(); |
230 } | 185 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
262 } | 217 } |
263 | 218 |
264 // Also add a special "all apps" button to the end of the container. | 219 // Also add a special "all apps" button to the end of the container. |
265 all_apps_button_->UpdateIcon(); | 220 all_apps_button_->UpdateIcon(); |
266 if (i % kNumStartPageTilesCols == 0) | 221 if (i % kNumStartPageTilesCols == 0) |
267 tiles_layout_manager->StartRow(0, 0); | 222 tiles_layout_manager->StartRow(0, 0); |
268 tiles_layout_manager->AddView(all_apps_button_); | 223 tiles_layout_manager->AddView(all_apps_button_); |
269 AddChildView(all_apps_button_); | 224 AddChildView(all_apps_button_); |
270 } | 225 } |
271 | 226 |
227 int StartPageView::StartPageTilesContainer::DoUpdate() { | |
228 // Ignore updates and disable buttons when transitioning to a different | |
229 // state. | |
230 if (contents_view_->GetActiveState() != AppListModel::STATE_START) { | |
231 for (auto* view : search_result_tile_views_) | |
232 view->SetEnabled(false); | |
233 | |
234 return num_results(); | |
235 } | |
236 | |
237 std::vector<SearchResult*> display_results = | |
238 AppListModel::FilterSearchResultsByDisplayType( | |
239 results(), SearchResult::DISPLAY_RECOMMENDATION, kNumStartPageTiles); | |
240 if (display_results.size() != search_result_tile_views_.size()) { | |
241 // We should recreate the grid layout in this case. | |
242 for (size_t i = 0; i < search_result_tile_views_.size(); ++i) | |
243 delete search_result_tile_views_[i]; | |
244 search_result_tile_views_.clear(); | |
245 RemoveChildView(all_apps_button_); | |
246 CreateAppsGrid(std::min(kNumStartPageTiles, display_results.size())); | |
247 } | |
248 | |
249 // Update the tile item results. | |
250 for (size_t i = 0; i < search_result_tile_views_.size(); ++i) { | |
251 SearchResult* item = nullptr; | |
252 if (i < display_results.size()) | |
253 item = display_results[i]; | |
254 search_result_tile_views_[i]->SetSearchResult(item); | |
255 search_result_tile_views_[i]->SetEnabled(true); | |
256 } | |
257 | |
258 Layout(); | |
259 parent()->Layout(); | |
260 // Add 1 to the results size to account for the all apps button. | |
261 return display_results.size() + 1; | |
262 } | |
263 | |
264 void StartPageView::StartPageTilesContainer::UpdateSelectedIndex( | |
265 int old_selected, | |
266 int new_selected) { | |
267 if (old_selected >= 0 && old_selected < num_results()) | |
268 GetTileItemView(old_selected)->SetSelected(false); | |
269 | |
270 if (new_selected >= 0 && new_selected < num_results()) | |
271 GetTileItemView(new_selected)->SetSelected(true); | |
272 } | |
273 | |
272 //////////////////////////////////////////////////////////////////////////////// | 274 //////////////////////////////////////////////////////////////////////////////// |
273 // StartPageView implementation: | 275 // StartPageView implementation: |
274 StartPageView::StartPageView(AppListMainView* app_list_main_view, | 276 StartPageView::StartPageView(AppListMainView* app_list_main_view, |
275 AppListViewDelegate* view_delegate) | 277 AppListViewDelegate* view_delegate) |
276 : app_list_main_view_(app_list_main_view), | 278 : app_list_main_view_(app_list_main_view), |
277 view_delegate_(view_delegate), | 279 view_delegate_(view_delegate), |
278 search_box_spacer_view_(new SearchBoxSpacerView( | 280 search_box_spacer_view_(new SearchBoxSpacerView( |
279 app_list_main_view->search_box_view()->GetPreferredSize())), | 281 app_list_main_view->search_box_view()->GetPreferredSize())), |
280 instant_container_(new views::View), | 282 instant_container_(new views::View), |
281 custom_launcher_page_background_(new CustomLauncherPageBackgroundView( | 283 custom_launcher_page_background_(new CustomLauncherPageBackgroundView( |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
353 | 355 |
354 void StartPageView::OnShown() { | 356 void StartPageView::OnShown() { |
355 // When the start page is shown, show or hide the custom launcher page | 357 // When the start page is shown, show or hide the custom launcher page |
356 // based on whether it is enabled. | 358 // based on whether it is enabled. |
357 CustomLauncherPageView* custom_page_view = | 359 CustomLauncherPageView* custom_page_view = |
358 app_list_main_view_->contents_view()->custom_page_view(); | 360 app_list_main_view_->contents_view()->custom_page_view(); |
359 if (custom_page_view) { | 361 if (custom_page_view) { |
360 custom_page_view->SetVisible( | 362 custom_page_view->SetVisible( |
361 app_list_main_view_->ShouldShowCustomLauncherPage()); | 363 app_list_main_view_->ShouldShowCustomLauncherPage()); |
362 } | 364 } |
365 tiles_container_->ClearSelectedIndex(); | |
363 tiles_container_->Update(); | 366 tiles_container_->Update(); |
364 tiles_container_->ClearSelectedIndex(); | |
365 custom_launcher_page_background_->SetSelected(false); | 367 custom_launcher_page_background_->SetSelected(false); |
366 } | 368 } |
367 | 369 |
368 gfx::Rect StartPageView::GetPageBoundsForState( | 370 gfx::Rect StartPageView::GetPageBoundsForState( |
369 AppListModel::State state) const { | 371 AppListModel::State state) const { |
370 gfx::Rect onscreen_bounds(GetFullContentsBounds()); | 372 gfx::Rect onscreen_bounds(GetFullContentsBounds()); |
371 if (state == AppListModel::STATE_START) | 373 if (state == AppListModel::STATE_START) |
372 return onscreen_bounds; | 374 return onscreen_bounds; |
373 | 375 |
374 return GetAboveContentsOffscreenBounds(onscreen_bounds.size()); | 376 return GetAboveContentsOffscreenBounds(onscreen_bounds.size()); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
527 // is enabled). | 529 // is enabled). |
528 if (event->type() == ui::ET_SCROLL && event->y_offset() < 0) | 530 if (event->type() == ui::ET_SCROLL && event->y_offset() < 0) |
529 MaybeOpenCustomLauncherPage(); | 531 MaybeOpenCustomLauncherPage(); |
530 } | 532 } |
531 | 533 |
532 TileItemView* StartPageView::GetTileItemView(size_t index) { | 534 TileItemView* StartPageView::GetTileItemView(size_t index) { |
533 return tiles_container_->GetTileItemView(index); | 535 return tiles_container_->GetTileItemView(index); |
534 } | 536 } |
535 | 537 |
536 } // namespace app_list | 538 } // namespace app_list |
OLD | NEW |