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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 virtual void AnimationCanceled(const gfx::Animation* animation) OVERRIDE { | 205 virtual void AnimationCanceled(const gfx::Animation* animation) OVERRIDE { |
206 view_->SchedulePaint(); | 206 view_->SchedulePaint(); |
207 } | 207 } |
208 | 208 |
209 private: | 209 private: |
210 views::View* view_; | 210 views::View* view_; |
211 | 211 |
212 DISALLOW_COPY_AND_ASSIGN(ItemMoveAnimationDelegate); | 212 DISALLOW_COPY_AND_ASSIGN(ItemMoveAnimationDelegate); |
213 }; | 213 }; |
214 | 214 |
215 // Returns true if the |item| is an folder item. | 215 // Returns true if the |item| is a folder item. |
216 bool IsFolderItem(AppListItem* item) { | 216 bool IsFolderItem(AppListItem* item) { |
217 return (item->GetItemType() == AppListFolderItem::kItemType); | 217 return (item->GetItemType() == AppListFolderItem::kItemType); |
218 } | 218 } |
219 | 219 |
220 bool IsOEMFolderItem(AppListItem* item) { | 220 bool IsOEMFolderItem(AppListItem* item) { |
221 return IsFolderItem(item) && | 221 return IsFolderItem(item) && |
222 (static_cast<AppListFolderItem*>(item))->folder_type() == | 222 (static_cast<AppListFolderItem*>(item))->folder_type() == |
223 AppListFolderItem::FOLDER_TYPE_OEM; | 223 AppListFolderItem::FOLDER_TYPE_OEM; |
224 } | 224 } |
225 | 225 |
(...skipping 1160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1386 drop_attempt_ = DROP_FOR_FOLDER; | 1386 drop_attempt_ = DROP_FOR_FOLDER; |
1387 return; | 1387 return; |
1388 } | 1388 } |
1389 | 1389 |
1390 drop_attempt_ = DROP_FOR_REORDER; | 1390 drop_attempt_ = DROP_FOR_REORDER; |
1391 CalculateReorderDropTarget(point, &reorder_drop_target_); | 1391 CalculateReorderDropTarget(point, &reorder_drop_target_); |
1392 } | 1392 } |
1393 | 1393 |
1394 bool AppsGridView::CalculateFolderDropTarget(const gfx::Point& point, | 1394 bool AppsGridView::CalculateFolderDropTarget(const gfx::Point& point, |
1395 Index* drop_target) const { | 1395 Index* drop_target) const { |
| 1396 // Folders can't be dropped into other folders. |
| 1397 if (IsFolderItem(drag_view_->item())) |
| 1398 return false; |
| 1399 |
| 1400 // A folder drop shouldn't happen on the reorder placeholder since that would |
| 1401 // be merging an item with itself. |
1396 Index nearest_tile_index(GetNearestTileIndexForPoint(point)); | 1402 Index nearest_tile_index(GetNearestTileIndexForPoint(point)); |
| 1403 if (!IsValidIndex(nearest_tile_index) || |
| 1404 nearest_tile_index == reorder_placeholder_) { |
| 1405 return false; |
| 1406 } |
| 1407 |
1397 int distance_to_tile_center = | 1408 int distance_to_tile_center = |
1398 (point - GetExpectedTileBounds(nearest_tile_index.slot).CenterPoint()) | 1409 (point - GetExpectedTileBounds(nearest_tile_index.slot).CenterPoint()) |
1399 .Length(); | 1410 .Length(); |
1400 if (nearest_tile_index != reorder_placeholder_ && | 1411 if (distance_to_tile_center > kFolderDroppingCircleRadius) |
1401 distance_to_tile_center < kFolderDroppingCircleRadius && | 1412 return false; |
1402 !IsFolderItem(drag_view_->item()) && | 1413 |
1403 CanDropIntoTarget(nearest_tile_index)) { | 1414 AppListItemView* target_view = |
1404 *drop_target = nearest_tile_index; | 1415 GetViewDisplayedAtSlotOnCurrentPage(nearest_tile_index.slot); |
1405 DCHECK(IsValidIndex(*drop_target)); | 1416 if (!target_view) |
1406 return true; | 1417 return false; |
| 1418 |
| 1419 AppListItem* target_item = target_view->item(); |
| 1420 |
| 1421 // Items can only be dropped into non-folders (which have no children) or |
| 1422 // folders that have fewer than the max allowed items. |
| 1423 // The OEM folder does not allow drag/drop of other items into it. |
| 1424 if (target_item->ChildItemCount() >= kMaxFolderItems || |
| 1425 IsOEMFolderItem(target_item)) { |
| 1426 return false; |
1407 } | 1427 } |
1408 | 1428 |
1409 return false; | 1429 *drop_target = nearest_tile_index; |
| 1430 DCHECK(IsValidIndex(*drop_target)); |
| 1431 return true; |
1410 } | 1432 } |
1411 | 1433 |
1412 void AppsGridView::CalculateReorderDropTarget(const gfx::Point& point, | 1434 void AppsGridView::CalculateReorderDropTarget(const gfx::Point& point, |
1413 Index* drop_target) const { | 1435 Index* drop_target) const { |
1414 gfx::Rect bounds = GetContentsBounds(); | 1436 gfx::Rect bounds = GetContentsBounds(); |
1415 Index grid_index = GetNearestTileIndexForPoint(point); | 1437 Index grid_index = GetNearestTileIndexForPoint(point); |
1416 gfx::Point reorder_placeholder_center = | 1438 gfx::Point reorder_placeholder_center = |
1417 GetExpectedTileBounds(reorder_placeholder_.slot).CenterPoint(); | 1439 GetExpectedTileBounds(reorder_placeholder_.slot).CenterPoint(); |
1418 | 1440 |
1419 int x_offset_direction = 0; | 1441 int x_offset_direction = 0; |
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2077 if (layer()->opacity() == 0.0f) | 2099 if (layer()->opacity() == 0.0f) |
2078 SetVisible(false); | 2100 SetVisible(false); |
2079 } | 2101 } |
2080 | 2102 |
2081 bool AppsGridView::EnableFolderDragDropUI() { | 2103 bool AppsGridView::EnableFolderDragDropUI() { |
2082 // Enable drag and drop folder UI only if it is at the app list root level | 2104 // Enable drag and drop folder UI only if it is at the app list root level |
2083 // and the switch is on. | 2105 // and the switch is on. |
2084 return model_->folders_enabled() && !folder_delegate_; | 2106 return model_->folders_enabled() && !folder_delegate_; |
2085 } | 2107 } |
2086 | 2108 |
2087 bool AppsGridView::CanDropIntoTarget(const Index& drop_target) const { | |
2088 AppListItemView* target_view = | |
2089 GetViewDisplayedAtSlotOnCurrentPage(drop_target.slot); | |
2090 if (!target_view) | |
2091 return false; | |
2092 | |
2093 AppListItem* target_item = target_view->item(); | |
2094 // Items can be dropped into non-folders (which have no children) or folders | |
2095 // that have fewer than the max allowed items. | |
2096 // OEM folder does not allow to drag/drop other items in it. | |
2097 return target_item->ChildItemCount() < kMaxFolderItems && | |
2098 !IsOEMFolderItem(target_item); | |
2099 } | |
2100 | |
2101 AppsGridView::Index AppsGridView::GetNearestTileIndexForPoint( | 2109 AppsGridView::Index AppsGridView::GetNearestTileIndexForPoint( |
2102 const gfx::Point& point) const { | 2110 const gfx::Point& point) const { |
2103 gfx::Rect bounds = GetContentsBounds(); | 2111 gfx::Rect bounds = GetContentsBounds(); |
2104 gfx::Size total_tile_size = GetTotalTileSize(); | 2112 gfx::Size total_tile_size = GetTotalTileSize(); |
2105 int col = ClampToRange( | 2113 int col = ClampToRange( |
2106 (point.x() - bounds.x()) / total_tile_size.width(), 0, cols_ - 1); | 2114 (point.x() - bounds.x()) / total_tile_size.width(), 0, cols_ - 1); |
2107 int row = ClampToRange((point.y() - bounds.y()) / total_tile_size.height(), | 2115 int row = ClampToRange((point.y() - bounds.y()) / total_tile_size.height(), |
2108 0, | 2116 0, |
2109 rows_per_page_ - 1); | 2117 rows_per_page_ - 1); |
2110 return Index(pagination_model_.selected_page(), row * cols_ + col); | 2118 return Index(pagination_model_.selected_page(), row * cols_ + col); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2153 | 2161 |
2154 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, | 2162 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, |
2155 bool is_target_folder) { | 2163 bool is_target_folder) { |
2156 AppListItemView* target_view = | 2164 AppListItemView* target_view = |
2157 GetViewDisplayedAtSlotOnCurrentPage(target_index.slot); | 2165 GetViewDisplayedAtSlotOnCurrentPage(target_index.slot); |
2158 if (target_view) | 2166 if (target_view) |
2159 target_view->SetAsAttemptedFolderTarget(is_target_folder); | 2167 target_view->SetAsAttemptedFolderTarget(is_target_folder); |
2160 } | 2168 } |
2161 | 2169 |
2162 } // namespace app_list | 2170 } // namespace app_list |
OLD | NEW |