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

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: Touchpad scroll events: don't allow horizontal scrolling if view scrolling is vertical. 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 879 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 890
891 bool AppsGridView::CanDrop(const OSExchangeData& data) { 891 bool AppsGridView::CanDrop(const OSExchangeData& data) {
892 return true; 892 return true;
893 } 893 }
894 894
895 int AppsGridView::OnDragUpdated(const ui::DropTargetEvent& event) { 895 int AppsGridView::OnDragUpdated(const ui::DropTargetEvent& event) {
896 return ui::DragDropTypes::DRAG_MOVE; 896 return ui::DragDropTypes::DRAG_MOVE;
897 } 897 }
898 898
899 void AppsGridView::OnGestureEvent(ui::GestureEvent* event) { 899 void AppsGridView::OnGestureEvent(ui::GestureEvent* event) {
900 const ui::GestureEventDetails& details = event->details();
900 switch (event->type()) { 901 switch (event->type()) {
901 case ui::ET_GESTURE_SCROLL_BEGIN: 902 case ui::ET_GESTURE_SCROLL_BEGIN:
902 pagination_model_.StartScroll(); 903 pagination_model_.StartScroll();
903 event->SetHandled(); 904 event->SetHandled();
904 return; 905 return;
905 case ui::ET_GESTURE_SCROLL_UPDATE: 906 case ui::ET_GESTURE_SCROLL_UPDATE: {
906 // event->details.scroll_x() > 0 means moving contents to right. That is, 907 float scroll = GetScrollAxis() == SCROLL_AXIS_VERTICAL
907 // transitioning to previous page. 908 ? details.scroll_y()
908 pagination_model_.UpdateScroll(event->details().scroll_x() / 909 : details.scroll_x();
909 GetContentsBounds().width()); 910 // scroll > 0 means moving contents right or down. That is, transitioning
911 // to the previous page.
912 pagination_model_.UpdateScroll(scroll / GetContentsBounds().width());
910 event->SetHandled(); 913 event->SetHandled();
911 return; 914 return;
915 }
912 case ui::ET_GESTURE_SCROLL_END: 916 case ui::ET_GESTURE_SCROLL_END:
913 pagination_model_.EndScroll(pagination_model_.transition().progress < 917 pagination_model_.EndScroll(pagination_model_.transition().progress <
914 kFinishTransitionThreshold); 918 kFinishTransitionThreshold);
915 event->SetHandled(); 919 event->SetHandled();
916 return; 920 return;
917 case ui::ET_SCROLL_FLING_START: { 921 case ui::ET_SCROLL_FLING_START: {
922 float velocity = GetScrollAxis() == SCROLL_AXIS_VERTICAL
923 ? details.velocity_y()
924 : details.velocity_x();
918 pagination_model_.EndScroll(true); 925 pagination_model_.EndScroll(true);
919 if (fabs(event->details().velocity_x()) > kMinHorizVelocityToSwitchPage) { 926 if (fabs(velocity) > kMinHorizVelocityToSwitchPage)
920 pagination_model_.SelectPageRelative( 927 pagination_model_.SelectPageRelative(velocity < 0 ? 1 : -1, true);
921 event->details().velocity_x() < 0 ? 1 : -1, true);
922 }
923 event->SetHandled(); 928 event->SetHandled();
924 return; 929 return;
925 } 930 }
926 default: 931 default:
927 break; 932 break;
928 } 933 }
929 } 934 }
930 935
931 void AppsGridView::OnScrollEvent(ui::ScrollEvent* event) { 936 void AppsGridView::OnScrollEvent(ui::ScrollEvent* event) {
932 if (event->type() == ui::ET_SCROLL_FLING_CANCEL) 937 if (event->type() == ui::ET_SCROLL_FLING_CANCEL)
933 return; 938 return;
934 939
935 float offset; 940 float offset;
936 if (std::abs(event->x_offset()) > std::abs(event->y_offset())) 941 if (GetScrollAxis() == SCROLL_AXIS_HORIZONTAL) {
Matt Giuca 2014/08/28 03:40:54 Obviously this can be simplified to y_offset is on
937 offset = event->x_offset(); 942 // If the view scrolls horizontally, both horizontal and vertical scroll
938 else 943 // events are valid (vertical scroll events simulate mouse wheel).
944 if (std::abs(event->x_offset()) > std::abs(event->y_offset()))
945 offset = event->x_offset();
946 else
947 offset = event->y_offset();
948 } else {
949 // If the view scrolls vertically, only vertical scroll events are valid.
939 offset = event->y_offset(); 950 offset = event->y_offset();
951 }
940 952
941 if (std::abs(offset) > kMinScrollToSwitchPage) { 953 if (std::abs(offset) > kMinScrollToSwitchPage) {
942 if (!pagination_model_.has_transition()) { 954 if (!pagination_model_.has_transition()) {
943 pagination_model_.SelectPageRelative(offset > 0 ? -1 : 1, true); 955 pagination_model_.SelectPageRelative(offset > 0 ? -1 : 1, true);
944 } 956 }
945 event->SetHandled(); 957 event->SetHandled();
946 event->StopPropagation(); 958 event->StopPropagation();
947 } 959 }
948 } 960 }
949 961
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 gfx::Rect rect(GetContentsBounds()); 1213 gfx::Rect rect(GetContentsBounds());
1202 if (rect.IsEmpty()) 1214 if (rect.IsEmpty())
1203 return; 1215 return;
1204 1216
1205 gfx::Size tile_size(kPreferredTileWidth, kPreferredTileHeight); 1217 gfx::Size tile_size(kPreferredTileWidth, kPreferredTileHeight);
1206 1218
1207 gfx::Rect grid_rect(gfx::Size(tile_size.width() * cols_, 1219 gfx::Rect grid_rect(gfx::Size(tile_size.width() * cols_,
1208 tile_size.height() * rows_per_page_)); 1220 tile_size.height() * rows_per_page_));
1209 grid_rect.Intersect(rect); 1221 grid_rect.Intersect(rect);
1210 1222
1211 // Page width including padding pixels. A tile.x + page_width means the same 1223 // Page size including padding pixels. A tile.x + page_width means the same
1212 // tile slot in the next page. 1224 // tile slot in the next page; similarly for tile.y + page_height.
1213 const int page_width = grid_rect.width() + kPagePadding; 1225 const int page_width = grid_rect.width() + kPagePadding;
1226 const int page_height = grid_rect.height() + kPagePadding;
1214 1227
1215 // If there is a transition, calculates offset for current and target page. 1228 // If there is a transition, calculates offset for current and target page.
1216 const int current_page = pagination_model_.selected_page(); 1229 const int current_page = pagination_model_.selected_page();
1217 const PaginationModel::Transition& transition = 1230 const PaginationModel::Transition& transition =
1218 pagination_model_.transition(); 1231 pagination_model_.transition();
1219 const bool is_valid = pagination_model_.is_valid_page(transition.target_page); 1232 const bool is_valid = pagination_model_.is_valid_page(transition.target_page);
1220 1233
1221 // Transition to right means negative offset. 1234 // Transition to previous page means negative offset.
1222 const int dir = transition.target_page > current_page ? -1 : 1; 1235 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 1236
1226 const int total_views = 1237 const int total_views =
1227 view_model_.view_size() + pulsing_blocks_model_.view_size(); 1238 view_model_.view_size() + pulsing_blocks_model_.view_size();
1228 int slot_index = 0; 1239 int slot_index = 0;
1229 for (int i = 0; i < total_views; ++i) { 1240 for (int i = 0; i < total_views; ++i) {
1230 if (i < view_model_.view_size() && view_model_.view_at(i) == drag_view_) { 1241 if (i < view_model_.view_size() && view_model_.view_at(i) == drag_view_) {
1231 if (EnableFolderDragDropUI() && drop_attempt_ == DROP_FOR_FOLDER) 1242 if (EnableFolderDragDropUI() && drop_attempt_ == DROP_FOR_FOLDER)
1232 ++slot_index; 1243 ++slot_index;
1233 continue; 1244 continue;
1234 } 1245 }
1235 1246
1236 Index view_index = GetIndexFromModelIndex(slot_index); 1247 Index view_index = GetIndexFromModelIndex(slot_index);
1237 1248
1238 if (drop_target_ == view_index) { 1249 if (drop_target_ == view_index) {
1239 if (EnableFolderDragDropUI() && drop_attempt_ == DROP_FOR_FOLDER) { 1250 if (EnableFolderDragDropUI() && drop_attempt_ == DROP_FOR_FOLDER) {
1240 view_index = GetIndexFromModelIndex(slot_index); 1251 view_index = GetIndexFromModelIndex(slot_index);
1241 } else if (!EnableFolderDragDropUI() || 1252 } else if (!EnableFolderDragDropUI() ||
1242 drop_attempt_ == DROP_FOR_REORDER) { 1253 drop_attempt_ == DROP_FOR_REORDER) {
1243 ++slot_index; 1254 ++slot_index;
1244 view_index = GetIndexFromModelIndex(slot_index); 1255 view_index = GetIndexFromModelIndex(slot_index);
1245 } 1256 }
1246 } 1257 }
1247 1258
1248 // Decides an x_offset for current item. 1259 // Decide the x or y offset for current item.
1249 int x_offset = 0; 1260 int x_offset = 0;
1250 if (view_index.page < current_page) 1261 int y_offset = 0;
1251 x_offset = -page_width;
1252 else if (view_index.page > current_page)
1253 x_offset = page_width;
1254 1262
1255 if (is_valid) { 1263 if (GetScrollAxis() == SCROLL_AXIS_VERTICAL) {
1256 if (view_index.page == current_page || 1264 if (view_index.page < current_page)
1257 view_index.page == transition.target_page) { 1265 y_offset = -page_height;
1258 x_offset += transition_offset; 1266 else if (view_index.page > current_page)
1267 y_offset = page_height;
1268
1269 if (is_valid) {
1270 if (view_index.page == current_page ||
1271 view_index.page == transition.target_page) {
1272 y_offset += transition.progress * page_height * dir;
1273 }
1274 }
1275 } else {
1276 if (view_index.page < current_page)
1277 x_offset = -page_width;
1278 else if (view_index.page > current_page)
1279 x_offset = page_width;
1280
1281 if (is_valid) {
1282 if (view_index.page == current_page ||
1283 view_index.page == transition.target_page) {
1284 x_offset += transition.progress * page_width * dir;
1285 }
1259 } 1286 }
1260 } 1287 }
1261 1288
1262 const int row = view_index.slot / cols_; 1289 const int row = view_index.slot / cols_;
1263 const int col = view_index.slot % cols_; 1290 const int col = view_index.slot % cols_;
1264 gfx::Rect tile_slot( 1291 gfx::Rect tile_slot(
1265 gfx::Point(grid_rect.x() + col * tile_size.width() + x_offset, 1292 gfx::Point(grid_rect.x() + col * tile_size.width() + x_offset,
1266 grid_rect.y() + row * tile_size.height()), 1293 grid_rect.y() + row * tile_size.height() + y_offset),
1267 tile_size); 1294 tile_size);
1268 if (i < view_model_.view_size()) { 1295 if (i < view_model_.view_size()) {
1269 view_model_.set_ideal_bounds(i, tile_slot); 1296 view_model_.set_ideal_bounds(i, tile_slot);
1270 } else { 1297 } else {
1271 pulsing_blocks_model_.set_ideal_bounds(i - view_model_.view_size(), 1298 pulsing_blocks_model_.set_ideal_bounds(i - view_model_.view_size(),
1272 tile_slot); 1299 tile_slot);
1273 } 1300 }
1274 1301
1275 ++slot_index; 1302 ++slot_index;
1276 } 1303 }
(...skipping 968 matching lines...) Expand 10 before | Expand all | Expand 10 after
2245 2272
2246 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, 2273 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index,
2247 bool is_target_folder) { 2274 bool is_target_folder) {
2248 AppListItemView* target_view = 2275 AppListItemView* target_view =
2249 static_cast<AppListItemView*>( 2276 static_cast<AppListItemView*>(
2250 GetViewAtSlotOnCurrentPage(target_index.slot)); 2277 GetViewAtSlotOnCurrentPage(target_index.slot));
2251 if (target_view) 2278 if (target_view)
2252 target_view->SetAsAttemptedFolderTarget(is_target_folder); 2279 target_view->SetAsAttemptedFolderTarget(is_target_folder);
2253 } 2280 }
2254 2281
2282 // static
2283 AppsGridView::ScrollAxis AppsGridView::GetScrollAxis() {
2284 // The experimental app list transitions vertically.
2285 return app_list::switches::IsExperimentalAppListEnabled()
2286 ? SCROLL_AXIS_VERTICAL
2287 : SCROLL_AXIS_HORIZONTAL;
2288 }
2289
2255 } // namespace app_list 2290 } // 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