Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: ui/app_list/views/contents_view.cc

Issue 660463003: Add a SearchResultPageView to the experimental app list. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@search_result_container_view
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/app_list/views/contents_view.h ('k') | ui/app_list/views/search_result_page_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_(nullptr),
32 start_page_view_(NULL), 33 search_results_list_view_(nullptr),
34 search_results_page_view_(nullptr),
35 start_page_view_(nullptr),
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_(nullptr),
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
42 ContentsView::~ContentsView() { 45 ContentsView::~ContentsView() {
43 pagination_model_.RemoveObserver(this); 46 pagination_model_.RemoveObserver(this);
44 if (contents_switcher_view_) 47 if (contents_switcher_view_)
(...skipping 17 matching lines...) Expand all
62 AddLauncherPage(*it, IDR_APP_LIST_NOTIFICATIONS_ICON, 65 AddLauncherPage(*it, 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(search_results_page_view_, 0,
79 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(search_results_list_view_, 0,
76 search_results_view_, 0, AppListModel::STATE_SEARCH_RESULTS); 84 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
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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 318
323 gfx::Rect ContentsView::GetDefaultContentsBounds() const { 319 gfx::Rect ContentsView::GetDefaultContentsBounds() const {
324 gfx::Rect bounds(gfx::Point(0, GetDefaultSearchBoxBounds().bottom()), 320 gfx::Rect bounds(gfx::Point(0, GetDefaultSearchBoxBounds().bottom()),
325 GetDefaultContentsSize()); 321 GetDefaultContentsSize());
326 return bounds; 322 return bounds;
327 } 323 }
328 324
329 gfx::Size ContentsView::GetDefaultContentsSize() const { 325 gfx::Size ContentsView::GetDefaultContentsSize() const {
330 const gfx::Size container_size = 326 const gfx::Size container_size =
331 apps_container_view_->apps_grid_view()->GetPreferredSize(); 327 apps_container_view_->apps_grid_view()->GetPreferredSize();
332 const gfx::Size results_size = search_results_view_ 328 const gfx::Size results_size =
333 ? search_results_view_->GetPreferredSize() 329 search_results_list_view_ ? search_results_list_view_->GetPreferredSize()
334 : gfx::Size(); 330 : gfx::Size();
335 331
336 int width = std::max(container_size.width(), results_size.width()); 332 int width = std::max(container_size.width(), results_size.width());
337 int height = std::max(container_size.height(), results_size.height()); 333 int height = std::max(container_size.height(), results_size.height());
338 return gfx::Size(width, height); 334 return gfx::Size(width, height);
339 } 335 }
340 336
341 gfx::Size ContentsView::GetPreferredSize() const { 337 gfx::Size ContentsView::GetPreferredSize() const {
342 gfx::Rect search_box_bounds = GetDefaultSearchBoxBounds(); 338 gfx::Rect search_box_bounds = GetDefaultSearchBoxBounds();
343 gfx::Rect default_contents_bounds = GetDefaultContentsBounds(); 339 gfx::Rect default_contents_bounds = GetDefaultContentsBounds();
344 gfx::Vector2d bottom_right = 340 gfx::Vector2d bottom_right =
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 } 375 }
380 376
381 void ContentsView::TransitionStarted() { 377 void ContentsView::TransitionStarted() {
382 } 378 }
383 379
384 void ContentsView::TransitionChanged() { 380 void ContentsView::TransitionChanged() {
385 UpdatePageBounds(); 381 UpdatePageBounds();
386 } 382 }
387 383
388 } // namespace app_list 384 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/views/contents_view.h ('k') | ui/app_list/views/search_result_page_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698