OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/contents_view.h" | 5 #include "ui/app_list/views/contents_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "ui/events/event.h" | 24 #include "ui/events/event.h" |
25 #include "ui/resources/grit/ui_resources.h" | 25 #include "ui/resources/grit/ui_resources.h" |
26 #include "ui/views/view_model.h" | 26 #include "ui/views/view_model.h" |
27 #include "ui/views/view_model_utils.h" | 27 #include "ui/views/view_model_utils.h" |
28 #include "ui/views/widget/widget.h" | 28 #include "ui/views/widget/widget.h" |
29 | 29 |
30 namespace app_list { | 30 namespace app_list { |
31 | 31 |
32 ContentsView::ContentsView(AppListMainView* app_list_main_view) | 32 ContentsView::ContentsView(AppListMainView* app_list_main_view) |
33 : apps_container_view_(nullptr), | 33 : apps_container_view_(nullptr), |
34 search_results_list_view_(nullptr), | |
35 search_results_page_view_(nullptr), | 34 search_results_page_view_(nullptr), |
36 start_page_view_(nullptr), | 35 start_page_view_(nullptr), |
37 custom_page_view_(nullptr), | 36 custom_page_view_(nullptr), |
38 app_list_main_view_(app_list_main_view), | 37 app_list_main_view_(app_list_main_view), |
39 view_model_(new views::ViewModel), | 38 view_model_(new views::ViewModel), |
40 page_before_search_(0) { | 39 page_before_search_(0) { |
41 pagination_model_.SetTransitionDurations(kPageTransitionDurationInMs, | 40 pagination_model_.SetTransitionDurations(kPageTransitionDurationInMs, |
42 kOverscrollPageTransitionDurationMs); | 41 kOverscrollPageTransitionDurationMs); |
43 pagination_model_.AddObserver(this); | 42 pagination_model_.AddObserver(this); |
44 } | 43 } |
(...skipping 21 matching lines...) Expand all Loading... |
66 | 65 |
67 AddLauncherPage(*it, AppListModel::STATE_CUSTOM_LAUNCHER_PAGE); | 66 AddLauncherPage(*it, AppListModel::STATE_CUSTOM_LAUNCHER_PAGE); |
68 } else { | 67 } else { |
69 AddLauncherPage(*it); | 68 AddLauncherPage(*it); |
70 } | 69 } |
71 } | 70 } |
72 | 71 |
73 // Start page. | 72 // Start page. |
74 start_page_view_ = new StartPageView(app_list_main_view_, view_delegate); | 73 start_page_view_ = new StartPageView(app_list_main_view_, view_delegate); |
75 AddLauncherPage(start_page_view_, AppListModel::STATE_START); | 74 AddLauncherPage(start_page_view_, AppListModel::STATE_START); |
| 75 } |
76 | 76 |
77 // Search results UI. | 77 // Search results UI. |
78 search_results_page_view_ = new SearchResultPageView(); | 78 search_results_page_view_ = new SearchResultPageView(); |
79 | 79 |
80 AppListModel::SearchResults* results = view_delegate->GetModel()->results(); | 80 AppListModel::SearchResults* results = view_delegate->GetModel()->results(); |
81 search_results_page_view_->AddSearchResultContainerView( | 81 search_results_page_view_->AddSearchResultContainerView( |
82 results, new SearchResultListView(app_list_main_view_, view_delegate)); | 82 results, new SearchResultListView(app_list_main_view_, view_delegate)); |
| 83 |
| 84 if (app_list::switches::IsExperimentalAppListEnabled()) { |
83 search_results_page_view_->AddSearchResultContainerView( | 85 search_results_page_view_->AddSearchResultContainerView( |
84 results, | 86 results, |
85 new SearchResultTileItemListView(GetSearchBoxView()->search_box())); | 87 new SearchResultTileItemListView(GetSearchBoxView()->search_box())); |
86 | |
87 AddLauncherPage(search_results_page_view_, | |
88 AppListModel::STATE_SEARCH_RESULTS); | |
89 } else { | |
90 search_results_list_view_ = | |
91 new SearchResultListView(app_list_main_view_, view_delegate); | |
92 AddLauncherPage(search_results_list_view_, | |
93 AppListModel::STATE_SEARCH_RESULTS); | |
94 search_results_list_view_->SetResults(model->results()); | |
95 } | 88 } |
| 89 AddLauncherPage(search_results_page_view_, |
| 90 AppListModel::STATE_SEARCH_RESULTS); |
96 | 91 |
97 apps_container_view_ = new AppsContainerView(app_list_main_view_, model); | 92 apps_container_view_ = new AppsContainerView(app_list_main_view_, model); |
98 | 93 |
99 AddLauncherPage(apps_container_view_, AppListModel::STATE_APPS); | 94 AddLauncherPage(apps_container_view_, AppListModel::STATE_APPS); |
100 | 95 |
101 int initial_page_index = app_list::switches::IsExperimentalAppListEnabled() | 96 int initial_page_index = app_list::switches::IsExperimentalAppListEnabled() |
102 ? GetPageIndexForState(AppListModel::STATE_START) | 97 ? GetPageIndexForState(AppListModel::STATE_START) |
103 : GetPageIndexForState(AppListModel::STATE_APPS); | 98 : GetPageIndexForState(AppListModel::STATE_APPS); |
104 DCHECK_GE(initial_page_index, 0); | 99 DCHECK_GE(initial_page_index, 0); |
105 | 100 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 // Set the visibility of the search box's back button. | 212 // Set the visibility of the search box's back button. |
218 app_list_main_view_->search_box_view()->back_button()->SetVisible( | 213 app_list_main_view_->search_box_view()->back_button()->SetVisible( |
219 state != AppListModel::STATE_START); | 214 state != AppListModel::STATE_START); |
220 app_list_main_view_->search_box_view()->Layout(); | 215 app_list_main_view_->search_box_view()->Layout(); |
221 | 216 |
222 // Whenever the page changes, the custom launcher page is considered to have | 217 // Whenever the page changes, the custom launcher page is considered to have |
223 // been reset. | 218 // been reset. |
224 app_list_main_view_->model()->ClearCustomLauncherPageSubpages(); | 219 app_list_main_view_->model()->ClearCustomLauncherPageSubpages(); |
225 } | 220 } |
226 | 221 |
227 // TODO(xiyuan): Highlight default match instead of the first. | |
228 if (state == AppListModel::STATE_SEARCH_RESULTS && | |
229 search_results_list_view_ && search_results_list_view_->visible()) { | |
230 search_results_list_view_->OnContainerSelected(false); | |
231 } | |
232 | |
233 if (search_results_list_view_) | |
234 search_results_list_view_->UpdateAutoLaunchState(); | |
235 | |
236 if (custom_page_view_) { | 222 if (custom_page_view_) { |
237 custom_page_view_->SetFocusable(state == | 223 custom_page_view_->SetFocusable(state == |
238 AppListModel::STATE_CUSTOM_LAUNCHER_PAGE); | 224 AppListModel::STATE_CUSTOM_LAUNCHER_PAGE); |
239 } | 225 } |
240 } | 226 } |
241 | 227 |
242 void ContentsView::ShowSearchResults(bool show) { | 228 void ContentsView::ShowSearchResults(bool show) { |
243 int search_page = GetPageIndexForState(AppListModel::STATE_SEARCH_RESULTS); | 229 int search_page = GetPageIndexForState(AppListModel::STATE_SEARCH_RESULTS); |
244 DCHECK_GE(search_page, 0); | 230 DCHECK_GE(search_page, 0); |
245 | 231 |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 ShowSearchResults(false); | 421 ShowSearchResults(false); |
436 break; | 422 break; |
437 case AppListModel::INVALID_STATE: | 423 case AppListModel::INVALID_STATE: |
438 NOTREACHED(); | 424 NOTREACHED(); |
439 break; | 425 break; |
440 } | 426 } |
441 return true; | 427 return true; |
442 } | 428 } |
443 | 429 |
444 gfx::Size ContentsView::GetDefaultContentsSize() const { | 430 gfx::Size ContentsView::GetDefaultContentsSize() const { |
445 const gfx::Size container_size = | 431 return apps_container_view_->apps_grid_view()->GetPreferredSize(); |
446 apps_container_view_->apps_grid_view()->GetPreferredSize(); | |
447 const gfx::Size results_size = | |
448 search_results_list_view_ ? search_results_list_view_->GetPreferredSize() | |
449 : gfx::Size(); | |
450 | |
451 int width = std::max(container_size.width(), results_size.width()); | |
452 int height = std::max(container_size.height(), results_size.height()); | |
453 return gfx::Size(width, height); | |
454 } | 432 } |
455 | 433 |
456 gfx::Size ContentsView::GetPreferredSize() const { | 434 gfx::Size ContentsView::GetPreferredSize() const { |
457 gfx::Rect search_box_bounds = GetDefaultSearchBoxBounds(); | 435 gfx::Rect search_box_bounds = GetDefaultSearchBoxBounds(); |
458 gfx::Rect default_contents_bounds = GetDefaultContentsBounds(); | 436 gfx::Rect default_contents_bounds = GetDefaultContentsBounds(); |
459 gfx::Vector2d bottom_right = | 437 gfx::Vector2d bottom_right = |
460 search_box_bounds.bottom_right().OffsetFromOrigin(); | 438 search_box_bounds.bottom_right().OffsetFromOrigin(); |
461 bottom_right.SetToMax( | 439 bottom_right.SetToMax( |
462 default_contents_bounds.bottom_right().OffsetFromOrigin()); | 440 default_contents_bounds.bottom_right().OffsetFromOrigin()); |
463 return gfx::Size(bottom_right.x(), bottom_right.y()); | 441 return gfx::Size(bottom_right.x(), bottom_right.y()); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 } | 512 } |
535 | 513 |
536 void ContentsView::TransitionStarted() { | 514 void ContentsView::TransitionStarted() { |
537 } | 515 } |
538 | 516 |
539 void ContentsView::TransitionChanged() { | 517 void ContentsView::TransitionChanged() { |
540 UpdatePageBounds(); | 518 UpdatePageBounds(); |
541 } | 519 } |
542 | 520 |
543 } // namespace app_list | 521 } // namespace app_list |
OLD | NEW |