Commit 91d3b693 authored by calamity's avatar calamity Committed by Commit bot

Refactor app list max folder logic.

This CL refactors the logic to fit all the folder
dropping logic in CalculateFolderDropTarget().

BUG=419642

Review URL: https://codereview.chromium.org/614213004

Cr-Commit-Position: refs/heads/master@{#300068}
parent 430b5eff
......@@ -212,7 +212,7 @@ class ItemMoveAnimationDelegate : public gfx::AnimationDelegate {
DISALLOW_COPY_AND_ASSIGN(ItemMoveAnimationDelegate);
};
// Returns true if the |item| is an folder item.
// Returns true if the |item| is a folder item.
bool IsFolderItem(AppListItem* item) {
return (item->GetItemType() == AppListFolderItem::kItemType);
}
......@@ -1388,20 +1388,42 @@ void AppsGridView::CalculateDropTarget() {
bool AppsGridView::CalculateFolderDropTarget(const gfx::Point& point,
Index* drop_target) const {
// Folders can't be dropped into other folders.
if (IsFolderItem(drag_view_->item()))
return false;
// A folder drop shouldn't happen on the reorder placeholder since that would
// be merging an item with itself.
Index nearest_tile_index(GetNearestTileIndexForPoint(point));
if (!IsValidIndex(nearest_tile_index) ||
nearest_tile_index == reorder_placeholder_) {
return false;
}
int distance_to_tile_center =
(point - GetExpectedTileBounds(nearest_tile_index.slot).CenterPoint())
.Length();
if (nearest_tile_index != reorder_placeholder_ &&
distance_to_tile_center < kFolderDroppingCircleRadius &&
!IsFolderItem(drag_view_->item()) &&
CanDropIntoTarget(nearest_tile_index)) {
*drop_target = nearest_tile_index;
DCHECK(IsValidIndex(*drop_target));
return true;
if (distance_to_tile_center > kFolderDroppingCircleRadius)
return false;
AppListItemView* target_view =
GetViewDisplayedAtSlotOnCurrentPage(nearest_tile_index.slot);
if (!target_view)
return false;
AppListItem* target_item = target_view->item();
// Items can only be dropped into non-folders (which have no children) or
// folders that have fewer than the max allowed items.
// The OEM folder does not allow drag/drop of other items into it.
if (target_item->ChildItemCount() >= kMaxFolderItems ||
IsOEMFolderItem(target_item)) {
return false;
}
return false;
*drop_target = nearest_tile_index;
DCHECK(IsValidIndex(*drop_target));
return true;
}
void AppsGridView::CalculateReorderDropTarget(const gfx::Point& point,
......@@ -2086,20 +2108,6 @@ bool AppsGridView::EnableFolderDragDropUI() {
return model_->folders_enabled() && !folder_delegate_;
}
bool AppsGridView::CanDropIntoTarget(const Index& drop_target) const {
AppListItemView* target_view =
GetViewDisplayedAtSlotOnCurrentPage(drop_target.slot);
if (!target_view)
return false;
AppListItem* target_item = target_view->item();
// Items can be dropped into non-folders (which have no children) or folders
// that have fewer than the max allowed items.
// OEM folder does not allow to drag/drop other items in it.
return target_item->ChildItemCount() < kMaxFolderItems &&
!IsOEMFolderItem(target_item);
}
AppsGridView::Index AppsGridView::GetNearestTileIndexForPoint(
const gfx::Point& point) const {
gfx::Rect bounds = GetContentsBounds();
......
......@@ -400,10 +400,6 @@ class APP_LIST_EXPORT AppsGridView : public views::View,
// Whether the folder drag-and-drop UI should be enabled.
bool EnableFolderDragDropUI();
// Whether target specified by |drap_target| can accept more items to be
// dropped into it.
bool CanDropIntoTarget(const Index& drop_target) const;
// Returns the size of the entire tile grid.
gfx::Size GetTileGridSize() const;
......
......@@ -485,14 +485,14 @@ TEST_F(AppsGridViewTest, MouseDragItemReorder) {
int tile_height = GetItemTileRectAt(1, 0).y() - GetItemTileRectAt(0, 0).y();
// Drag left but stop before the folder dropping circle.
drag_vector.set_x(-half_tile_width - 5);
drag_vector.set_x(-half_tile_width - 4);
SimulateDrag(AppsGridView::MOUSE, top_right, top_right + drag_vector);
apps_grid_view_->EndDrag(false);
EXPECT_EQ(std::string("Item 0,Item 1,Item 2,Item 3"),
model_->GetModelContent());
// Drag left, past the folder dropping circle.
drag_vector.set_x(-3 * half_tile_width + 5);
drag_vector.set_x(-3 * half_tile_width + 4);
SimulateDrag(AppsGridView::MOUSE, top_right, top_right + drag_vector);
apps_grid_view_->EndDrag(false);
EXPECT_EQ(std::string("Item 1,Item 0,Item 2,Item 3"),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment