OLD | NEW |
---|---|
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 Loading... | |
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_HORIZONTAL |
907 // transitioning to previous page. | 908 ? details.scroll_x() |
908 pagination_model_.UpdateScroll(event->details().scroll_x() / | 909 : details.scroll_y(); |
909 GetContentsBounds().width()); | 910 gfx::Rect bounds(GetContentsBounds()); |
911 int width = GetScrollAxis() == SCROLL_AXIS_HORIZONTAL ? bounds.width() | |
912 : bounds.height(); | |
913 // scroll > 0 means moving contents right or down. That is, transitioning | |
914 // to the previous page. | |
915 pagination_model_.UpdateScroll(scroll / width); | |
910 event->SetHandled(); | 916 event->SetHandled(); |
911 return; | 917 return; |
918 } | |
912 case ui::ET_GESTURE_SCROLL_END: | 919 case ui::ET_GESTURE_SCROLL_END: |
913 pagination_model_.EndScroll(pagination_model_.transition().progress < | 920 pagination_model_.EndScroll(pagination_model_.transition().progress < |
914 kFinishTransitionThreshold); | 921 kFinishTransitionThreshold); |
915 event->SetHandled(); | 922 event->SetHandled(); |
916 return; | 923 return; |
917 case ui::ET_SCROLL_FLING_START: { | 924 case ui::ET_SCROLL_FLING_START: { |
925 float velocity = GetScrollAxis() == SCROLL_AXIS_HORIZONTAL | |
926 ? details.velocity_x() | |
927 : details.velocity_y(); | |
918 pagination_model_.EndScroll(true); | 928 pagination_model_.EndScroll(true); |
919 if (fabs(event->details().velocity_x()) > kMinHorizVelocityToSwitchPage) { | 929 if (fabs(velocity) > kMinHorizVelocityToSwitchPage) |
920 pagination_model_.SelectPageRelative( | 930 pagination_model_.SelectPageRelative(velocity < 0 ? 1 : -1, true); |
921 event->details().velocity_x() < 0 ? 1 : -1, true); | |
922 } | |
923 event->SetHandled(); | 931 event->SetHandled(); |
924 return; | 932 return; |
925 } | 933 } |
926 default: | 934 default: |
927 break; | 935 break; |
928 } | 936 } |
929 } | 937 } |
930 | 938 |
931 void AppsGridView::OnScrollEvent(ui::ScrollEvent* event) { | 939 void AppsGridView::OnScrollEvent(ui::ScrollEvent* event) { |
932 if (event->type() == ui::ET_SCROLL_FLING_CANCEL) | 940 if (event->type() == ui::ET_SCROLL_FLING_CANCEL) |
933 return; | 941 return; |
934 | 942 |
935 float offset; | 943 float offset; |
936 if (std::abs(event->x_offset()) > std::abs(event->y_offset())) | 944 if (GetScrollAxis() == SCROLL_AXIS_HORIZONTAL) { |
Matt Giuca
2014/08/28 08:35:20
Ugh, this duplication (with OnMouseWheel) is getti
| |
937 offset = event->x_offset(); | 945 // If the view scrolls horizontally, both horizontal and vertical scroll |
938 else | 946 // events are valid (vertical scroll events simulate mouse wheel). |
947 if (std::abs(event->x_offset()) > std::abs(event->y_offset())) | |
948 offset = event->x_offset(); | |
949 else | |
950 offset = event->y_offset(); | |
951 } else { | |
952 // If the view scrolls vertically, only vertical scroll events are valid. | |
939 offset = event->y_offset(); | 953 offset = event->y_offset(); |
954 } | |
940 | 955 |
941 if (std::abs(offset) > kMinScrollToSwitchPage) { | 956 if (std::abs(offset) > kMinScrollToSwitchPage) { |
942 if (!pagination_model_.has_transition()) { | 957 if (!pagination_model_.has_transition()) { |
943 pagination_model_.SelectPageRelative(offset > 0 ? -1 : 1, true); | 958 pagination_model_.SelectPageRelative(offset > 0 ? -1 : 1, true); |
944 } | 959 } |
945 event->SetHandled(); | 960 event->SetHandled(); |
946 event->StopPropagation(); | 961 event->StopPropagation(); |
947 } | 962 } |
948 } | 963 } |
949 | 964 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1006 bool AppsGridView::OnKeyReleased(const ui::KeyEvent& event) { | 1021 bool AppsGridView::OnKeyReleased(const ui::KeyEvent& event) { |
1007 bool handled = false; | 1022 bool handled = false; |
1008 if (selected_view_) | 1023 if (selected_view_) |
1009 handled = selected_view_->OnKeyReleased(event); | 1024 handled = selected_view_->OnKeyReleased(event); |
1010 | 1025 |
1011 return handled; | 1026 return handled; |
1012 } | 1027 } |
1013 | 1028 |
1014 bool AppsGridView::OnMouseWheel(const ui::MouseWheelEvent& event) { | 1029 bool AppsGridView::OnMouseWheel(const ui::MouseWheelEvent& event) { |
1015 int offset; | 1030 int offset; |
1016 if (abs(event.x_offset()) > abs(event.y_offset())) | 1031 if (GetScrollAxis() == SCROLL_AXIS_HORIZONTAL) { |
1017 offset = event.x_offset(); | 1032 // If the view scrolls horizontally, both horizontal and vertical scroll |
1018 else | 1033 // events are valid (since most mouse wheels only have vertical scrolling). |
1034 if (abs(event.x_offset()) > abs(event.y_offset())) | |
1035 offset = event.x_offset(); | |
1036 else | |
1037 offset = event.y_offset(); | |
1038 } else { | |
1039 // If the view scrolls vertically, only vertical scroll events are valid. | |
1019 offset = event.y_offset(); | 1040 offset = event.y_offset(); |
1041 } | |
1020 | 1042 |
1021 if (abs(offset) > kMinMouseWheelToSwitchPage) { | 1043 if (abs(offset) > kMinMouseWheelToSwitchPage) { |
1022 if (!pagination_model_.has_transition()) { | 1044 if (!pagination_model_.has_transition()) { |
1023 pagination_model_.SelectPageRelative(offset > 0 ? -1 : 1, true); | 1045 pagination_model_.SelectPageRelative(offset > 0 ? -1 : 1, true); |
1024 } | 1046 } |
1025 return true; | 1047 return true; |
1026 } | 1048 } |
1027 | 1049 |
1028 return false; | 1050 return false; |
1029 } | 1051 } |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 Loading... | |
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 |
OLD | NEW |