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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 | 42 |
43 ContentsView::~ContentsView() { | 43 ContentsView::~ContentsView() { |
44 pagination_model_.RemoveObserver(this); | 44 pagination_model_.RemoveObserver(this); |
45 } | 45 } |
46 | 46 |
47 void ContentsView::Init(AppListModel* model) { | 47 void ContentsView::Init(AppListModel* model) { |
48 DCHECK(model); | 48 DCHECK(model); |
49 | 49 |
50 AppListViewDelegate* view_delegate = app_list_main_view_->view_delegate(); | 50 AppListViewDelegate* view_delegate = app_list_main_view_->view_delegate(); |
51 | 51 |
52 if (app_list::switches::IsExperimentalAppListEnabled()) { | 52 std::vector<views::View*> custom_page_views = |
53 std::vector<views::View*> custom_page_views = | 53 view_delegate->CreateCustomPageWebViews(GetLocalBounds().size()); |
54 view_delegate->CreateCustomPageWebViews(GetLocalBounds().size()); | 54 // Only add the first custom page view as STATE_CUSTOM_LAUNCHER_PAGE. Ignore |
55 // Only add the first custom page view as STATE_CUSTOM_LAUNCHER_PAGE. Ignore | 55 // any subsequent custom pages. |
56 // any subsequent custom pages. | 56 if (!custom_page_views.empty()) { |
57 if (!custom_page_views.empty()) { | 57 custom_page_view_ = new CustomLauncherPageView(custom_page_views[0]); |
58 custom_page_view_ = new CustomLauncherPageView(custom_page_views[0]); | |
59 | 58 |
60 AddLauncherPage(custom_page_view_, | 59 AddLauncherPage(custom_page_view_, |
61 AppListModel::STATE_CUSTOM_LAUNCHER_PAGE); | 60 AppListModel::STATE_CUSTOM_LAUNCHER_PAGE); |
62 } | 61 } |
63 | 62 |
64 // Start page. | 63 // Start page. |
65 start_page_view_ = new StartPageView(app_list_main_view_, view_delegate); | 64 start_page_view_ = new StartPageView(app_list_main_view_, view_delegate); |
66 AddLauncherPage(start_page_view_, AppListModel::STATE_START); | 65 AddLauncherPage(start_page_view_, AppListModel::STATE_START); |
67 } | |
68 | 66 |
69 // Search results UI. | 67 // Search results UI. |
70 search_results_page_view_ = new SearchResultPageView(); | 68 search_results_page_view_ = new SearchResultPageView(); |
71 | 69 |
72 AppListModel::SearchResults* results = view_delegate->GetModel()->results(); | 70 AppListModel::SearchResults* results = view_delegate->GetModel()->results(); |
73 search_results_page_view_->AddSearchResultContainerView( | 71 search_results_page_view_->AddSearchResultContainerView( |
74 results, new SearchResultListView(app_list_main_view_, view_delegate)); | 72 results, new SearchResultListView(app_list_main_view_, view_delegate)); |
75 | 73 |
76 if (app_list::switches::IsExperimentalAppListEnabled()) { | 74 search_results_page_view_->AddSearchResultContainerView( |
77 search_results_page_view_->AddSearchResultContainerView( | 75 results, new SearchResultTileItemListView( |
78 results, new SearchResultTileItemListView( | 76 GetSearchBoxView()->search_box(), view_delegate)); |
79 GetSearchBoxView()->search_box(), view_delegate)); | |
80 } | |
81 AddLauncherPage(search_results_page_view_, | 77 AddLauncherPage(search_results_page_view_, |
82 AppListModel::STATE_SEARCH_RESULTS); | 78 AppListModel::STATE_SEARCH_RESULTS); |
83 | 79 |
84 apps_container_view_ = new AppsContainerView(app_list_main_view_, model); | 80 apps_container_view_ = new AppsContainerView(app_list_main_view_, model); |
85 | 81 |
86 AddLauncherPage(apps_container_view_, AppListModel::STATE_APPS); | 82 AddLauncherPage(apps_container_view_, AppListModel::STATE_APPS); |
87 | 83 |
88 int initial_page_index = app_list::switches::IsExperimentalAppListEnabled() | 84 int initial_page_index = GetPageIndexForState(AppListModel::STATE_START); |
89 ? GetPageIndexForState(AppListModel::STATE_START) | |
90 : GetPageIndexForState(AppListModel::STATE_APPS); | |
91 DCHECK_GE(initial_page_index, 0); | 85 DCHECK_GE(initial_page_index, 0); |
92 | 86 |
93 page_before_search_ = initial_page_index; | 87 page_before_search_ = initial_page_index; |
94 // Must only call SetTotalPages once all the launcher pages have been added | 88 // Must only call SetTotalPages once all the launcher pages have been added |
95 // (as it will trigger a SelectedPageChanged call). | 89 // (as it will trigger a SelectedPageChanged call). |
96 pagination_model_.SetTotalPages(app_list_pages_.size()); | 90 pagination_model_.SetTotalPages(app_list_pages_.size()); |
97 | 91 |
98 // Page 0 is selected by SetTotalPages and needs to be 'hidden' when selecting | 92 // Page 0 is selected by SetTotalPages and needs to be 'hidden' when selecting |
99 // the initial page. | 93 // the initial page. |
100 app_list_pages_[GetActivePageIndex()]->OnWillBeHidden(); | 94 app_list_pages_[GetActivePageIndex()]->OnWillBeHidden(); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 | 187 |
194 std::map<int, AppListModel::State>::const_iterator it = | 188 std::map<int, AppListModel::State>::const_iterator it = |
195 view_to_state_.find(GetActivePageIndex()); | 189 view_to_state_.find(GetActivePageIndex()); |
196 if (it != view_to_state_.end()) | 190 if (it != view_to_state_.end()) |
197 state = it->second; | 191 state = it->second; |
198 | 192 |
199 app_list_pages_[GetActivePageIndex()]->OnWillBeShown(); | 193 app_list_pages_[GetActivePageIndex()]->OnWillBeShown(); |
200 | 194 |
201 app_list_main_view_->model()->SetState(state); | 195 app_list_main_view_->model()->SetState(state); |
202 | 196 |
203 if (switches::IsExperimentalAppListEnabled()) { | 197 DCHECK(start_page_view_); |
204 DCHECK(start_page_view_); | |
205 | 198 |
206 // Set the visibility of the search box's back button. | 199 // Set the visibility of the search box's back button. |
207 app_list_main_view_->search_box_view()->back_button()->SetVisible( | 200 app_list_main_view_->search_box_view()->back_button()->SetVisible( |
208 state != AppListModel::STATE_START); | 201 state != AppListModel::STATE_START); |
209 app_list_main_view_->search_box_view()->Layout(); | 202 app_list_main_view_->search_box_view()->Layout(); |
210 bool folder_active = (state == AppListModel::STATE_APPS) | 203 bool folder_active = (state == AppListModel::STATE_APPS) |
211 ? apps_container_view_->IsInFolderView() : false; | 204 ? apps_container_view_->IsInFolderView() |
212 app_list_main_view_->search_box_view()->SetBackButtonLabel(folder_active); | 205 : false; |
| 206 app_list_main_view_->search_box_view()->SetBackButtonLabel(folder_active); |
213 | 207 |
214 // Whenever the page changes, the custom launcher page is considered to have | 208 // Whenever the page changes, the custom launcher page is considered to have |
215 // been reset. | 209 // been reset. |
216 app_list_main_view_->model()->ClearCustomLauncherPageSubpages(); | 210 app_list_main_view_->model()->ClearCustomLauncherPageSubpages(); |
217 } | |
218 | |
219 app_list_main_view_->search_box_view()->ResetTabFocus(false); | 211 app_list_main_view_->search_box_view()->ResetTabFocus(false); |
220 } | 212 } |
221 | 213 |
222 void ContentsView::ShowSearchResults(bool show) { | 214 void ContentsView::ShowSearchResults(bool show) { |
223 int search_page = GetPageIndexForState(AppListModel::STATE_SEARCH_RESULTS); | 215 int search_page = GetPageIndexForState(AppListModel::STATE_SEARCH_RESULTS); |
224 DCHECK_GE(search_page, 0); | 216 DCHECK_GE(search_page, 0); |
225 | 217 |
226 search_results_page_view_->ClearSelectedIndex(); | 218 search_results_page_view_->ClearSelectedIndex(); |
227 | 219 |
228 SetActiveStateInternal(show ? search_page : page_before_search_, show, true); | 220 SetActiveStateInternal(show ? search_page : page_before_search_, show, true); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 view_to_state_.insert(std::make_pair(page_index, state)).second; | 345 view_to_state_.insert(std::make_pair(page_index, state)).second; |
354 | 346 |
355 // There shouldn't be duplicates in either map. | 347 // There shouldn't be duplicates in either map. |
356 DCHECK(success); | 348 DCHECK(success); |
357 return page_index; | 349 return page_index; |
358 } | 350 } |
359 | 351 |
360 gfx::Rect ContentsView::GetDefaultSearchBoxBounds() const { | 352 gfx::Rect ContentsView::GetDefaultSearchBoxBounds() const { |
361 gfx::Rect search_box_bounds(0, 0, GetDefaultContentsSize().width(), | 353 gfx::Rect search_box_bounds(0, 0, GetDefaultContentsSize().width(), |
362 GetSearchBoxView()->GetPreferredSize().height()); | 354 GetSearchBoxView()->GetPreferredSize().height()); |
363 if (switches::IsExperimentalAppListEnabled()) { | 355 search_box_bounds.set_y(kSearchBoxPadding); |
364 search_box_bounds.set_y(kExperimentalSearchBoxPadding); | 356 search_box_bounds.Inset(kSearchBoxPadding, 0); |
365 search_box_bounds.Inset(kExperimentalSearchBoxPadding, 0); | |
366 } | |
367 return search_box_bounds; | 357 return search_box_bounds; |
368 } | 358 } |
369 | 359 |
370 gfx::Rect ContentsView::GetSearchBoxBoundsForState( | 360 gfx::Rect ContentsView::GetSearchBoxBoundsForState( |
371 AppListModel::State state) const { | 361 AppListModel::State state) const { |
372 AppListPage* page = GetPageView(GetPageIndexForState(state)); | 362 AppListPage* page = GetPageView(GetPageIndexForState(state)); |
373 return page->GetSearchBoxBounds(); | 363 return page->GetSearchBoxBounds(); |
374 } | 364 } |
375 | 365 |
376 gfx::Rect ContentsView::GetDefaultContentsBounds() const { | 366 gfx::Rect ContentsView::GetDefaultContentsBounds() const { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 } | 466 } |
477 | 467 |
478 void ContentsView::TransitionStarted() { | 468 void ContentsView::TransitionStarted() { |
479 } | 469 } |
480 | 470 |
481 void ContentsView::TransitionChanged() { | 471 void ContentsView::TransitionChanged() { |
482 UpdatePageBounds(); | 472 UpdatePageBounds(); |
483 } | 473 } |
484 | 474 |
485 } // namespace app_list | 475 } // namespace app_list |
OLD | NEW |