| 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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 | 183 |
| 184 std::vector<SearchResult*> display_results = | 184 std::vector<SearchResult*> display_results = |
| 185 AppListModel::FilterSearchResultsByDisplayType( | 185 AppListModel::FilterSearchResultsByDisplayType( |
| 186 results(), SearchResult::DISPLAY_RECOMMENDATION, kNumStartPageTiles); | 186 results(), SearchResult::DISPLAY_RECOMMENDATION, kNumStartPageTiles); |
| 187 if (display_results.size() != search_result_tile_views_.size()) { | 187 if (display_results.size() != search_result_tile_views_.size()) { |
| 188 // We should recreate the grid layout in this case. | 188 // We should recreate the grid layout in this case. |
| 189 for (size_t i = 0; i < search_result_tile_views_.size(); ++i) | 189 for (size_t i = 0; i < search_result_tile_views_.size(); ++i) |
| 190 delete search_result_tile_views_[i]; | 190 delete search_result_tile_views_[i]; |
| 191 search_result_tile_views_.clear(); | 191 search_result_tile_views_.clear(); |
| 192 RemoveChildView(all_apps_button_); | 192 RemoveChildView(all_apps_button_); |
| 193 CreateAppsGrid(std::min(kNumStartPageTiles, display_results.size())); | 193 CreateAppsGrid(display_results.size()); |
| 194 } | 194 } |
| 195 | 195 |
| 196 // Update the tile item results. | 196 // Update the tile item results. |
| 197 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) { |
| 198 SearchResult* item = nullptr; | 198 SearchResult* item = nullptr; |
| 199 if (i < display_results.size()) | 199 if (i < display_results.size()) |
| 200 item = display_results[i]; | 200 item = display_results[i]; |
| 201 search_result_tile_views_[i]->SetSearchResult(item); | 201 search_result_tile_views_[i]->SetSearchResult(item); |
| 202 search_result_tile_views_[i]->SetEnabled(true); | 202 search_result_tile_views_[i]->SetEnabled(true); |
| 203 } | 203 } |
| 204 | 204 |
| 205 Layout(); | 205 Layout(); |
| 206 parent()->Layout(); | 206 parent()->Layout(); |
| 207 // 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. |
| 208 return display_results.size() + 1; | 208 return display_results.size() + 1; |
| 209 } | 209 } |
| 210 | 210 |
| 211 void StartPageView::StartPageTilesContainer::UpdateSelectedIndex( | 211 void StartPageView::StartPageTilesContainer::UpdateSelectedIndex( |
| 212 int old_selected, | 212 int old_selected, |
| 213 int new_selected) { | 213 int new_selected) { |
| 214 if (old_selected >= 0) | 214 if (old_selected >= 0 && old_selected < num_results()) |
| 215 GetTileItemView(old_selected)->SetSelected(false); | 215 GetTileItemView(old_selected)->SetSelected(false); |
| 216 | 216 |
| 217 if (new_selected >= 0) | 217 if (new_selected >= 0 && new_selected < num_results()) |
| 218 GetTileItemView(new_selected)->SetSelected(true); | 218 GetTileItemView(new_selected)->SetSelected(true); |
| 219 } | 219 } |
| 220 | 220 |
| 221 void StartPageView::StartPageTilesContainer::OnContainerSelected( | 221 void StartPageView::StartPageTilesContainer::OnContainerSelected( |
| 222 bool /*from_bottom*/, | 222 bool /*from_bottom*/, |
| 223 bool /*directional_movement*/) { | 223 bool /*directional_movement*/) { |
| 224 NOTREACHED(); | 224 NOTREACHED(); |
| 225 } | 225 } |
| 226 | 226 |
| 227 void StartPageView::StartPageTilesContainer::NotifyFirstResultYIndex( | 227 void StartPageView::StartPageTilesContainer::NotifyFirstResultYIndex( |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 | 353 |
| 354 void StartPageView::OnShown() { | 354 void StartPageView::OnShown() { |
| 355 // When the start page is shown, show or hide the custom launcher page | 355 // When the start page is shown, show or hide the custom launcher page |
| 356 // based on whether it is enabled. | 356 // based on whether it is enabled. |
| 357 CustomLauncherPageView* custom_page_view = | 357 CustomLauncherPageView* custom_page_view = |
| 358 app_list_main_view_->contents_view()->custom_page_view(); | 358 app_list_main_view_->contents_view()->custom_page_view(); |
| 359 if (custom_page_view) { | 359 if (custom_page_view) { |
| 360 custom_page_view->SetVisible( | 360 custom_page_view->SetVisible( |
| 361 app_list_main_view_->ShouldShowCustomLauncherPage()); | 361 app_list_main_view_->ShouldShowCustomLauncherPage()); |
| 362 } | 362 } |
| 363 tiles_container_->Update(); | |
| 364 tiles_container_->ClearSelectedIndex(); | 363 tiles_container_->ClearSelectedIndex(); |
| 364 tiles_container_->set_num_results(tiles_container_->Update()); |
| 365 custom_launcher_page_background_->SetSelected(false); | 365 custom_launcher_page_background_->SetSelected(false); |
| 366 } | 366 } |
| 367 | 367 |
| 368 gfx::Rect StartPageView::GetPageBoundsForState( | 368 gfx::Rect StartPageView::GetPageBoundsForState( |
| 369 AppListModel::State state) const { | 369 AppListModel::State state) const { |
| 370 gfx::Rect onscreen_bounds(GetFullContentsBounds()); | 370 gfx::Rect onscreen_bounds(GetFullContentsBounds()); |
| 371 if (state == AppListModel::STATE_START) | 371 if (state == AppListModel::STATE_START) |
| 372 return onscreen_bounds; | 372 return onscreen_bounds; |
| 373 | 373 |
| 374 return GetAboveContentsOffscreenBounds(onscreen_bounds.size()); | 374 return GetAboveContentsOffscreenBounds(onscreen_bounds.size()); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 // is enabled). | 527 // is enabled). |
| 528 if (event->type() == ui::ET_SCROLL && event->y_offset() < 0) | 528 if (event->type() == ui::ET_SCROLL && event->y_offset() < 0) |
| 529 MaybeOpenCustomLauncherPage(); | 529 MaybeOpenCustomLauncherPage(); |
| 530 } | 530 } |
| 531 | 531 |
| 532 TileItemView* StartPageView::GetTileItemView(size_t index) { | 532 TileItemView* StartPageView::GetTileItemView(size_t index) { |
| 533 return tiles_container_->GetTileItemView(index); | 533 return tiles_container_->GetTileItemView(index); |
| 534 } | 534 } |
| 535 | 535 |
| 536 } // namespace app_list | 536 } // namespace app_list |
| OLD | NEW |