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

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: 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
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 10 matching lines...) Expand all
21 #include "ui/views/animation/bounds_animator.h" 21 #include "ui/views/animation/bounds_animator.h"
22 #include "ui/views/view_model.h" 22 #include "ui/views/view_model.h"
23 #include "ui/views/view_model_utils.h" 23 #include "ui/views/view_model_utils.h"
24 24
25 namespace app_list { 25 namespace app_list {
26 26
27 namespace { 27 namespace {
28 28
29 // Indexes of interesting views in ViewModel of ContentsView. 29 // Indexes of interesting views in ViewModel of ContentsView.
30 const int kIndexAppsContainer = 0; 30 const int kIndexAppsContainer = 0;
31 // Only one of these views is created depending on whether the experimental app
32 // list is enabled.
31 const int kIndexSearchResults = 1; 33 const int kIndexSearchResults = 1;
32 const int kIndexStartPage = 2; 34 const int kIndexStartPage = 1;
33 35
34 const int kMinMouseWheelToSwitchPage = 20; 36 const int kMinMouseWheelToSwitchPage = 20;
35 const int kMinScrollToSwitchPage = 20; 37 const int kMinScrollToSwitchPage = 20;
36 const int kMinHorizVelocityToSwitchPage = 800; 38 const int kMinHorizVelocityToSwitchPage = 800;
37 39
38 const double kFinishTransitionThreshold = 0.33; 40 const double kFinishTransitionThreshold = 0.33;
39 41
40 AppsContainerView* GetAppsContainerView(views::ViewModel* model) { 42 AppsContainerView* GetAppsContainerView(views::ViewModel* model) {
41 return static_cast<AppsContainerView*>(model->view_at(kIndexAppsContainer)); 43 return static_cast<AppsContainerView*>(model->view_at(kIndexAppsContainer));
42 } 44 }
43 45
44 SearchResultListView* GetSearchResultListView(views::ViewModel* model) { 46 SearchResultListView* GetSearchResultListView(views::ViewModel* model) {
47 DCHECK(!app_list::switches::IsExperimentalAppListEnabled());
45 return static_cast<SearchResultListView*>( 48 return static_cast<SearchResultListView*>(
46 model->view_at(kIndexSearchResults)); 49 model->view_at(kIndexSearchResults));
47 } 50 }
48 51
49 StartPageView* GetStartPageView(views::ViewModel* model) { 52 StartPageView* GetStartPageView(views::ViewModel* model) {
53 DCHECK(app_list::switches::IsExperimentalAppListEnabled());
50 return static_cast<StartPageView*>(model->view_at(kIndexStartPage)); 54 return static_cast<StartPageView*>(model->view_at(kIndexStartPage));
51 } 55 }
52 56
53 } // namespace 57 } // namespace
54 58
55 ContentsView::ContentsView(AppListMainView* app_list_main_view, 59 ContentsView::ContentsView(AppListMainView* app_list_main_view,
56 PaginationModel* pagination_model, 60 PaginationModel* pagination_model,
57 AppListModel* model, 61 AppListModel* model,
58 AppListViewDelegate* view_delegate) 62 AppListViewDelegate* view_delegate)
59 : show_state_(SHOW_APPS), 63 : show_state_(SHOW_APPS),
60 pagination_model_(pagination_model), 64 pagination_model_(pagination_model),
61 start_page_view_(NULL), 65 start_page_view_(NULL),
62 app_list_main_view_(app_list_main_view), 66 app_list_main_view_(app_list_main_view),
63 view_model_(new views::ViewModel), 67 view_model_(new views::ViewModel),
64 bounds_animator_(new views::BoundsAnimator(this)) { 68 bounds_animator_(new views::BoundsAnimator(this)) {
65 DCHECK(model); 69 DCHECK(model);
66 pagination_model_->SetTransitionDurations( 70 pagination_model_->SetTransitionDurations(
67 kPageTransitionDurationInMs, 71 kPageTransitionDurationInMs,
68 kOverscrollPageTransitionDurationMs); 72 kOverscrollPageTransitionDurationMs);
69 73
70 apps_container_view_ = 74 apps_container_view_ =
71 new AppsContainerView(app_list_main_view, pagination_model, model); 75 new AppsContainerView(app_list_main_view, pagination_model, model);
72 AddChildView(apps_container_view_); 76 AddChildView(apps_container_view_);
73 view_model_->Add(apps_container_view_, kIndexAppsContainer); 77 view_model_->Add(apps_container_view_, kIndexAppsContainer);
74 78
75 SearchResultListView* search_results_view = new SearchResultListView(
76 app_list_main_view, view_delegate);
77 AddChildView(search_results_view);
78 view_model_->Add(search_results_view, kIndexSearchResults);
79
80 if (app_list::switches::IsExperimentalAppListEnabled()) { 79 if (app_list::switches::IsExperimentalAppListEnabled()) {
81 start_page_view_ = new StartPageView(app_list_main_view, view_delegate); 80 start_page_view_ = new StartPageView(app_list_main_view, view_delegate);
82 AddChildView(start_page_view_); 81 AddChildView(start_page_view_);
83 view_model_->Add(start_page_view_, kIndexStartPage); 82 view_model_->Add(start_page_view_, kIndexStartPage);
83 } else {
84 SearchResultListView* search_results_view =
85 new SearchResultListView(app_list_main_view, view_delegate);
86 AddChildView(search_results_view);
87 view_model_->Add(search_results_view, kIndexSearchResults);
88 GetSearchResultListView(view_model_.get())->SetResults(model->results());
84 } 89 }
85 90
86 GetSearchResultListView(view_model_.get())->SetResults(model->results());
87 } 91 }
88 92
89 ContentsView::~ContentsView() { 93 ContentsView::~ContentsView() {
90 } 94 }
91 95
92 void ContentsView::CancelDrag() { 96 void ContentsView::CancelDrag() {
93 if (apps_container_view_->apps_grid_view()->has_dragged_view()) 97 if (apps_container_view_->apps_grid_view()->has_dragged_view())
94 apps_container_view_->apps_grid_view()->EndDrag(true); 98 apps_container_view_->apps_grid_view()->EndDrag(true);
95 if (apps_container_view_->app_list_folder_view() 99 if (apps_container_view_->app_list_folder_view()
96 ->items_grid_view() 100 ->items_grid_view()
(...skipping 10 matching lines...) Expand all
107 111
108 void ContentsView::SetShowState(ShowState show_state) { 112 void ContentsView::SetShowState(ShowState show_state) {
109 if (show_state_ == show_state) 113 if (show_state_ == show_state)
110 return; 114 return;
111 115
112 show_state_ = show_state; 116 show_state_ = show_state;
113 ShowStateChanged(); 117 ShowStateChanged();
114 } 118 }
115 119
116 void ContentsView::ShowStateChanged() { 120 void ContentsView::ShowStateChanged() {
117 SearchResultListView* results_view = 121 if (app_list::switches::IsExperimentalAppListEnabled()) {
118 GetSearchResultListView(view_model_.get()); 122 if (show_state_ == SHOW_START_PAGE)
119 // TODO(xiyuan): Highlight default match instead of the first. 123 GetStartPageView(view_model_.get())->Reset();
120 if (show_state_ == SHOW_SEARCH_RESULTS && results_view->visible()) 124 else if (show_state_ == SHOW_SEARCH_RESULTS)
tapted 2014/06/04 06:12:43 Do you need to trigger a start_page-view->results_
calamity 2014/06/12 05:16:56 Done.
121 results_view->SetSelectedIndex(0); 125 GetStartPageView(view_model_.get())->ShowSearchResults();
122 results_view->UpdateAutoLaunchState(); 126 } else {
123 127 SearchResultListView* results_view =
128 GetSearchResultListView(view_model_.get());
129 // TODO(xiyuan): Highlight default match instead of the first.
130 if (show_state_ == SHOW_SEARCH_RESULTS && results_view->visible())
131 results_view->SetSelectedIndex(0);
132 results_view->UpdateAutoLaunchState();
133 }
124 // Notify parent AppListMainView of show state change. 134 // Notify parent AppListMainView of show state change.
125 app_list_main_view_->OnContentsViewShowStateChanged(); 135 app_list_main_view_->OnContentsViewShowStateChanged();
126 136
127 if (show_state_ == SHOW_START_PAGE)
128 GetStartPageView(view_model_.get())->Reset();
129
130 AnimateToIdealBounds(); 137 AnimateToIdealBounds();
131 } 138 }
132 139
133 void ContentsView::CalculateIdealBounds() { 140 void ContentsView::CalculateIdealBounds() {
134 gfx::Rect rect(GetContentsBounds()); 141 gfx::Rect rect(GetContentsBounds());
135 if (rect.IsEmpty()) 142 if (rect.IsEmpty())
136 return; 143 return;
137 144
138 if (app_list::switches::IsExperimentalAppListEnabled()) { 145 if (app_list::switches::IsExperimentalAppListEnabled()) {
139 int incoming_view_index = 0; 146 int incoming_view_index = 0;
140 switch (show_state_) { 147 switch (show_state_) {
141 case SHOW_APPS: 148 case SHOW_APPS:
142 incoming_view_index = kIndexAppsContainer; 149 incoming_view_index = kIndexAppsContainer;
143 break; 150 break;
144 case SHOW_SEARCH_RESULTS: 151 case SHOW_SEARCH_RESULTS: // Falls through.
tapted 2014/06/04 06:12:43 nit: might be slightly less weird to leave this th
calamity 2014/06/12 05:16:56 This is gone.
145 incoming_view_index = kIndexSearchResults;
146 break;
147 case SHOW_START_PAGE: 152 case SHOW_START_PAGE:
148 incoming_view_index = kIndexStartPage; 153 incoming_view_index = kIndexStartPage;
149 break; 154 break;
150 default: 155 default:
151 NOTREACHED(); 156 NOTREACHED();
152 } 157 }
153 158
154 gfx::Rect incoming_target(rect); 159 gfx::Rect incoming_target(rect);
155 gfx::Rect outgoing_target(rect); 160 gfx::Rect outgoing_target(rect);
156 outgoing_target.set_x(-outgoing_target.width()); 161 outgoing_target.set_x(-outgoing_target.width());
(...skipping 30 matching lines...) Expand all
187 } 192 }
188 193
189 void ContentsView::AnimateToIdealBounds() { 194 void ContentsView::AnimateToIdealBounds() {
190 CalculateIdealBounds(); 195 CalculateIdealBounds();
191 for (int i = 0; i < view_model_->view_size(); ++i) { 196 for (int i = 0; i < view_model_->view_size(); ++i) {
192 bounds_animator_->AnimateViewTo(view_model_->view_at(i), 197 bounds_animator_->AnimateViewTo(view_model_->view_at(i),
193 view_model_->ideal_bounds(i)); 198 view_model_->ideal_bounds(i));
194 } 199 }
195 } 200 }
196 201
197 void ContentsView::ShowSearchResults(bool show) {
198 SetShowState(show ? SHOW_SEARCH_RESULTS : SHOW_APPS);
199 }
200
201 void ContentsView::ShowFolderContent(AppListFolderItem* item) { 202 void ContentsView::ShowFolderContent(AppListFolderItem* item) {
202 apps_container_view_->ShowActiveFolder(item); 203 apps_container_view_->ShowActiveFolder(item);
203 } 204 }
204 205
205 void ContentsView::Prerender() { 206 void ContentsView::Prerender() {
206 const int selected_page = std::max(0, pagination_model_->selected_page()); 207 const int selected_page = std::max(0, pagination_model_->selected_page());
207 apps_container_view_->apps_grid_view()->Prerender(selected_page); 208 apps_container_view_->apps_grid_view()->Prerender(selected_page);
208 } 209 }
209 210
210 gfx::Size ContentsView::GetPreferredSize() const { 211 gfx::Size ContentsView::GetPreferredSize() const {
211 const gfx::Size container_size = GetAppsContainerView(view_model_.get())-> 212 const gfx::Size container_size = GetAppsContainerView(view_model_.get())->
212 apps_grid_view()->GetPreferredSize(); 213 apps_grid_view()->GetPreferredSize();
214 if (app_list::switches::IsExperimentalAppListEnabled())
215 return container_size;
213 const gfx::Size results_size = 216 const gfx::Size results_size =
214 GetSearchResultListView(view_model_.get())->GetPreferredSize(); 217 GetSearchResultListView(view_model_.get())->GetPreferredSize();
215 218
tapted 2014/06/04 06:12:43 nit: move this blank line up after the return
calamity 2014/06/12 05:16:56 Also gone.
216 int width = std::max(container_size.width(), results_size.width()); 219 int width = std::max(container_size.width(), results_size.width());
217 int height = std::max(container_size.height(), results_size.height()); 220 int height = std::max(container_size.height(), results_size.height());
218 return gfx::Size(width, height); 221 return gfx::Size(width, height);
219 } 222 }
220 223
221 void ContentsView::Layout() { 224 void ContentsView::Layout() {
222 CalculateIdealBounds(); 225 CalculateIdealBounds();
223 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); 226 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_);
224 } 227 }
225 228
226 bool ContentsView::OnKeyPressed(const ui::KeyEvent& event) { 229 bool ContentsView::OnKeyPressed(const ui::KeyEvent& event) {
227 switch (show_state_) { 230 switch (show_state_) {
228 case SHOW_APPS: 231 case SHOW_APPS:
229 return GetAppsContainerView(view_model_.get())->OnKeyPressed(event); 232 return GetAppsContainerView(view_model_.get())->OnKeyPressed(event);
230 case SHOW_SEARCH_RESULTS: 233 case SHOW_SEARCH_RESULTS:
231 return GetSearchResultListView(view_model_.get())->OnKeyPressed(event); 234 if (app_list::switches::IsExperimentalAppListEnabled())
235 return GetStartPageView(view_model_.get())->OnKeyPressed(event);
236 else
tapted 2014/06/04 06:12:43 nit: no else after a return statement
calamity 2014/06/12 05:16:56 Gone.
237 return GetSearchResultListView(view_model_.get())->OnKeyPressed(event);
232 case SHOW_START_PAGE: 238 case SHOW_START_PAGE:
233 return GetStartPageView(view_model_.get())->OnKeyPressed(event); 239 return GetStartPageView(view_model_.get())->OnKeyPressed(event);
234 default: 240 default:
235 NOTREACHED() << "Unknown show state " << show_state_; 241 NOTREACHED() << "Unknown show state " << show_state_;
236 } 242 }
237 return false; 243 return false;
238 } 244 }
239 245
240 bool ContentsView::OnMouseWheel(const ui::MouseWheelEvent& event) { 246 bool ContentsView::OnMouseWheel(const ui::MouseWheelEvent& event) {
241 if (show_state_ != SHOW_APPS) 247 if (show_state_ != SHOW_APPS)
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 if (!pagination_model_->has_transition()) { 316 if (!pagination_model_->has_transition()) {
311 pagination_model_->SelectPageRelative(offset > 0 ? -1 : 1, 317 pagination_model_->SelectPageRelative(offset > 0 ? -1 : 1,
312 true); 318 true);
313 } 319 }
314 event->SetHandled(); 320 event->SetHandled();
315 event->StopPropagation(); 321 event->StopPropagation();
316 } 322 }
317 } 323 }
318 324
319 } // namespace app_list 325 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698