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

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

Issue 497413003: Refactor app list event handling and prerendering. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved some app-grid-specific logic from ContentsView to AppsGridView. Created 6 years, 3 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
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/pagination_model.h"
calamity 2014/08/26 08:12:34 This is already included in the header.
Matt Giuca 2014/08/28 00:35:21 Done.
14 #include "ui/app_list/views/app_list_folder_view.h" 15 #include "ui/app_list/views/app_list_folder_view.h"
15 #include "ui/app_list/views/app_list_main_view.h" 16 #include "ui/app_list/views/app_list_main_view.h"
16 #include "ui/app_list/views/apps_container_view.h" 17 #include "ui/app_list/views/apps_container_view.h"
17 #include "ui/app_list/views/apps_grid_view.h" 18 #include "ui/app_list/views/apps_grid_view.h"
18 #include "ui/app_list/views/contents_switcher_view.h" 19 #include "ui/app_list/views/contents_switcher_view.h"
19 #include "ui/app_list/views/search_result_list_view.h" 20 #include "ui/app_list/views/search_result_list_view.h"
20 #include "ui/app_list/views/start_page_view.h" 21 #include "ui/app_list/views/start_page_view.h"
21 #include "ui/events/event.h" 22 #include "ui/events/event.h"
22 #include "ui/resources/grit/ui_resources.h" 23 #include "ui/resources/grit/ui_resources.h"
23 #include "ui/views/view_model.h" 24 #include "ui/views/view_model.h"
24 #include "ui/views/view_model_utils.h" 25 #include "ui/views/view_model_utils.h"
25 26
26 namespace app_list { 27 namespace app_list {
27 28
28 namespace {
29
30 const int kMinMouseWheelToSwitchPage = 20;
31 const int kMinScrollToSwitchPage = 20;
32 const int kMinHorizVelocityToSwitchPage = 800;
33
34 const double kFinishTransitionThreshold = 0.33;
35
36 } // namespace
37
38 ContentsView::ContentsView(AppListMainView* app_list_main_view) 29 ContentsView::ContentsView(AppListMainView* app_list_main_view)
39 : search_results_view_(NULL), 30 : search_results_view_(NULL),
40 start_page_view_(NULL), 31 start_page_view_(NULL),
41 app_list_main_view_(app_list_main_view), 32 app_list_main_view_(app_list_main_view),
42 contents_switcher_view_(NULL), 33 contents_switcher_view_(NULL),
43 view_model_(new views::ViewModel), 34 view_model_(new views::ViewModel),
44 page_before_search_(0) { 35 page_before_search_(0) {
45 pagination_model_.AddObserver(this); 36 pagination_model_.AddObserver(this);
46 } 37 }
47 38
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 230
240 PaginationModel* ContentsView::GetAppsPaginationModel() { 231 PaginationModel* ContentsView::GetAppsPaginationModel() {
241 return apps_container_view_->apps_grid_view()->pagination_model(); 232 return apps_container_view_->apps_grid_view()->pagination_model();
242 } 233 }
243 234
244 void ContentsView::ShowFolderContent(AppListFolderItem* item) { 235 void ContentsView::ShowFolderContent(AppListFolderItem* item) {
245 apps_container_view_->ShowActiveFolder(item); 236 apps_container_view_->ShowActiveFolder(item);
246 } 237 }
247 238
248 void ContentsView::Prerender() { 239 void ContentsView::Prerender() {
249 const int selected_page = 240 apps_container_view_->apps_grid_view()->Prerender();
250 std::max(0, GetAppsPaginationModel()->selected_page());
251 apps_container_view_->apps_grid_view()->Prerender(selected_page);
252 } 241 }
253 242
254 views::View* ContentsView::GetPageView(int index) { 243 views::View* ContentsView::GetPageView(int index) {
255 return view_model_->view_at(index); 244 return view_model_->view_at(index);
256 } 245 }
257 246
258 void ContentsView::AddBlankPageForTesting() { 247 void ContentsView::AddBlankPageForTesting() {
259 AddLauncherPage(new views::View, 0); 248 AddLauncherPage(new views::View, 0);
260 } 249 }
261 250
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 for (int i = 0; i < view_model_->view_size(); ++i) { 295 for (int i = 0; i < view_model_->view_size(); ++i) {
307 view_model_->view_at(i)->SetBoundsRect( 296 view_model_->view_at(i)->SetBoundsRect(
308 i == pagination_model_.SelectedTargetPage() ? rect : offscreen_target); 297 i == pagination_model_.SelectedTargetPage() ? rect : offscreen_target);
309 } 298 }
310 } 299 }
311 300
312 bool ContentsView::OnKeyPressed(const ui::KeyEvent& event) { 301 bool ContentsView::OnKeyPressed(const ui::KeyEvent& event) {
313 return view_model_->view_at(GetActivePageIndex())->OnKeyPressed(event); 302 return view_model_->view_at(GetActivePageIndex())->OnKeyPressed(event);
314 } 303 }
315 304
316 bool ContentsView::OnMouseWheel(const ui::MouseWheelEvent& event) {
317 if (!IsNamedPageActive(NAMED_PAGE_APPS))
318 return false;
319
320 int offset;
321 if (abs(event.x_offset()) > abs(event.y_offset()))
322 offset = event.x_offset();
323 else
324 offset = event.y_offset();
325
326 if (abs(offset) > kMinMouseWheelToSwitchPage) {
327 if (!GetAppsPaginationModel()->has_transition()) {
328 GetAppsPaginationModel()->SelectPageRelative(offset > 0 ? -1 : 1, true);
329 }
330 return true;
331 }
332
333 return false;
334 }
335
336 void ContentsView::TotalPagesChanged() { 305 void ContentsView::TotalPagesChanged() {
337 } 306 }
338 307
339 void ContentsView::SelectedPageChanged(int old_selected, int new_selected) { 308 void ContentsView::SelectedPageChanged(int old_selected, int new_selected) {
340 } 309 }
341 310
342 void ContentsView::TransitionStarted() { 311 void ContentsView::TransitionStarted() {
343 } 312 }
344 313
345 void ContentsView::TransitionChanged() { 314 void ContentsView::TransitionChanged() {
346 UpdatePageBounds(); 315 UpdatePageBounds();
347 } 316 }
348 317
349 void ContentsView::OnGestureEvent(ui::GestureEvent* event) {
350 if (!IsNamedPageActive(NAMED_PAGE_APPS))
351 return;
352
353 switch (event->type()) {
354 case ui::ET_GESTURE_SCROLL_BEGIN:
355 GetAppsPaginationModel()->StartScroll();
356 event->SetHandled();
357 return;
358 case ui::ET_GESTURE_SCROLL_UPDATE:
359 // event->details.scroll_x() > 0 means moving contents to right. That is,
360 // transitioning to previous page.
361 GetAppsPaginationModel()->UpdateScroll(event->details().scroll_x() /
362 GetContentsBounds().width());
363 event->SetHandled();
364 return;
365 case ui::ET_GESTURE_SCROLL_END:
366 GetAppsPaginationModel()->EndScroll(
367 GetAppsPaginationModel()->transition().progress <
368 kFinishTransitionThreshold);
369 event->SetHandled();
370 return;
371 case ui::ET_SCROLL_FLING_START: {
372 GetAppsPaginationModel()->EndScroll(true);
373 if (fabs(event->details().velocity_x()) > kMinHorizVelocityToSwitchPage) {
374 GetAppsPaginationModel()->SelectPageRelative(
375 event->details().velocity_x() < 0 ? 1 : -1, true);
376 }
377 event->SetHandled();
378 return;
379 }
380 default:
381 break;
382 }
383 }
384
385 void ContentsView::OnScrollEvent(ui::ScrollEvent* event) {
386 if (!IsNamedPageActive(NAMED_PAGE_APPS) ||
387 event->type() == ui::ET_SCROLL_FLING_CANCEL) {
388 return;
389 }
390
391 float offset;
392 if (std::abs(event->x_offset()) > std::abs(event->y_offset()))
393 offset = event->x_offset();
394 else
395 offset = event->y_offset();
396
397 if (std::abs(offset) > kMinScrollToSwitchPage) {
398 if (!GetAppsPaginationModel()->has_transition()) {
399 GetAppsPaginationModel()->SelectPageRelative(offset > 0 ? -1 : 1, true);
400 }
401 event->SetHandled();
402 event->StopPropagation();
403 }
404 }
405
406 } // namespace app_list 318 } // namespace app_list
OLDNEW
« ui/app_list/views/apps_container_view.h ('K') | « ui/app_list/views/contents_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698