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

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

Issue 497413003: Refactor app list event handling and prerendering. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reorder in .cc file. 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
« no previous file with comments | « ui/app_list/views/apps_grid_view.h ('k') | ui/app_list/views/contents_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/apps_grid_view.h" 5 #include "ui/app_list/views/apps_grid_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 10
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 // Delays in milliseconds to show re-order preview. 85 // Delays in milliseconds to show re-order preview.
86 const int kReorderDelay = 120; 86 const int kReorderDelay = 120;
87 87
88 // Delays in milliseconds to show folder item reparent UI. 88 // Delays in milliseconds to show folder item reparent UI.
89 const int kFolderItemReparentDelay = 50; 89 const int kFolderItemReparentDelay = 50;
90 90
91 // Radius of the circle, in which if entered, show folder dropping preview 91 // Radius of the circle, in which if entered, show folder dropping preview
92 // UI. 92 // UI.
93 const int kFolderDroppingCircleRadius = 15; 93 const int kFolderDroppingCircleRadius = 15;
94 94
95 // Constants for dealing with scroll events.
96 const int kMinMouseWheelToSwitchPage = 20;
97 const int kMinScrollToSwitchPage = 20;
98 const int kMinHorizVelocityToSwitchPage = 800;
99
100 const double kFinishTransitionThreshold = 0.33;
95 101
96 // RowMoveAnimationDelegate is used when moving an item into a different row. 102 // RowMoveAnimationDelegate is used when moving an item into a different row.
97 // Before running the animation, the item's layer is re-created and kept in 103 // Before running the animation, the item's layer is re-created and kept in
98 // the original position, then the item is moved to just before its target 104 // the original position, then the item is moved to just before its target
99 // position and opacity set to 0. When the animation runs, this delegate moves 105 // position and opacity set to 0. When the animation runs, this delegate moves
100 // the layer and fades it out while fading in the item at the same time. 106 // the layer and fades it out while fading in the item at the same time.
101 class RowMoveAnimationDelegate : public gfx::AnimationDelegate { 107 class RowMoveAnimationDelegate : public gfx::AnimationDelegate {
102 public: 108 public:
103 RowMoveAnimationDelegate(views::View* view, 109 RowMoveAnimationDelegate(views::View* view,
104 ui::Layer* layer, 110 ui::Layer* layer,
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 void AppsGridView::SetDragViewVisible(bool visible) { 845 void AppsGridView::SetDragViewVisible(bool visible) {
840 DCHECK(drag_view_); 846 DCHECK(drag_view_);
841 SetViewHidden(drag_view_, !visible, true); 847 SetViewHidden(drag_view_, !visible, true);
842 } 848 }
843 849
844 void AppsGridView::SetDragAndDropHostOfCurrentAppList( 850 void AppsGridView::SetDragAndDropHostOfCurrentAppList(
845 ApplicationDragAndDropHost* drag_and_drop_host) { 851 ApplicationDragAndDropHost* drag_and_drop_host) {
846 drag_and_drop_host_ = drag_and_drop_host; 852 drag_and_drop_host_ = drag_and_drop_host;
847 } 853 }
848 854
849 void AppsGridView::Prerender(int page_index) { 855 void AppsGridView::Prerender() {
850 Layout(); 856 Layout();
851 int start = std::max(0, (page_index - kPrerenderPages) * tiles_per_page()); 857 int selected_page = std::max(0, pagination_model_.selected_page());
858 int start = std::max(0, (selected_page - kPrerenderPages) * tiles_per_page());
852 int end = std::min(view_model_.view_size(), 859 int end = std::min(view_model_.view_size(),
853 (page_index + 1 + kPrerenderPages) * tiles_per_page()); 860 (selected_page + 1 + kPrerenderPages) * tiles_per_page());
854 for (int i = start; i < end; i++) { 861 for (int i = start; i < end; i++) {
855 AppListItemView* v = static_cast<AppListItemView*>(view_model_.view_at(i)); 862 AppListItemView* v = static_cast<AppListItemView*>(view_model_.view_at(i));
856 v->Prerender(); 863 v->Prerender();
857 } 864 }
858 } 865 }
859 866
860 bool AppsGridView::IsAnimatingView(views::View* view) { 867 bool AppsGridView::IsAnimatingView(views::View* view) {
861 return bounds_animator_.IsAnimating(view); 868 return bounds_animator_.IsAnimating(view);
862 } 869 }
863 870
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 } 953 }
947 954
948 bool AppsGridView::OnKeyReleased(const ui::KeyEvent& event) { 955 bool AppsGridView::OnKeyReleased(const ui::KeyEvent& event) {
949 bool handled = false; 956 bool handled = false;
950 if (selected_view_) 957 if (selected_view_)
951 handled = selected_view_->OnKeyReleased(event); 958 handled = selected_view_->OnKeyReleased(event);
952 959
953 return handled; 960 return handled;
954 } 961 }
955 962
963 bool AppsGridView::OnMouseWheel(const ui::MouseWheelEvent& event) {
964 int offset;
965 if (abs(event.x_offset()) > abs(event.y_offset()))
966 offset = event.x_offset();
967 else
968 offset = event.y_offset();
969
970 if (abs(offset) > kMinMouseWheelToSwitchPage) {
971 if (!pagination_model_.has_transition()) {
972 pagination_model_.SelectPageRelative(offset > 0 ? -1 : 1, true);
973 }
974 return true;
975 }
976
977 return false;
978 }
979
956 void AppsGridView::ViewHierarchyChanged( 980 void AppsGridView::ViewHierarchyChanged(
957 const ViewHierarchyChangedDetails& details) { 981 const ViewHierarchyChangedDetails& details) {
958 if (!details.is_add && details.parent == this) { 982 if (!details.is_add && details.parent == this) {
959 // The view being delete should not have reference in |view_model_|. 983 // The view being delete should not have reference in |view_model_|.
960 CHECK_EQ(-1, view_model_.GetIndexOfView(details.child)); 984 CHECK_EQ(-1, view_model_.GetIndexOfView(details.child));
961 985
962 if (selected_view_ == details.child) 986 if (selected_view_ == details.child)
963 selected_view_ = NULL; 987 selected_view_ = NULL;
964 if (activated_folder_item_view_ == details.child) 988 if (activated_folder_item_view_ == details.child)
965 activated_folder_item_view_ = NULL; 989 activated_folder_item_view_ = NULL;
966 990
967 if (drag_view_ == details.child) 991 if (drag_view_ == details.child)
968 EndDrag(true); 992 EndDrag(true);
969 993
970 bounds_animator_.StopAnimatingView(details.child); 994 bounds_animator_.StopAnimatingView(details.child);
971 } 995 }
972 } 996 }
973 997
998 void AppsGridView::OnGestureEvent(ui::GestureEvent* event) {
999 switch (event->type()) {
1000 case ui::ET_GESTURE_SCROLL_BEGIN:
1001 pagination_model_.StartScroll();
1002 event->SetHandled();
1003 return;
1004 case ui::ET_GESTURE_SCROLL_UPDATE:
1005 // event->details.scroll_x() > 0 means moving contents to right. That is,
1006 // transitioning to previous page.
1007 pagination_model_.UpdateScroll(event->details().scroll_x() /
1008 GetContentsBounds().width());
1009 event->SetHandled();
1010 return;
1011 case ui::ET_GESTURE_SCROLL_END:
1012 pagination_model_.EndScroll(pagination_model_.transition().progress <
1013 kFinishTransitionThreshold);
1014 event->SetHandled();
1015 return;
1016 case ui::ET_SCROLL_FLING_START: {
1017 pagination_model_.EndScroll(true);
1018 if (fabs(event->details().velocity_x()) > kMinHorizVelocityToSwitchPage) {
1019 pagination_model_.SelectPageRelative(
1020 event->details().velocity_x() < 0 ? 1 : -1, true);
1021 }
1022 event->SetHandled();
1023 return;
1024 }
1025 default:
1026 break;
1027 }
1028 }
1029
1030 void AppsGridView::OnScrollEvent(ui::ScrollEvent* event) {
1031 if (event->type() == ui::ET_SCROLL_FLING_CANCEL)
1032 return;
1033
1034 float offset;
1035 if (std::abs(event->x_offset()) > std::abs(event->y_offset()))
1036 offset = event->x_offset();
1037 else
1038 offset = event->y_offset();
1039
1040 if (std::abs(offset) > kMinScrollToSwitchPage) {
1041 if (!pagination_model_.has_transition()) {
1042 pagination_model_.SelectPageRelative(offset > 0 ? -1 : 1, true);
1043 }
1044 event->SetHandled();
1045 event->StopPropagation();
1046 }
1047 }
1048
974 void AppsGridView::Update() { 1049 void AppsGridView::Update() {
975 DCHECK(!selected_view_ && !drag_view_); 1050 DCHECK(!selected_view_ && !drag_view_);
976 view_model_.Clear(); 1051 view_model_.Clear();
977 if (!item_list_ || !item_list_->item_count()) 1052 if (!item_list_ || !item_list_->item_count())
978 return; 1053 return;
979 for (size_t i = 0; i < item_list_->item_count(); ++i) { 1054 for (size_t i = 0; i < item_list_->item_count(); ++i) {
980 views::View* view = CreateViewForItemAtIndex(i); 1055 views::View* view = CreateViewForItemAtIndex(i);
981 view_model_.Add(view, i); 1056 view_model_.Add(view, i);
982 AddChildView(view); 1057 AddChildView(view);
983 } 1058 }
(...skipping 1187 matching lines...) Expand 10 before | Expand all | Expand 10 after
2171 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, 2246 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index,
2172 bool is_target_folder) { 2247 bool is_target_folder) {
2173 AppListItemView* target_view = 2248 AppListItemView* target_view =
2174 static_cast<AppListItemView*>( 2249 static_cast<AppListItemView*>(
2175 GetViewAtSlotOnCurrentPage(target_index.slot)); 2250 GetViewAtSlotOnCurrentPage(target_index.slot));
2176 if (target_view) 2251 if (target_view)
2177 target_view->SetAsAttemptedFolderTarget(is_target_folder); 2252 target_view->SetAsAttemptedFolderTarget(is_target_folder);
2178 } 2253 }
2179 2254
2180 } // namespace app_list 2255 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/views/apps_grid_view.h ('k') | ui/app_list/views/contents_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698