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" |
11 #include "ui/app_list/app_list_constants.h" | 11 #include "ui/app_list/app_list_constants.h" |
12 #include "ui/app_list/app_list_switches.h" | 12 #include "ui/app_list/app_list_switches.h" |
13 #include "ui/app_list/app_list_view_delegate.h" | 13 #include "ui/app_list/app_list_view_delegate.h" |
14 #include "ui/app_list/views/app_list_folder_view.h" | 14 #include "ui/app_list/views/app_list_folder_view.h" |
15 #include "ui/app_list/views/app_list_main_view.h" | 15 #include "ui/app_list/views/app_list_main_view.h" |
16 #include "ui/app_list/views/apps_container_view.h" | 16 #include "ui/app_list/views/apps_container_view.h" |
17 #include "ui/app_list/views/apps_grid_view.h" | 17 #include "ui/app_list/views/apps_grid_view.h" |
18 #include "ui/app_list/views/contents_switcher_view.h" | 18 #include "ui/app_list/views/contents_switcher_view.h" |
19 #include "ui/app_list/views/search_box_view.h" | 19 #include "ui/app_list/views/search_box_view.h" |
20 #include "ui/app_list/views/search_result_list_view.h" | 20 #include "ui/app_list/views/search_result_list_view.h" |
| 21 #include "ui/app_list/views/search_result_page_view.h" |
21 #include "ui/app_list/views/start_page_view.h" | 22 #include "ui/app_list/views/start_page_view.h" |
22 #include "ui/events/event.h" | 23 #include "ui/events/event.h" |
23 #include "ui/gfx/animation/tween.h" | 24 #include "ui/gfx/animation/tween.h" |
24 #include "ui/resources/grit/ui_resources.h" | 25 #include "ui/resources/grit/ui_resources.h" |
25 #include "ui/views/view_model.h" | 26 #include "ui/views/view_model.h" |
26 #include "ui/views/view_model_utils.h" | 27 #include "ui/views/view_model_utils.h" |
27 | 28 |
28 namespace app_list { | 29 namespace app_list { |
29 | 30 |
30 ContentsView::ContentsView(AppListMainView* app_list_main_view) | 31 ContentsView::ContentsView(AppListMainView* app_list_main_view) |
31 : search_results_view_(NULL), | 32 : apps_container_view_(NULL), |
| 33 search_results_list_view_(NULL), |
| 34 search_results_page_view_(NULL), |
32 start_page_view_(NULL), | 35 start_page_view_(NULL), |
33 app_list_main_view_(app_list_main_view), | 36 app_list_main_view_(app_list_main_view), |
34 contents_switcher_view_(NULL), | 37 contents_switcher_view_(NULL), |
35 view_model_(new views::ViewModel), | 38 view_model_(new views::ViewModel), |
36 page_before_search_(0) { | 39 page_before_search_(0) { |
37 pagination_model_.SetTransitionDurations(kPageTransitionDurationInMs, | 40 pagination_model_.SetTransitionDurations(kPageTransitionDurationInMs, |
38 kOverscrollPageTransitionDurationMs); | 41 kOverscrollPageTransitionDurationMs); |
39 pagination_model_.AddObserver(this); | 42 pagination_model_.AddObserver(this); |
40 } | 43 } |
41 | 44 |
(...skipping 20 matching lines...) Expand all Loading... |
62 IDR_APP_LIST_NOTIFICATIONS_ICON, | 65 IDR_APP_LIST_NOTIFICATIONS_ICON, |
63 AppListModel::STATE_CUSTOM_LAUNCHER_PAGE); | 66 AppListModel::STATE_CUSTOM_LAUNCHER_PAGE); |
64 } else { | 67 } else { |
65 AddLauncherPage(*it, IDR_APP_LIST_NOTIFICATIONS_ICON); | 68 AddLauncherPage(*it, IDR_APP_LIST_NOTIFICATIONS_ICON); |
66 } | 69 } |
67 } | 70 } |
68 | 71 |
69 start_page_view_ = new StartPageView(app_list_main_view_, view_delegate); | 72 start_page_view_ = new StartPageView(app_list_main_view_, view_delegate); |
70 AddLauncherPage( | 73 AddLauncherPage( |
71 start_page_view_, IDR_APP_LIST_SEARCH_ICON, AppListModel::STATE_START); | 74 start_page_view_, IDR_APP_LIST_SEARCH_ICON, AppListModel::STATE_START); |
| 75 |
| 76 search_results_page_view_ = |
| 77 new SearchResultPageView(app_list_main_view_, view_delegate); |
| 78 AddLauncherPage( |
| 79 search_results_page_view_, 0, AppListModel::STATE_SEARCH_RESULTS); |
72 } else { | 80 } else { |
73 search_results_view_ = | 81 search_results_list_view_ = |
74 new SearchResultListView(app_list_main_view_, view_delegate); | 82 new SearchResultListView(app_list_main_view_, view_delegate); |
75 AddLauncherPage( | 83 AddLauncherPage( |
76 search_results_view_, 0, AppListModel::STATE_SEARCH_RESULTS); | 84 search_results_list_view_, 0, AppListModel::STATE_SEARCH_RESULTS); |
77 search_results_view_->SetResults(model->results()); | 85 search_results_list_view_->SetResults(model->results()); |
78 } | 86 } |
79 | 87 |
80 apps_container_view_ = new AppsContainerView(app_list_main_view_, model); | 88 apps_container_view_ = new AppsContainerView(app_list_main_view_, model); |
81 | 89 |
82 AddLauncherPage( | 90 AddLauncherPage( |
83 apps_container_view_, IDR_APP_LIST_APPS_ICON, AppListModel::STATE_APPS); | 91 apps_container_view_, IDR_APP_LIST_APPS_ICON, AppListModel::STATE_APPS); |
84 | 92 |
85 int initial_page_index = app_list::switches::IsExperimentalAppListEnabled() | 93 int initial_page_index = app_list::switches::IsExperimentalAppListEnabled() |
86 ? GetPageIndexForState(AppListModel::STATE_START) | 94 ? GetPageIndexForState(AppListModel::STATE_START) |
87 : GetPageIndexForState(AppListModel::STATE_APPS); | 95 : GetPageIndexForState(AppListModel::STATE_APPS); |
88 DCHECK_GE(initial_page_index, 0); | 96 DCHECK_GE(initial_page_index, 0); |
89 | 97 |
90 page_before_search_ = initial_page_index; | 98 page_before_search_ = initial_page_index; |
91 pagination_model_.SelectPage(initial_page_index, false); | 99 pagination_model_.SelectPage(initial_page_index, false); |
92 ActivePageChanged(false); | 100 ActivePageChanged(); |
93 } | 101 } |
94 | 102 |
95 void ContentsView::CancelDrag() { | 103 void ContentsView::CancelDrag() { |
96 if (apps_container_view_->apps_grid_view()->has_dragged_view()) | 104 if (apps_container_view_->apps_grid_view()->has_dragged_view()) |
97 apps_container_view_->apps_grid_view()->EndDrag(true); | 105 apps_container_view_->apps_grid_view()->EndDrag(true); |
98 if (apps_container_view_->app_list_folder_view() | 106 if (apps_container_view_->app_list_folder_view() |
99 ->items_grid_view() | 107 ->items_grid_view() |
100 ->has_dragged_view()) { | 108 ->has_dragged_view()) { |
101 apps_container_view_->app_list_folder_view()->items_grid_view()->EndDrag( | 109 apps_container_view_->app_list_folder_view()->items_grid_view()->EndDrag( |
102 true); | 110 true); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 int ContentsView::NumLauncherPages() const { | 155 int ContentsView::NumLauncherPages() const { |
148 return pagination_model_.total_pages(); | 156 return pagination_model_.total_pages(); |
149 } | 157 } |
150 | 158 |
151 void ContentsView::SetActivePageInternal(int page_index, | 159 void ContentsView::SetActivePageInternal(int page_index, |
152 bool show_search_results) { | 160 bool show_search_results) { |
153 if (!show_search_results) | 161 if (!show_search_results) |
154 page_before_search_ = page_index; | 162 page_before_search_ = page_index; |
155 // Start animating to the new page. | 163 // Start animating to the new page. |
156 pagination_model_.SelectPage(page_index, true); | 164 pagination_model_.SelectPage(page_index, true); |
157 ActivePageChanged(show_search_results); | 165 ActivePageChanged(); |
158 } | 166 } |
159 | 167 |
160 void ContentsView::ActivePageChanged(bool show_search_results) { | 168 void ContentsView::ActivePageChanged() { |
161 AppListModel::State state = AppListModel::INVALID_STATE; | 169 AppListModel::State state = AppListModel::INVALID_STATE; |
162 | 170 |
163 // TODO(calamity): This does not report search results being shown in the | 171 // TODO(calamity): This does not report search results being shown in the |
164 // experimental app list as a boolean is currently used to indicate whether | 172 // experimental app list as a boolean is currently used to indicate whether |
165 // search results are showing. See http://crbug.com/427787/. | 173 // search results are showing. See http://crbug.com/427787/. |
166 std::map<int, AppListModel::State>::const_iterator it = | 174 std::map<int, AppListModel::State>::const_iterator it = |
167 view_to_state_.find(pagination_model_.SelectedTargetPage()); | 175 view_to_state_.find(pagination_model_.SelectedTargetPage()); |
168 if (it != view_to_state_.end()) | 176 if (it != view_to_state_.end()) |
169 state = it->second; | 177 state = it->second; |
170 | 178 |
171 app_list_main_view_->model()->SetState(state); | 179 app_list_main_view_->model()->SetState(state); |
172 | 180 |
173 // TODO(xiyuan): Highlight default match instead of the first. | 181 // TODO(xiyuan): Highlight default match instead of the first. |
174 if (IsStateActive(AppListModel::STATE_SEARCH_RESULTS) && | 182 if (IsStateActive(AppListModel::STATE_SEARCH_RESULTS) && |
175 search_results_view_->visible()) { | 183 search_results_list_view_ && search_results_list_view_->visible()) { |
176 search_results_view_->SetSelectedIndex(0); | 184 search_results_list_view_->SetSelectedIndex(0); |
177 } | 185 } |
178 if (search_results_view_) | |
179 search_results_view_->UpdateAutoLaunchState(); | |
180 | 186 |
181 if (IsStateActive(AppListModel::STATE_START)) { | 187 if (search_results_list_view_) |
182 if (show_search_results) | 188 search_results_list_view_->UpdateAutoLaunchState(); |
183 start_page_view_->ShowSearchResults(); | |
184 else | |
185 start_page_view_->Reset(); | |
186 } | |
187 | 189 |
188 // Notify parent AppListMainView of the page change. | 190 // Notify parent AppListMainView of the page change. |
189 app_list_main_view_->UpdateSearchBoxVisibility(); | 191 app_list_main_view_->UpdateSearchBoxVisibility(); |
190 } | 192 } |
191 | 193 |
192 void ContentsView::ShowSearchResults(bool show) { | 194 void ContentsView::ShowSearchResults(bool show) { |
193 int search_page = | 195 int search_page = GetPageIndexForState(AppListModel::STATE_SEARCH_RESULTS); |
194 GetPageIndexForState(app_list::switches::IsExperimentalAppListEnabled() | |
195 ? AppListModel::STATE_START | |
196 : AppListModel::STATE_SEARCH_RESULTS); | |
197 DCHECK_GE(search_page, 0); | 196 DCHECK_GE(search_page, 0); |
198 | 197 |
199 SetActivePageInternal(show ? search_page : page_before_search_, show); | 198 SetActivePageInternal(show ? search_page : page_before_search_, show); |
200 } | 199 } |
201 | 200 |
202 bool ContentsView::IsShowingSearchResults() const { | 201 bool ContentsView::IsShowingSearchResults() const { |
203 return app_list::switches::IsExperimentalAppListEnabled() | 202 return IsStateActive(AppListModel::STATE_SEARCH_RESULTS); |
204 ? IsStateActive(AppListModel::STATE_START) && | |
205 start_page_view_->IsShowingSearchResults() | |
206 : IsStateActive(AppListModel::STATE_SEARCH_RESULTS); | |
207 } | 203 } |
208 | 204 |
209 gfx::Rect ContentsView::GetOffscreenPageBounds(int page_index) const { | 205 gfx::Rect ContentsView::GetOffscreenPageBounds(int page_index) const { |
210 gfx::Rect bounds(GetContentsBounds()); | 206 gfx::Rect bounds(GetContentsBounds()); |
211 // The start page and search page origins are above; all other pages' origins | 207 // The start page and search page origins are above; all other pages' origins |
212 // are below. | 208 // are below. |
213 int page_height = bounds.height(); | 209 int page_height = bounds.height(); |
214 bool origin_above = | 210 bool origin_above = |
215 GetPageIndexForState(AppListModel::STATE_START) == page_index || | 211 GetPageIndexForState(AppListModel::STATE_START) == page_index || |
216 GetPageIndexForState(AppListModel::STATE_SEARCH_RESULTS) == page_index; | 212 GetPageIndexForState(AppListModel::STATE_SEARCH_RESULTS) == page_index; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 | 302 |
307 gfx::Rect ContentsView::GetDefaultContentsBounds() const { | 303 gfx::Rect ContentsView::GetDefaultContentsBounds() const { |
308 gfx::Rect bounds(gfx::Point(0, GetDefaultSearchBoxBounds().bottom()), | 304 gfx::Rect bounds(gfx::Point(0, GetDefaultSearchBoxBounds().bottom()), |
309 GetDefaultContentsSize()); | 305 GetDefaultContentsSize()); |
310 return bounds; | 306 return bounds; |
311 } | 307 } |
312 | 308 |
313 gfx::Size ContentsView::GetDefaultContentsSize() const { | 309 gfx::Size ContentsView::GetDefaultContentsSize() const { |
314 const gfx::Size container_size = | 310 const gfx::Size container_size = |
315 apps_container_view_->apps_grid_view()->GetPreferredSize(); | 311 apps_container_view_->apps_grid_view()->GetPreferredSize(); |
316 const gfx::Size results_size = search_results_view_ | 312 const gfx::Size results_size = |
317 ? search_results_view_->GetPreferredSize() | 313 search_results_list_view_ ? search_results_list_view_->GetPreferredSize() |
318 : gfx::Size(); | 314 : gfx::Size(); |
319 | 315 |
320 int width = std::max(container_size.width(), results_size.width()); | 316 int width = std::max(container_size.width(), results_size.width()); |
321 int height = std::max(container_size.height(), results_size.height()); | 317 int height = std::max(container_size.height(), results_size.height()); |
322 return gfx::Size(width, height); | 318 return gfx::Size(width, height); |
323 } | 319 } |
324 | 320 |
325 gfx::Size ContentsView::GetPreferredSize() const { | 321 gfx::Size ContentsView::GetPreferredSize() const { |
326 gfx::Rect search_box_bounds = GetDefaultSearchBoxBounds(); | 322 gfx::Rect search_box_bounds = GetDefaultSearchBoxBounds(); |
327 gfx::Rect default_contents_bounds = GetDefaultContentsBounds(); | 323 gfx::Rect default_contents_bounds = GetDefaultContentsBounds(); |
328 gfx::Vector2d bottom_right = | 324 gfx::Vector2d bottom_right = |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 } | 359 } |
364 | 360 |
365 void ContentsView::TransitionStarted() { | 361 void ContentsView::TransitionStarted() { |
366 } | 362 } |
367 | 363 |
368 void ContentsView::TransitionChanged() { | 364 void ContentsView::TransitionChanged() { |
369 UpdatePageBounds(); | 365 UpdatePageBounds(); |
370 } | 366 } |
371 | 367 |
372 } // namespace app_list | 368 } // namespace app_list |
OLD | NEW |