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 1382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1393 Index* drop_target) const { | 1393 Index* drop_target) const { |
1394 Index nearest_tile_index(GetNearestTileIndexForPoint(point)); | 1394 Index nearest_tile_index(GetNearestTileIndexForPoint(point)); |
1395 int distance_to_tile_center = | 1395 int distance_to_tile_center = |
1396 (point - GetExpectedTileBounds(nearest_tile_index.slot).CenterPoint()) | 1396 (point - GetExpectedTileBounds(nearest_tile_index.slot).CenterPoint()) |
1397 .Length(); | 1397 .Length(); |
1398 if (nearest_tile_index != reorder_placeholder_ && | 1398 if (nearest_tile_index != reorder_placeholder_ && |
1399 distance_to_tile_center < kFolderDroppingCircleRadius && | 1399 distance_to_tile_center < kFolderDroppingCircleRadius && |
1400 !IsFolderItem(drag_view_->item()) && | 1400 !IsFolderItem(drag_view_->item()) && |
1401 CanDropIntoTarget(nearest_tile_index)) { | 1401 CanDropIntoTarget(nearest_tile_index)) { |
1402 *drop_target = nearest_tile_index; | 1402 *drop_target = nearest_tile_index; |
| 1403 DCHECK(IsValidIndex(*drop_target)); |
1403 return true; | 1404 return true; |
1404 } | 1405 } |
1405 | 1406 |
1406 return false; | 1407 return false; |
1407 } | 1408 } |
1408 | 1409 |
1409 void AppsGridView::CalculateReorderDropTarget(const gfx::Point& point, | 1410 void AppsGridView::CalculateReorderDropTarget(const gfx::Point& point, |
1410 Index* drop_target) const { | 1411 Index* drop_target) const { |
1411 gfx::Rect bounds = GetContentsBounds(); | 1412 gfx::Rect bounds = GetContentsBounds(); |
1412 Index grid_index = GetNearestTileIndexForPoint(point); | 1413 Index grid_index = GetNearestTileIndexForPoint(point); |
(...skipping 16 matching lines...) Expand all Loading... |
1429 // | 1430 // |
1430 // This makes eordering feel like the user is slotting items into the spaces | 1431 // This makes eordering feel like the user is slotting items into the spaces |
1431 // between apps. | 1432 // between apps. |
1432 int x_offset = x_offset_direction * | 1433 int x_offset = x_offset_direction * |
1433 (total_tile_size.width() - kFolderDroppingCircleRadius) / 2; | 1434 (total_tile_size.width() - kFolderDroppingCircleRadius) / 2; |
1434 int col = (point.x() - bounds.x() + x_offset) / total_tile_size.width(); | 1435 int col = (point.x() - bounds.x() + x_offset) / total_tile_size.width(); |
1435 col = ClampToRange(col, 0, cols_ - 1); | 1436 col = ClampToRange(col, 0, cols_ - 1); |
1436 *drop_target = | 1437 *drop_target = |
1437 std::min(Index(pagination_model_.selected_page(), row * cols_ + col), | 1438 std::min(Index(pagination_model_.selected_page(), row * cols_ + col), |
1438 GetLastViewIndex()); | 1439 GetLastViewIndex()); |
| 1440 DCHECK(IsValidIndex(*drop_target)); |
1439 } | 1441 } |
1440 | 1442 |
1441 void AppsGridView::OnReorderTimer() { | 1443 void AppsGridView::OnReorderTimer() { |
1442 if (drop_attempt_ == DROP_FOR_REORDER) { | 1444 if (drop_attempt_ == DROP_FOR_REORDER) { |
1443 reorder_placeholder_ = reorder_drop_target_; | 1445 reorder_placeholder_ = reorder_drop_target_; |
1444 AnimateToIdealBounds(); | 1446 AnimateToIdealBounds(); |
1445 } | 1447 } |
1446 } | 1448 } |
1447 | 1449 |
1448 void AppsGridView::OnFolderItemReparentTimer() { | 1450 void AppsGridView::OnFolderItemReparentTimer() { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1543 DCHECK(IsDraggingForReparentInRootLevelGridView()); | 1545 DCHECK(IsDraggingForReparentInRootLevelGridView()); |
1544 bool cancel_reparent = cancel_drag || drop_attempt_ == DROP_FOR_NONE; | 1546 bool cancel_reparent = cancel_drag || drop_attempt_ == DROP_FOR_NONE; |
1545 if (!events_forwarded_to_drag_drop_host && !cancel_reparent) { | 1547 if (!events_forwarded_to_drag_drop_host && !cancel_reparent) { |
1546 CalculateDropTarget(); | 1548 CalculateDropTarget(); |
1547 if (drop_attempt_ == DROP_FOR_REORDER && | 1549 if (drop_attempt_ == DROP_FOR_REORDER && |
1548 IsValidIndex(reorder_drop_target_)) { | 1550 IsValidIndex(reorder_drop_target_)) { |
1549 ReparentItemForReorder(drag_view_, reorder_drop_target_); | 1551 ReparentItemForReorder(drag_view_, reorder_drop_target_); |
1550 } else if (drop_attempt_ == DROP_FOR_FOLDER && | 1552 } else if (drop_attempt_ == DROP_FOR_FOLDER && |
1551 IsValidIndex(folder_drop_target_)) { | 1553 IsValidIndex(folder_drop_target_)) { |
1552 ReparentItemToAnotherFolder(drag_view_, folder_drop_target_); | 1554 ReparentItemToAnotherFolder(drag_view_, folder_drop_target_); |
| 1555 } else { |
| 1556 NOTREACHED(); |
1553 } | 1557 } |
1554 SetViewHidden(drag_view_, false /* show */, true /* no animate */); | 1558 SetViewHidden(drag_view_, false /* show */, true /* no animate */); |
1555 } | 1559 } |
1556 | 1560 |
1557 // The drag can be ended after the synchronous drag is created but before it | 1561 // The drag can be ended after the synchronous drag is created but before it |
1558 // is Run(). | 1562 // is Run(). |
1559 CleanUpSynchronousDrag(); | 1563 CleanUpSynchronousDrag(); |
1560 | 1564 |
1561 SetAsFolderDroppingTarget(folder_drop_target_, false); | 1565 SetAsFolderDroppingTarget(folder_drop_target_, false); |
1562 if (cancel_reparent) { | 1566 if (cancel_reparent) { |
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2088 // OEM folder does not allow to drag/drop other items in it. | 2092 // OEM folder does not allow to drag/drop other items in it. |
2089 return target_item->ChildItemCount() < kMaxFolderItems && | 2093 return target_item->ChildItemCount() < kMaxFolderItems && |
2090 !IsOEMFolderItem(target_item); | 2094 !IsOEMFolderItem(target_item); |
2091 } | 2095 } |
2092 | 2096 |
2093 AppsGridView::Index AppsGridView::GetNearestTileIndexForPoint( | 2097 AppsGridView::Index AppsGridView::GetNearestTileIndexForPoint( |
2094 const gfx::Point& point) const { | 2098 const gfx::Point& point) const { |
2095 gfx::Rect bounds = GetContentsBounds(); | 2099 gfx::Rect bounds = GetContentsBounds(); |
2096 gfx::Size total_tile_size = GetTotalTileSize(); | 2100 gfx::Size total_tile_size = GetTotalTileSize(); |
2097 int col = ClampToRange( | 2101 int col = ClampToRange( |
2098 (point.x() - bounds.x()) / total_tile_size.width(), 0, cols_); | 2102 (point.x() - bounds.x()) / total_tile_size.width(), 0, cols_ - 1); |
2099 int row = ClampToRange( | 2103 int row = ClampToRange((point.y() - bounds.y()) / total_tile_size.height(), |
2100 (point.y() - bounds.y()) / total_tile_size.height(), 0, rows_per_page_); | 2104 0, |
| 2105 rows_per_page_ - 1); |
2101 return Index(pagination_model_.selected_page(), row * cols_ + col); | 2106 return Index(pagination_model_.selected_page(), row * cols_ + col); |
2102 } | 2107 } |
2103 | 2108 |
2104 gfx::Size AppsGridView::GetTileGridSize() const { | 2109 gfx::Size AppsGridView::GetTileGridSize() const { |
2105 gfx::Rect bounds = GetExpectedTileBounds(0, 0); | 2110 gfx::Rect bounds = GetExpectedTileBounds(0, 0); |
2106 bounds.Union(GetExpectedTileBounds(rows_per_page_ - 1, cols_ - 1)); | 2111 bounds.Union(GetExpectedTileBounds(rows_per_page_ - 1, cols_ - 1)); |
2107 if (switches::IsExperimentalAppListEnabled()) | 2112 if (switches::IsExperimentalAppListEnabled()) |
2108 bounds.Inset(-kExperimentalTileLeftRightPadding, | 2113 bounds.Inset(-kExperimentalTileLeftRightPadding, |
2109 -kExperimentalTileTopBottomPadding); | 2114 -kExperimentalTileTopBottomPadding); |
2110 return bounds.size(); | 2115 return bounds.size(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2144 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, | 2149 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, |
2145 bool is_target_folder) { | 2150 bool is_target_folder) { |
2146 AppListItemView* target_view = | 2151 AppListItemView* target_view = |
2147 static_cast<AppListItemView*>( | 2152 static_cast<AppListItemView*>( |
2148 GetViewAtSlotOnCurrentPage(target_index.slot)); | 2153 GetViewAtSlotOnCurrentPage(target_index.slot)); |
2149 if (target_view) | 2154 if (target_view) |
2150 target_view->SetAsAttemptedFolderTarget(is_target_folder); | 2155 target_view->SetAsAttemptedFolderTarget(is_target_folder); |
2151 } | 2156 } |
2152 | 2157 |
2153 } // namespace app_list | 2158 } // namespace app_list |
OLD | NEW |