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 (GetLastViewIndex() < nearest_tile_index || | |
Matt Giuca
2014/10/02 06:08:59
I don't understand where this condition (GetLastVi
calamity
2014/10/03 03:37:36
Wups. Roundabout way of checking index validity. F
| |
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) |
Matt Giuca
2014/10/02 06:08:59
FYI, you are slightly changing the behaviour here.
calamity
2014/10/03 03:37:36
I think radii of drop zones should be inclusive of
Matt Giuca
2014/10/09 17:25:18
Acknowledged.
| |
1401 distance_to_tile_center < kFolderDroppingCircleRadius && | 1412 return false; |
1402 !IsFolderItem(drag_view_->item()) && | 1413 |
1403 CanDropIntoTarget(nearest_tile_index)) { | 1414 AppListItemView* target_view = |
Matt Giuca
2014/10/02 06:08:59
I'm not sure I agree with inlining CanDropIntoTarg
calamity
2014/10/03 03:37:37
It's only used in one place and the logic should b
Matt Giuca
2014/10/09 17:25:18
Acknowledged.
| |
1404 *drop_target = nearest_tile_index; | 1415 GetViewDisplayedAtSlotOnCurrentPage(nearest_tile_index.slot); |
Matt Giuca
2014/10/02 06:08:59
You removed the NULL-check here?
calamity
2014/10/03 03:37:37
Hmmmmm. I _think_ this can't be NULL. But maybe it
| |
1405 DCHECK(IsValidIndex(*drop_target)); | 1416 AppListItem* target_item = target_view->item(); |
1406 return true; | 1417 |
1418 // Items can only be dropped into non-folders (which have no children) or | |
1419 // folders that have fewer than the max allowed items. | |
1420 // The OEM folder does not allow drag/drop of other items into it. | |
1421 if (target_item->ChildItemCount() >= kMaxFolderItems || | |
1422 IsOEMFolderItem(target_item)) { | |
1423 return false; | |
1407 } | 1424 } |
1408 | 1425 |
1409 return false; | 1426 *drop_target = nearest_tile_index; |
1427 DCHECK(IsValidIndex(*drop_target)); | |
1428 return true; | |
1410 } | 1429 } |
1411 | 1430 |
1412 void AppsGridView::CalculateReorderDropTarget(const gfx::Point& point, | 1431 void AppsGridView::CalculateReorderDropTarget(const gfx::Point& point, |
1413 Index* drop_target) const { | 1432 Index* drop_target) const { |
1414 gfx::Rect bounds = GetContentsBounds(); | 1433 gfx::Rect bounds = GetContentsBounds(); |
1415 Index grid_index = GetNearestTileIndexForPoint(point); | 1434 Index grid_index = GetNearestTileIndexForPoint(point); |
1416 gfx::Point reorder_placeholder_center = | 1435 gfx::Point reorder_placeholder_center = |
1417 GetExpectedTileBounds(reorder_placeholder_.slot).CenterPoint(); | 1436 GetExpectedTileBounds(reorder_placeholder_.slot).CenterPoint(); |
1418 | 1437 |
1419 int x_offset_direction = 0; | 1438 int x_offset_direction = 0; |
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2077 if (layer()->opacity() == 0.0f) | 2096 if (layer()->opacity() == 0.0f) |
2078 SetVisible(false); | 2097 SetVisible(false); |
2079 } | 2098 } |
2080 | 2099 |
2081 bool AppsGridView::EnableFolderDragDropUI() { | 2100 bool AppsGridView::EnableFolderDragDropUI() { |
2082 // Enable drag and drop folder UI only if it is at the app list root level | 2101 // Enable drag and drop folder UI only if it is at the app list root level |
2083 // and the switch is on. | 2102 // and the switch is on. |
2084 return model_->folders_enabled() && !folder_delegate_; | 2103 return model_->folders_enabled() && !folder_delegate_; |
2085 } | 2104 } |
2086 | 2105 |
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( | 2106 AppsGridView::Index AppsGridView::GetNearestTileIndexForPoint( |
2102 const gfx::Point& point) const { | 2107 const gfx::Point& point) const { |
2103 gfx::Rect bounds = GetContentsBounds(); | 2108 gfx::Rect bounds = GetContentsBounds(); |
2104 gfx::Size total_tile_size = GetTotalTileSize(); | 2109 gfx::Size total_tile_size = GetTotalTileSize(); |
2105 int col = ClampToRange( | 2110 int col = ClampToRange( |
2106 (point.x() - bounds.x()) / total_tile_size.width(), 0, cols_ - 1); | 2111 (point.x() - bounds.x()) / total_tile_size.width(), 0, cols_ - 1); |
2107 int row = ClampToRange((point.y() - bounds.y()) / total_tile_size.height(), | 2112 int row = ClampToRange((point.y() - bounds.y()) / total_tile_size.height(), |
2108 0, | 2113 0, |
2109 rows_per_page_ - 1); | 2114 rows_per_page_ - 1); |
2110 return Index(pagination_model_.selected_page(), row * cols_ + col); | 2115 return Index(pagination_model_.selected_page(), row * cols_ + col); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2153 | 2158 |
2154 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, | 2159 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, |
2155 bool is_target_folder) { | 2160 bool is_target_folder) { |
2156 AppListItemView* target_view = | 2161 AppListItemView* target_view = |
2157 GetViewDisplayedAtSlotOnCurrentPage(target_index.slot); | 2162 GetViewDisplayedAtSlotOnCurrentPage(target_index.slot); |
2158 if (target_view) | 2163 if (target_view) |
2159 target_view->SetAsAttemptedFolderTarget(is_target_folder); | 2164 target_view->SetAsAttemptedFolderTarget(is_target_folder); |
2160 } | 2165 } |
2161 | 2166 |
2162 } // namespace app_list | 2167 } // namespace app_list |
OLD | NEW |