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

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: Moved scrolling event handlers from AppsContainerView 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
« 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 18 matching lines...) Expand all
882 } 889 }
883 890
884 bool AppsGridView::CanDrop(const OSExchangeData& data) { 891 bool AppsGridView::CanDrop(const OSExchangeData& data) {
885 return true; 892 return true;
886 } 893 }
887 894
888 int AppsGridView::OnDragUpdated(const ui::DropTargetEvent& event) { 895 int AppsGridView::OnDragUpdated(const ui::DropTargetEvent& event) {
889 return ui::DragDropTypes::DRAG_MOVE; 896 return ui::DragDropTypes::DRAG_MOVE;
890 } 897 }
891 898
899 void AppsGridView::OnGestureEvent(ui::GestureEvent* event) {
calamity 2014/08/29 04:15:09 nit: May as well move this behind all the View ove
Matt Giuca 2014/08/29 06:28:19 Done.
900 switch (event->type()) {
calamity 2014/08/29 04:15:10 I have a feeling this could change the folder beha
Matt Giuca 2014/08/29 06:28:19 Seems to be OK, but haven't tested on ChromeOS (wi
Matt Giuca 2014/08/29 07:47:28 Ugh, I can't test on ChromeOS because login manage
901 case ui::ET_GESTURE_SCROLL_BEGIN:
902 pagination_model_.StartScroll();
903 event->SetHandled();
904 return;
905 case ui::ET_GESTURE_SCROLL_UPDATE:
906 // event->details.scroll_x() > 0 means moving contents to right. That is,
907 // transitioning to previous page.
908 pagination_model_.UpdateScroll(event->details().scroll_x() /
909 GetContentsBounds().width());
910 event->SetHandled();
911 return;
912 case ui::ET_GESTURE_SCROLL_END:
913 pagination_model_.EndScroll(pagination_model_.transition().progress <
914 kFinishTransitionThreshold);
915 event->SetHandled();
916 return;
917 case ui::ET_SCROLL_FLING_START: {
918 pagination_model_.EndScroll(true);
919 if (fabs(event->details().velocity_x()) > kMinHorizVelocityToSwitchPage) {
920 pagination_model_.SelectPageRelative(
921 event->details().velocity_x() < 0 ? 1 : -1, true);
922 }
923 event->SetHandled();
924 return;
925 }
926 default:
927 break;
928 }
929 }
930
931 void AppsGridView::OnScrollEvent(ui::ScrollEvent* event) {
932 if (event->type() == ui::ET_SCROLL_FLING_CANCEL)
933 return;
934
935 float offset;
936 if (std::abs(event->x_offset()) > std::abs(event->y_offset()))
937 offset = event->x_offset();
938 else
939 offset = event->y_offset();
940
941 if (std::abs(offset) > kMinScrollToSwitchPage) {
942 if (!pagination_model_.has_transition()) {
943 pagination_model_.SelectPageRelative(offset > 0 ? -1 : 1, true);
944 }
945 event->SetHandled();
946 event->StopPropagation();
947 }
948 }
949
892 void AppsGridView::Layout() { 950 void AppsGridView::Layout() {
893 if (bounds_animator_.IsAnimating()) 951 if (bounds_animator_.IsAnimating())
894 bounds_animator_.Cancel(); 952 bounds_animator_.Cancel();
895 953
896 CalculateIdealBounds(); 954 CalculateIdealBounds();
897 for (int i = 0; i < view_model_.view_size(); ++i) { 955 for (int i = 0; i < view_model_.view_size(); ++i) {
898 views::View* view = view_model_.view_at(i); 956 views::View* view = view_model_.view_at(i);
899 if (view != drag_view_) 957 if (view != drag_view_)
900 view->SetBoundsRect(view_model_.ideal_bounds(i)); 958 view->SetBoundsRect(view_model_.ideal_bounds(i));
901 } 959 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 } 1004 }
947 1005
948 bool AppsGridView::OnKeyReleased(const ui::KeyEvent& event) { 1006 bool AppsGridView::OnKeyReleased(const ui::KeyEvent& event) {
949 bool handled = false; 1007 bool handled = false;
950 if (selected_view_) 1008 if (selected_view_)
951 handled = selected_view_->OnKeyReleased(event); 1009 handled = selected_view_->OnKeyReleased(event);
952 1010
953 return handled; 1011 return handled;
954 } 1012 }
955 1013
1014 bool AppsGridView::OnMouseWheel(const ui::MouseWheelEvent& event) {
1015 int offset;
1016 if (abs(event.x_offset()) > abs(event.y_offset()))
1017 offset = event.x_offset();
1018 else
1019 offset = event.y_offset();
1020
1021 if (abs(offset) > kMinMouseWheelToSwitchPage) {
1022 if (!pagination_model_.has_transition()) {
1023 pagination_model_.SelectPageRelative(offset > 0 ? -1 : 1, true);
1024 }
1025 return true;
1026 }
1027
1028 return false;
1029 }
1030
956 void AppsGridView::ViewHierarchyChanged( 1031 void AppsGridView::ViewHierarchyChanged(
957 const ViewHierarchyChangedDetails& details) { 1032 const ViewHierarchyChangedDetails& details) {
958 if (!details.is_add && details.parent == this) { 1033 if (!details.is_add && details.parent == this) {
959 // The view being delete should not have reference in |view_model_|. 1034 // The view being delete should not have reference in |view_model_|.
960 CHECK_EQ(-1, view_model_.GetIndexOfView(details.child)); 1035 CHECK_EQ(-1, view_model_.GetIndexOfView(details.child));
961 1036
962 if (selected_view_ == details.child) 1037 if (selected_view_ == details.child)
963 selected_view_ = NULL; 1038 selected_view_ = NULL;
964 if (activated_folder_item_view_ == details.child) 1039 if (activated_folder_item_view_ == details.child)
965 activated_folder_item_view_ = NULL; 1040 activated_folder_item_view_ = NULL;
(...skipping 1205 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