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

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

Issue 307333002: Add search results to experimental app list start page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments, fix for breaking a test Created 6 years, 6 months 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 | Annotate | Revision Log
« no previous file with comments | « ui/app_list/views/contents_view.h ('k') | ui/app_list/views/search_result_list_view.cc » ('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 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "ui/app_list/app_list_constants.h" 10 #include "ui/app_list/app_list_constants.h"
(...skipping 19 matching lines...) Expand all
30 const int kMinScrollToSwitchPage = 20; 30 const int kMinScrollToSwitchPage = 20;
31 const int kMinHorizVelocityToSwitchPage = 800; 31 const int kMinHorizVelocityToSwitchPage = 800;
32 32
33 const double kFinishTransitionThreshold = 0.33; 33 const double kFinishTransitionThreshold = 0.33;
34 34
35 } // namespace 35 } // namespace
36 36
37 ContentsView::ContentsView(AppListMainView* app_list_main_view, 37 ContentsView::ContentsView(AppListMainView* app_list_main_view,
38 AppListModel* model, 38 AppListModel* model,
39 AppListViewDelegate* view_delegate) 39 AppListViewDelegate* view_delegate)
40 : start_page_view_(NULL), 40 : search_results_view_(NULL),
41 start_page_view_(NULL),
41 app_list_main_view_(app_list_main_view), 42 app_list_main_view_(app_list_main_view),
42 view_model_(new views::ViewModel), 43 view_model_(new views::ViewModel),
43 bounds_animator_(new views::BoundsAnimator(this)) { 44 bounds_animator_(new views::BoundsAnimator(this)) {
44 DCHECK(model); 45 DCHECK(model);
45 46
46 search_results_view_ =
47 new SearchResultListView(app_list_main_view, view_delegate);
48 AddLauncherPage(search_results_view_, NAMED_PAGE_SEARCH_RESULTS);
49
50 if (app_list::switches::IsExperimentalAppListEnabled()) { 47 if (app_list::switches::IsExperimentalAppListEnabled()) {
51 start_page_view_ = new StartPageView(app_list_main_view, view_delegate); 48 start_page_view_ = new StartPageView(app_list_main_view, view_delegate);
52 AddLauncherPage(start_page_view_, NAMED_PAGE_START); 49 AddLauncherPage(start_page_view_, NAMED_PAGE_START);
50 } else {
51 search_results_view_ =
52 new SearchResultListView(app_list_main_view, view_delegate);
53 AddLauncherPage(search_results_view_, NAMED_PAGE_SEARCH_RESULTS);
54 search_results_view_->SetResults(model->results());
53 } 55 }
54 56
55 apps_container_view_ = new AppsContainerView(app_list_main_view, model); 57 apps_container_view_ = new AppsContainerView(app_list_main_view, model);
56 active_page_ = AddLauncherPage(apps_container_view_, NAMED_PAGE_APPS); 58 active_page_ = AddLauncherPage(apps_container_view_, NAMED_PAGE_APPS);
57 59
58 search_results_view_->SetResults(model->results());
59 } 60 }
60 61
61 ContentsView::~ContentsView() { 62 ContentsView::~ContentsView() {
62 } 63 }
63 64
64 void ContentsView::CancelDrag() { 65 void ContentsView::CancelDrag() {
65 if (apps_container_view_->apps_grid_view()->has_dragged_view()) 66 if (apps_container_view_->apps_grid_view()->has_dragged_view())
66 apps_container_view_->apps_grid_view()->EndDrag(true); 67 apps_container_view_->apps_grid_view()->EndDrag(true);
67 if (apps_container_view_->app_list_folder_view() 68 if (apps_container_view_->app_list_folder_view()
68 ->items_grid_view() 69 ->items_grid_view()
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 DCHECK(it != named_page_to_view_.end()); 103 DCHECK(it != named_page_to_view_.end());
103 return it->second; 104 return it->second;
104 } 105 }
105 106
106 void ContentsView::ActivePageChanged() { 107 void ContentsView::ActivePageChanged() {
107 // TODO(xiyuan): Highlight default match instead of the first. 108 // TODO(xiyuan): Highlight default match instead of the first.
108 if (IsNamedPageActive(NAMED_PAGE_SEARCH_RESULTS) && 109 if (IsNamedPageActive(NAMED_PAGE_SEARCH_RESULTS) &&
109 search_results_view_->visible()) { 110 search_results_view_->visible()) {
110 search_results_view_->SetSelectedIndex(0); 111 search_results_view_->SetSelectedIndex(0);
111 } 112 }
112 search_results_view_->UpdateAutoLaunchState(); 113 if (search_results_view_)
113 114 search_results_view_->UpdateAutoLaunchState();
114 // Notify parent AppListMainView of the page change.
115 app_list_main_view_->OnContentsViewActivePageChanged();
116 115
117 if (IsNamedPageActive(NAMED_PAGE_START)) 116 if (IsNamedPageActive(NAMED_PAGE_START))
118 start_page_view_->Reset(); 117 start_page_view_->Reset();
119 118
119 // Notify parent AppListMainView of the page change.
120 app_list_main_view_->UpdateSearchBoxVisibility();
121
120 AnimateToIdealBounds(); 122 AnimateToIdealBounds();
121 } 123 }
122 124
125 void ContentsView::ShowSearchResults(bool show) {
126 NamedPage new_named_page = show ? NAMED_PAGE_SEARCH_RESULTS : NAMED_PAGE_APPS;
127 if (app_list::switches::IsExperimentalAppListEnabled())
128 new_named_page = NAMED_PAGE_START;
129
130 SetActivePage(GetPageIndexForNamedPage(new_named_page));
131
132 if (app_list::switches::IsExperimentalAppListEnabled()) {
133 if (show)
134 start_page_view_->ShowSearchResults();
135 else
136 start_page_view_->Reset();
137 app_list_main_view_->UpdateSearchBoxVisibility();
138 }
139 }
140
141 bool ContentsView::IsShowingSearchResults() const {
142 return app_list::switches::IsExperimentalAppListEnabled()
143 ? IsNamedPageActive(NAMED_PAGE_START) &&
144 start_page_view_->IsShowingSearchResults()
145 : IsNamedPageActive(NAMED_PAGE_SEARCH_RESULTS);
146 }
147
123 void ContentsView::CalculateIdealBounds() { 148 void ContentsView::CalculateIdealBounds() {
124 gfx::Rect rect(GetContentsBounds()); 149 gfx::Rect rect(GetContentsBounds());
125 if (rect.IsEmpty()) 150 if (rect.IsEmpty())
126 return; 151 return;
127 152
128 if (app_list::switches::IsExperimentalAppListEnabled()) { 153 if (app_list::switches::IsExperimentalAppListEnabled()) {
129 gfx::Rect incoming_target(rect); 154 gfx::Rect incoming_target(rect);
130 gfx::Rect outgoing_target(rect); 155 gfx::Rect outgoing_target(rect);
131 outgoing_target.set_x(-outgoing_target.width()); 156 outgoing_target.set_x(-outgoing_target.width());
132 157
(...skipping 29 matching lines...) Expand all
162 for (int i = 0; i < view_model_->view_size(); ++i) { 187 for (int i = 0; i < view_model_->view_size(); ++i) {
163 bounds_animator_->AnimateViewTo(view_model_->view_at(i), 188 bounds_animator_->AnimateViewTo(view_model_->view_at(i),
164 view_model_->ideal_bounds(i)); 189 view_model_->ideal_bounds(i));
165 } 190 }
166 } 191 }
167 192
168 PaginationModel* ContentsView::GetAppsPaginationModel() { 193 PaginationModel* ContentsView::GetAppsPaginationModel() {
169 return apps_container_view_->apps_grid_view()->pagination_model(); 194 return apps_container_view_->apps_grid_view()->pagination_model();
170 } 195 }
171 196
172 void ContentsView::ShowSearchResults(bool show) {
173 NamedPage new_named_page = show ? NAMED_PAGE_SEARCH_RESULTS : NAMED_PAGE_APPS;
174 SetActivePage(GetPageIndexForNamedPage(new_named_page));
175 }
176
177 void ContentsView::ShowFolderContent(AppListFolderItem* item) { 197 void ContentsView::ShowFolderContent(AppListFolderItem* item) {
178 apps_container_view_->ShowActiveFolder(item); 198 apps_container_view_->ShowActiveFolder(item);
179 } 199 }
180 200
181 void ContentsView::Prerender() { 201 void ContentsView::Prerender() {
182 const int selected_page = 202 const int selected_page =
183 std::max(0, GetAppsPaginationModel()->selected_page()); 203 std::max(0, GetAppsPaginationModel()->selected_page());
184 apps_container_view_->apps_grid_view()->Prerender(selected_page); 204 apps_container_view_->apps_grid_view()->Prerender(selected_page);
185 } 205 }
186 206
187 int ContentsView::AddLauncherPage(views::View* view) { 207 int ContentsView::AddLauncherPage(views::View* view) {
188 int page_index = view_model_->view_size(); 208 int page_index = view_model_->view_size();
189 AddChildView(view); 209 AddChildView(view);
190 view_model_->Add(view, page_index); 210 view_model_->Add(view, page_index);
191 return page_index; 211 return page_index;
192 } 212 }
193 213
194 int ContentsView::AddLauncherPage(views::View* view, NamedPage named_page) { 214 int ContentsView::AddLauncherPage(views::View* view, NamedPage named_page) {
195 int page_index = AddLauncherPage(view); 215 int page_index = AddLauncherPage(view);
196 named_page_to_view_.insert(std::pair<NamedPage, int>(named_page, page_index)); 216 named_page_to_view_.insert(std::pair<NamedPage, int>(named_page, page_index));
197 return page_index; 217 return page_index;
198 } 218 }
199 219
200 gfx::Size ContentsView::GetPreferredSize() const { 220 gfx::Size ContentsView::GetPreferredSize() const {
201 const gfx::Size container_size = 221 const gfx::Size container_size =
202 apps_container_view_->apps_grid_view()->GetPreferredSize(); 222 apps_container_view_->apps_grid_view()->GetPreferredSize();
203 const gfx::Size results_size = search_results_view_->GetPreferredSize(); 223 const gfx::Size results_size = search_results_view_
224 ? search_results_view_->GetPreferredSize()
225 : gfx::Size();
204 226
205 int width = std::max(container_size.width(), results_size.width()); 227 int width = std::max(container_size.width(), results_size.width());
206 int height = std::max(container_size.height(), results_size.height()); 228 int height = std::max(container_size.height(), results_size.height());
207 return gfx::Size(width, height); 229 return gfx::Size(width, height);
208 } 230 }
209 231
210 void ContentsView::Layout() { 232 void ContentsView::Layout() {
211 CalculateIdealBounds(); 233 CalculateIdealBounds();
212 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); 234 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_);
213 } 235 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 if (std::abs(offset) > kMinScrollToSwitchPage) { 309 if (std::abs(offset) > kMinScrollToSwitchPage) {
288 if (!GetAppsPaginationModel()->has_transition()) { 310 if (!GetAppsPaginationModel()->has_transition()) {
289 GetAppsPaginationModel()->SelectPageRelative(offset > 0 ? -1 : 1, true); 311 GetAppsPaginationModel()->SelectPageRelative(offset > 0 ? -1 : 1, true);
290 } 312 }
291 event->SetHandled(); 313 event->SetHandled();
292 event->StopPropagation(); 314 event->StopPropagation();
293 } 315 }
294 } 316 }
295 317
296 } // namespace app_list 318 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/views/contents_view.h ('k') | ui/app_list/views/search_result_list_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698