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

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

Issue 491973004: Make apps grid view scroll vertically in experimental app list. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@calamity-ares-vertical-scroll
Patch Set: Rename width to size. 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') | no next file » | 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 944 matching lines...) Expand 10 before | Expand all | Expand 10 after
955 bool AppsGridView::OnKeyReleased(const ui::KeyEvent& event) { 955 bool AppsGridView::OnKeyReleased(const ui::KeyEvent& event) {
956 bool handled = false; 956 bool handled = false;
957 if (selected_view_) 957 if (selected_view_)
958 handled = selected_view_->OnKeyReleased(event); 958 handled = selected_view_->OnKeyReleased(event);
959 959
960 return handled; 960 return handled;
961 } 961 }
962 962
963 bool AppsGridView::OnMouseWheel(const ui::MouseWheelEvent& event) { 963 bool AppsGridView::OnMouseWheel(const ui::MouseWheelEvent& event) {
964 int offset; 964 int offset;
965 if (abs(event.x_offset()) > abs(event.y_offset())) 965 if (GetScrollAxis() == SCROLL_AXIS_HORIZONTAL) {
966 offset = event.x_offset(); 966 // If the view scrolls horizontally, both horizontal and vertical scroll
967 else 967 // events are valid (since most mouse wheels only have vertical scrolling).
968 if (abs(event.x_offset()) > abs(event.y_offset()))
969 offset = event.x_offset();
970 else
971 offset = event.y_offset();
972 } else {
973 // If the view scrolls vertically, only vertical scroll events are valid.
968 offset = event.y_offset(); 974 offset = event.y_offset();
975 }
969 976
970 if (abs(offset) > kMinMouseWheelToSwitchPage) { 977 if (abs(offset) > kMinMouseWheelToSwitchPage) {
971 if (!pagination_model_.has_transition()) { 978 if (!pagination_model_.has_transition()) {
972 pagination_model_.SelectPageRelative(offset > 0 ? -1 : 1, true); 979 pagination_model_.SelectPageRelative(offset > 0 ? -1 : 1, true);
973 } 980 }
974 return true; 981 return true;
975 } 982 }
976 983
977 return false; 984 return false;
978 } 985 }
(...skipping 10 matching lines...) Expand all
989 activated_folder_item_view_ = NULL; 996 activated_folder_item_view_ = NULL;
990 997
991 if (drag_view_ == details.child) 998 if (drag_view_ == details.child)
992 EndDrag(true); 999 EndDrag(true);
993 1000
994 bounds_animator_.StopAnimatingView(details.child); 1001 bounds_animator_.StopAnimatingView(details.child);
995 } 1002 }
996 } 1003 }
997 1004
998 void AppsGridView::OnGestureEvent(ui::GestureEvent* event) { 1005 void AppsGridView::OnGestureEvent(ui::GestureEvent* event) {
1006 const ui::GestureEventDetails& details = event->details();
999 switch (event->type()) { 1007 switch (event->type()) {
1000 case ui::ET_GESTURE_SCROLL_BEGIN: 1008 case ui::ET_GESTURE_SCROLL_BEGIN:
1001 pagination_model_.StartScroll(); 1009 pagination_model_.StartScroll();
1002 event->SetHandled(); 1010 event->SetHandled();
1003 return; 1011 return;
1004 case ui::ET_GESTURE_SCROLL_UPDATE: 1012 case ui::ET_GESTURE_SCROLL_UPDATE: {
1005 // event->details.scroll_x() > 0 means moving contents to right. That is, 1013 float scroll = GetScrollAxis() == SCROLL_AXIS_HORIZONTAL
1006 // transitioning to previous page. 1014 ? details.scroll_x()
1007 pagination_model_.UpdateScroll(event->details().scroll_x() / 1015 : details.scroll_y();
1008 GetContentsBounds().width()); 1016 gfx::Rect bounds(GetContentsBounds());
1017 int size = GetScrollAxis() == SCROLL_AXIS_HORIZONTAL ? bounds.width()
1018 : bounds.height();
1019 // scroll > 0 means moving contents right or down. That is, transitioning
1020 // to the previous page.
1021 pagination_model_.UpdateScroll(scroll / size);
1009 event->SetHandled(); 1022 event->SetHandled();
1010 return; 1023 return;
1024 }
1011 case ui::ET_GESTURE_SCROLL_END: 1025 case ui::ET_GESTURE_SCROLL_END:
1012 pagination_model_.EndScroll(pagination_model_.transition().progress < 1026 pagination_model_.EndScroll(pagination_model_.transition().progress <
1013 kFinishTransitionThreshold); 1027 kFinishTransitionThreshold);
1014 event->SetHandled(); 1028 event->SetHandled();
1015 return; 1029 return;
1016 case ui::ET_SCROLL_FLING_START: { 1030 case ui::ET_SCROLL_FLING_START: {
1031 float velocity = GetScrollAxis() == SCROLL_AXIS_HORIZONTAL
1032 ? details.velocity_x()
1033 : details.velocity_y();
1017 pagination_model_.EndScroll(true); 1034 pagination_model_.EndScroll(true);
1018 if (fabs(event->details().velocity_x()) > kMinHorizVelocityToSwitchPage) { 1035 if (fabs(velocity) > kMinHorizVelocityToSwitchPage)
1019 pagination_model_.SelectPageRelative( 1036 pagination_model_.SelectPageRelative(velocity < 0 ? 1 : -1, true);
1020 event->details().velocity_x() < 0 ? 1 : -1, true);
1021 }
1022 event->SetHandled(); 1037 event->SetHandled();
1023 return; 1038 return;
1024 } 1039 }
1025 default: 1040 default:
1026 break; 1041 break;
1027 } 1042 }
1028 } 1043 }
1029 1044
1030 void AppsGridView::OnScrollEvent(ui::ScrollEvent* event) { 1045 void AppsGridView::OnScrollEvent(ui::ScrollEvent* event) {
1031 if (event->type() == ui::ET_SCROLL_FLING_CANCEL) 1046 if (event->type() == ui::ET_SCROLL_FLING_CANCEL)
1032 return; 1047 return;
1033 1048
1034 float offset; 1049 float offset;
1035 if (std::abs(event->x_offset()) > std::abs(event->y_offset())) 1050 if (GetScrollAxis() == SCROLL_AXIS_HORIZONTAL) {
1036 offset = event->x_offset(); 1051 // If the view scrolls horizontally, both horizontal and vertical scroll
1037 else 1052 // events are valid (vertical scroll events simulate mouse wheel).
1053 if (std::abs(event->x_offset()) > std::abs(event->y_offset()))
1054 offset = event->x_offset();
1055 else
1056 offset = event->y_offset();
1057 } else {
1058 // If the view scrolls vertically, only vertical scroll events are valid.
1038 offset = event->y_offset(); 1059 offset = event->y_offset();
1060 }
1039 1061
1040 if (std::abs(offset) > kMinScrollToSwitchPage) { 1062 if (std::abs(offset) > kMinScrollToSwitchPage) {
1041 if (!pagination_model_.has_transition()) { 1063 if (!pagination_model_.has_transition()) {
1042 pagination_model_.SelectPageRelative(offset > 0 ? -1 : 1, true); 1064 pagination_model_.SelectPageRelative(offset > 0 ? -1 : 1, true);
1043 } 1065 }
1044 event->SetHandled(); 1066 event->SetHandled();
1045 event->StopPropagation(); 1067 event->StopPropagation();
1046 } 1068 }
1047 } 1069 }
1048 1070
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 gfx::Rect rect(GetContentsBounds()); 1223 gfx::Rect rect(GetContentsBounds());
1202 if (rect.IsEmpty()) 1224 if (rect.IsEmpty())
1203 return; 1225 return;
1204 1226
1205 gfx::Size tile_size(kPreferredTileWidth, kPreferredTileHeight); 1227 gfx::Size tile_size(kPreferredTileWidth, kPreferredTileHeight);
1206 1228
1207 gfx::Rect grid_rect(gfx::Size(tile_size.width() * cols_, 1229 gfx::Rect grid_rect(gfx::Size(tile_size.width() * cols_,
1208 tile_size.height() * rows_per_page_)); 1230 tile_size.height() * rows_per_page_));
1209 grid_rect.Intersect(rect); 1231 grid_rect.Intersect(rect);
1210 1232
1211 // Page width including padding pixels. A tile.x + page_width means the same 1233 // Page size including padding pixels. A tile.x + page_width means the same
1212 // tile slot in the next page. 1234 // tile slot in the next page; similarly for tile.y + page_height.
1213 const int page_width = grid_rect.width() + kPagePadding; 1235 const int page_width = grid_rect.width() + kPagePadding;
1236 const int page_height = grid_rect.height() + kPagePadding;
1214 1237
1215 // If there is a transition, calculates offset for current and target page. 1238 // If there is a transition, calculates offset for current and target page.
1216 const int current_page = pagination_model_.selected_page(); 1239 const int current_page = pagination_model_.selected_page();
1217 const PaginationModel::Transition& transition = 1240 const PaginationModel::Transition& transition =
1218 pagination_model_.transition(); 1241 pagination_model_.transition();
1219 const bool is_valid = pagination_model_.is_valid_page(transition.target_page); 1242 const bool is_valid = pagination_model_.is_valid_page(transition.target_page);
1220 1243
1221 // Transition to right means negative offset. 1244 // Transition to previous page means negative offset.
1222 const int dir = transition.target_page > current_page ? -1 : 1; 1245 const int dir = transition.target_page > current_page ? -1 : 1;
1223 const int transition_offset = is_valid ?
1224 transition.progress * page_width * dir : 0;
1225 1246
1226 const int total_views = 1247 const int total_views =
1227 view_model_.view_size() + pulsing_blocks_model_.view_size(); 1248 view_model_.view_size() + pulsing_blocks_model_.view_size();
1228 int slot_index = 0; 1249 int slot_index = 0;
1229 for (int i = 0; i < total_views; ++i) { 1250 for (int i = 0; i < total_views; ++i) {
1230 if (i < view_model_.view_size() && view_model_.view_at(i) == drag_view_) { 1251 if (i < view_model_.view_size() && view_model_.view_at(i) == drag_view_) {
1231 if (EnableFolderDragDropUI() && drop_attempt_ == DROP_FOR_FOLDER) 1252 if (EnableFolderDragDropUI() && drop_attempt_ == DROP_FOR_FOLDER)
1232 ++slot_index; 1253 ++slot_index;
1233 continue; 1254 continue;
1234 } 1255 }
1235 1256
1236 Index view_index = GetIndexFromModelIndex(slot_index); 1257 Index view_index = GetIndexFromModelIndex(slot_index);
1237 1258
1238 if (drop_target_ == view_index) { 1259 if (drop_target_ == view_index) {
1239 if (EnableFolderDragDropUI() && drop_attempt_ == DROP_FOR_FOLDER) { 1260 if (EnableFolderDragDropUI() && drop_attempt_ == DROP_FOR_FOLDER) {
1240 view_index = GetIndexFromModelIndex(slot_index); 1261 view_index = GetIndexFromModelIndex(slot_index);
1241 } else if (!EnableFolderDragDropUI() || 1262 } else if (!EnableFolderDragDropUI() ||
1242 drop_attempt_ == DROP_FOR_REORDER) { 1263 drop_attempt_ == DROP_FOR_REORDER) {
1243 ++slot_index; 1264 ++slot_index;
1244 view_index = GetIndexFromModelIndex(slot_index); 1265 view_index = GetIndexFromModelIndex(slot_index);
1245 } 1266 }
1246 } 1267 }
1247 1268
1248 // Decides an x_offset for current item. 1269 // Decide the x or y offset for current item.
1249 int x_offset = 0; 1270 int x_offset = 0;
1250 if (view_index.page < current_page) 1271 int y_offset = 0;
1251 x_offset = -page_width;
1252 else if (view_index.page > current_page)
1253 x_offset = page_width;
1254 1272
1255 if (is_valid) { 1273 if (GetScrollAxis() == SCROLL_AXIS_HORIZONTAL) {
1256 if (view_index.page == current_page || 1274 if (view_index.page < current_page)
1257 view_index.page == transition.target_page) { 1275 x_offset = -page_width;
1258 x_offset += transition_offset; 1276 else if (view_index.page > current_page)
1277 x_offset = page_width;
1278
1279 if (is_valid) {
1280 if (view_index.page == current_page ||
1281 view_index.page == transition.target_page) {
1282 x_offset += transition.progress * page_width * dir;
1283 }
1284 }
1285 } else {
1286 if (view_index.page < current_page)
1287 y_offset = -page_height;
1288 else if (view_index.page > current_page)
1289 y_offset = page_height;
1290
1291 if (is_valid) {
1292 if (view_index.page == current_page ||
1293 view_index.page == transition.target_page) {
1294 y_offset += transition.progress * page_height * dir;
1295 }
1259 } 1296 }
1260 } 1297 }
1261 1298
1262 const int row = view_index.slot / cols_; 1299 const int row = view_index.slot / cols_;
1263 const int col = view_index.slot % cols_; 1300 const int col = view_index.slot % cols_;
1264 gfx::Rect tile_slot( 1301 gfx::Rect tile_slot(
1265 gfx::Point(grid_rect.x() + col * tile_size.width() + x_offset, 1302 gfx::Point(grid_rect.x() + col * tile_size.width() + x_offset,
1266 grid_rect.y() + row * tile_size.height()), 1303 grid_rect.y() + row * tile_size.height() + y_offset),
1267 tile_size); 1304 tile_size);
1268 if (i < view_model_.view_size()) { 1305 if (i < view_model_.view_size()) {
1269 view_model_.set_ideal_bounds(i, tile_slot); 1306 view_model_.set_ideal_bounds(i, tile_slot);
1270 } else { 1307 } else {
1271 pulsing_blocks_model_.set_ideal_bounds(i - view_model_.view_size(), 1308 pulsing_blocks_model_.set_ideal_bounds(i - view_model_.view_size(),
1272 tile_slot); 1309 tile_slot);
1273 } 1310 }
1274 1311
1275 ++slot_index; 1312 ++slot_index;
1276 } 1313 }
(...skipping 968 matching lines...) Expand 10 before | Expand all | Expand 10 after
2245 2282
2246 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, 2283 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index,
2247 bool is_target_folder) { 2284 bool is_target_folder) {
2248 AppListItemView* target_view = 2285 AppListItemView* target_view =
2249 static_cast<AppListItemView*>( 2286 static_cast<AppListItemView*>(
2250 GetViewAtSlotOnCurrentPage(target_index.slot)); 2287 GetViewAtSlotOnCurrentPage(target_index.slot));
2251 if (target_view) 2288 if (target_view)
2252 target_view->SetAsAttemptedFolderTarget(is_target_folder); 2289 target_view->SetAsAttemptedFolderTarget(is_target_folder);
2253 } 2290 }
2254 2291
2292 // static
2293 AppsGridView::ScrollAxis AppsGridView::GetScrollAxis() {
2294 // The experimental app list transitions vertically.
2295 return app_list::switches::IsExperimentalAppListEnabled()
2296 ? SCROLL_AXIS_VERTICAL
2297 : SCROLL_AXIS_HORIZONTAL;
2298 }
2299
2255 } // namespace app_list 2300 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/views/apps_grid_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698