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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 TileItemView* StartPageView::StartPageTilesContainer::GetTileItemView( | 165 TileItemView* StartPageView::StartPageTilesContainer::GetTileItemView( |
166 int index) { | 166 int index) { |
167 DCHECK_GT(num_results(), index); | 167 DCHECK_GT(num_results(), index); |
168 if (index == num_results() - 1) | 168 if (index == num_results() - 1) |
169 return all_apps_button_; | 169 return all_apps_button_; |
170 | 170 |
171 return search_result_tile_views_[index]; | 171 return search_result_tile_views_[index]; |
172 } | 172 } |
173 | 173 |
174 int StartPageView::StartPageTilesContainer::Update() { | 174 int StartPageView::StartPageTilesContainer::Update() { |
175 std::vector<SearchResult*> display_results = | |
176 AppListModel::FilterSearchResultsByDisplayType( | |
177 results(), SearchResult::DISPLAY_RECOMMENDATION, kNumStartPageTiles); | |
178 | |
175 // Ignore updates and disable buttons when transitioning to a different | 179 // Ignore updates and disable buttons when transitioning to a different |
176 // state. | 180 // state. |
177 if (contents_view_->GetActiveState() != AppListModel::STATE_START) { | 181 if (contents_view_->GetActiveState() != AppListModel::STATE_START) { |
178 for (auto* view : search_result_tile_views_) | 182 for (auto* view : search_result_tile_views_) |
179 view->SetEnabled(false); | 183 view->SetEnabled(false); |
180 | 184 |
181 return num_results(); | 185 // We still need to update the number: add 1 to the results size to account |
186 // for the all apps button. | |
187 return display_results.size() + 1; | |
xiyuan
2017/01/03 17:05:13
Not sure whether this is the right thing to do. We
xdai1
2017/01/03 19:15:41
Emmm... In this case the approach in the first pat
| |
182 } | 188 } |
183 | 189 |
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()) { | 190 if (display_results.size() != search_result_tile_views_.size()) { |
188 // We should recreate the grid layout in this case. | 191 // We should recreate the grid layout in this case. |
189 for (size_t i = 0; i < search_result_tile_views_.size(); ++i) | 192 for (size_t i = 0; i < search_result_tile_views_.size(); ++i) |
190 delete search_result_tile_views_[i]; | 193 delete search_result_tile_views_[i]; |
191 search_result_tile_views_.clear(); | 194 search_result_tile_views_.clear(); |
192 RemoveChildView(all_apps_button_); | 195 RemoveChildView(all_apps_button_); |
193 CreateAppsGrid(std::min(kNumStartPageTiles, display_results.size())); | 196 CreateAppsGrid(display_results.size()); |
xiyuan
2017/01/03 17:05:14
Would this change have side effect that we might d
xdai1
2017/01/03 19:15:41
The maximum number of |display_results| is kNumSta
| |
194 } | 197 } |
195 | 198 |
196 // Update the tile item results. | 199 // Update the tile item results. |
197 for (size_t i = 0; i < search_result_tile_views_.size(); ++i) { | 200 for (size_t i = 0; i < search_result_tile_views_.size(); ++i) { |
198 SearchResult* item = nullptr; | 201 SearchResult* item = nullptr; |
199 if (i < display_results.size()) | 202 if (i < display_results.size()) |
200 item = display_results[i]; | 203 item = display_results[i]; |
201 search_result_tile_views_[i]->SetSearchResult(item); | 204 search_result_tile_views_[i]->SetSearchResult(item); |
202 search_result_tile_views_[i]->SetEnabled(true); | 205 search_result_tile_views_[i]->SetEnabled(true); |
203 } | 206 } |
204 | 207 |
205 Layout(); | 208 Layout(); |
206 parent()->Layout(); | 209 parent()->Layout(); |
207 // Add 1 to the results size to account for the all apps button. | 210 // Add 1 to the results size to account for the all apps button. |
208 return display_results.size() + 1; | 211 return display_results.size() + 1; |
209 } | 212 } |
210 | 213 |
211 void StartPageView::StartPageTilesContainer::UpdateSelectedIndex( | 214 void StartPageView::StartPageTilesContainer::UpdateSelectedIndex( |
212 int old_selected, | 215 int old_selected, |
213 int new_selected) { | 216 int new_selected) { |
214 if (old_selected >= 0) | 217 if (old_selected >= 0 && old_selected < num_results()) |
215 GetTileItemView(old_selected)->SetSelected(false); | 218 GetTileItemView(old_selected)->SetSelected(false); |
216 | 219 |
217 if (new_selected >= 0) | 220 if (new_selected >= 0 && new_selected < num_results()) |
218 GetTileItemView(new_selected)->SetSelected(true); | 221 GetTileItemView(new_selected)->SetSelected(true); |
219 } | 222 } |
220 | 223 |
221 void StartPageView::StartPageTilesContainer::OnContainerSelected( | 224 void StartPageView::StartPageTilesContainer::OnContainerSelected( |
222 bool /*from_bottom*/, | 225 bool /*from_bottom*/, |
223 bool /*directional_movement*/) { | 226 bool /*directional_movement*/) { |
224 NOTREACHED(); | 227 NOTREACHED(); |
225 } | 228 } |
226 | 229 |
227 void StartPageView::StartPageTilesContainer::NotifyFirstResultYIndex( | 230 void StartPageView::StartPageTilesContainer::NotifyFirstResultYIndex( |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
527 // is enabled). | 530 // is enabled). |
528 if (event->type() == ui::ET_SCROLL && event->y_offset() < 0) | 531 if (event->type() == ui::ET_SCROLL && event->y_offset() < 0) |
529 MaybeOpenCustomLauncherPage(); | 532 MaybeOpenCustomLauncherPage(); |
530 } | 533 } |
531 | 534 |
532 TileItemView* StartPageView::GetTileItemView(size_t index) { | 535 TileItemView* StartPageView::GetTileItemView(size_t index) { |
533 return tiles_container_->GetTileItemView(index); | 536 return tiles_container_->GetTileItemView(index); |
534 } | 537 } |
535 | 538 |
536 } // namespace app_list | 539 } // namespace app_list |
OLD | NEW |