| 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 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 pagination_model_.RemoveObserver(this); | 380 pagination_model_.RemoveObserver(this); |
| 381 | 381 |
| 382 if (item_list_) | 382 if (item_list_) |
| 383 item_list_->RemoveObserver(this); | 383 item_list_->RemoveObserver(this); |
| 384 | 384 |
| 385 // Make sure |page_switcher_view_| is deleted before |pagination_model_|. | 385 // Make sure |page_switcher_view_| is deleted before |pagination_model_|. |
| 386 view_model_.Clear(); | 386 view_model_.Clear(); |
| 387 RemoveAllChildViews(true); | 387 RemoveAllChildViews(true); |
| 388 } | 388 } |
| 389 | 389 |
| 390 void AppsGridView::SetLayout(int icon_size, int cols, int rows_per_page) { | 390 void AppsGridView::SetLayout(int cols, int rows_per_page) { |
| 391 icon_size_.SetSize(icon_size, icon_size); | |
| 392 cols_ = cols; | 391 cols_ = cols; |
| 393 rows_per_page_ = rows_per_page; | 392 rows_per_page_ = rows_per_page; |
| 394 | 393 |
| 395 SetBorder(views::Border::CreateEmptyBorder( | 394 SetBorder(views::Border::CreateEmptyBorder( |
| 396 kTopPadding, kLeftRightPadding, 0, kLeftRightPadding)); | 395 kTopPadding, kLeftRightPadding, 0, kLeftRightPadding)); |
| 397 } | 396 } |
| 398 | 397 |
| 399 void AppsGridView::ResetForShowApps() { | 398 void AppsGridView::ResetForShowApps() { |
| 400 activated_folder_item_view_ = NULL; | 399 activated_folder_item_view_ = NULL; |
| 401 ClearDragState(); | 400 ClearDragState(); |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 | 774 |
| 776 // Create a new AppListItemView to duplicate the original_drag_view in the | 775 // Create a new AppListItemView to duplicate the original_drag_view in the |
| 777 // folder's grid view. | 776 // folder's grid view. |
| 778 AppListItemView* view = new AppListItemView(this, original_drag_view->item()); | 777 AppListItemView* view = new AppListItemView(this, original_drag_view->item()); |
| 779 AddChildView(view); | 778 AddChildView(view); |
| 780 drag_view_ = view; | 779 drag_view_ = view; |
| 781 drag_view_->SetPaintToLayer(true); | 780 drag_view_->SetPaintToLayer(true); |
| 782 // Note: For testing purpose, SetFillsBoundsOpaquely can be set to true to | 781 // Note: For testing purpose, SetFillsBoundsOpaquely can be set to true to |
| 783 // show the gray background. | 782 // show the gray background. |
| 784 drag_view_->SetFillsBoundsOpaquely(false); | 783 drag_view_->SetFillsBoundsOpaquely(false); |
| 785 drag_view_->SetIconSize(icon_size_); | |
| 786 drag_view_->SetBoundsRect(drag_view_rect); | 784 drag_view_->SetBoundsRect(drag_view_rect); |
| 787 drag_view_->SetDragUIState(); // Hide the title of the drag_view_. | 785 drag_view_->SetDragUIState(); // Hide the title of the drag_view_. |
| 788 | 786 |
| 789 // Hide the drag_view_ for drag icon proxy. | 787 // Hide the drag_view_ for drag icon proxy. |
| 790 SetViewHidden(drag_view_, | 788 SetViewHidden(drag_view_, |
| 791 true /* hide */, | 789 true /* hide */, |
| 792 true /* no animate */); | 790 true /* no animate */); |
| 793 | 791 |
| 794 // Add drag_view_ to the end of the view_model_. | 792 // Add drag_view_ to the end of the view_model_. |
| 795 view_model_.Add(drag_view_, view_model_.view_size()); | 793 view_model_.Add(drag_view_, view_model_.view_size()); |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1020 AddChildView(view); | 1018 AddChildView(view); |
| 1021 } | 1019 } |
| 1022 } | 1020 } |
| 1023 | 1021 |
| 1024 views::View* AppsGridView::CreateViewForItemAtIndex(size_t index) { | 1022 views::View* AppsGridView::CreateViewForItemAtIndex(size_t index) { |
| 1025 // The drag_view_ might be pending for deletion, therefore view_model_ | 1023 // The drag_view_ might be pending for deletion, therefore view_model_ |
| 1026 // may have one more item than item_list_. | 1024 // may have one more item than item_list_. |
| 1027 DCHECK_LE(index, item_list_->item_count()); | 1025 DCHECK_LE(index, item_list_->item_count()); |
| 1028 AppListItemView* view = new AppListItemView(this, | 1026 AppListItemView* view = new AppListItemView(this, |
| 1029 item_list_->item_at(index)); | 1027 item_list_->item_at(index)); |
| 1030 view->SetIconSize(icon_size_); | |
| 1031 view->SetPaintToLayer(true); | 1028 view->SetPaintToLayer(true); |
| 1032 view->SetFillsBoundsOpaquely(false); | 1029 view->SetFillsBoundsOpaquely(false); |
| 1033 return view; | 1030 return view; |
| 1034 } | 1031 } |
| 1035 | 1032 |
| 1036 AppsGridView::Index AppsGridView::GetIndexFromModelIndex( | 1033 AppsGridView::Index AppsGridView::GetIndexFromModelIndex( |
| 1037 int model_index) const { | 1034 int model_index) const { |
| 1038 return Index(model_index / tiles_per_page(), model_index % tiles_per_page()); | 1035 return Index(model_index / tiles_per_page(), model_index % tiles_per_page()); |
| 1039 } | 1036 } |
| 1040 | 1037 |
| (...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1846 // The icon of the dragged item must target to its final ideal bounds after | 1843 // The icon of the dragged item must target to its final ideal bounds after |
| 1847 // the animation completes. | 1844 // the animation completes. |
| 1848 CalculateIdealBounds(); | 1845 CalculateIdealBounds(); |
| 1849 | 1846 |
| 1850 gfx::Rect target_icon_rect = | 1847 gfx::Rect target_icon_rect = |
| 1851 GetTargetIconRectInFolder(drag_item_view, activated_folder_item_view_); | 1848 GetTargetIconRectInFolder(drag_item_view, activated_folder_item_view_); |
| 1852 | 1849 |
| 1853 gfx::Rect drag_view_icon_to_grid = | 1850 gfx::Rect drag_view_icon_to_grid = |
| 1854 drag_item_view->ConvertRectToParent(drag_item_view->GetIconBounds()); | 1851 drag_item_view->ConvertRectToParent(drag_item_view->GetIconBounds()); |
| 1855 drag_view_icon_to_grid.ClampToCenteredSize( | 1852 drag_view_icon_to_grid.ClampToCenteredSize( |
| 1856 gfx::Size(kPreferredIconDimension, kPreferredIconDimension)); | 1853 gfx::Size(kGridIconDimension, kGridIconDimension)); |
| 1857 TopIconAnimationView* icon_view = new TopIconAnimationView( | 1854 TopIconAnimationView* icon_view = new TopIconAnimationView( |
| 1858 drag_item_view->item()->icon(), | 1855 drag_item_view->item()->icon(), |
| 1859 target_icon_rect, | 1856 target_icon_rect, |
| 1860 false); /* animate like closing folder */ | 1857 false); /* animate like closing folder */ |
| 1861 AddChildView(icon_view); | 1858 AddChildView(icon_view); |
| 1862 icon_view->SetBoundsRect(drag_view_icon_to_grid); | 1859 icon_view->SetBoundsRect(drag_view_icon_to_grid); |
| 1863 icon_view->TransformView(); | 1860 icon_view->TransformView(); |
| 1864 } | 1861 } |
| 1865 | 1862 |
| 1866 void AppsGridView::CancelContextMenusOnCurrentPage() { | 1863 void AppsGridView::CancelContextMenusOnCurrentPage() { |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2033 | 2030 |
| 2034 // Calculate the bottom left tile |drag_view| intersects. | 2031 // Calculate the bottom left tile |drag_view| intersects. |
| 2035 pt = drag_view_->bounds().bottom_left(); | 2032 pt = drag_view_->bounds().bottom_left(); |
| 2036 CalculateNearestTileForVertex(pt, &nearest_tile, &d_min); | 2033 CalculateNearestTileForVertex(pt, &nearest_tile, &d_min); |
| 2037 | 2034 |
| 2038 // Calculate the bottom right tile |drag_view| intersects. | 2035 // Calculate the bottom right tile |drag_view| intersects. |
| 2039 pt = drag_view_->bounds().bottom_right(); | 2036 pt = drag_view_->bounds().bottom_right(); |
| 2040 CalculateNearestTileForVertex(pt, &nearest_tile, &d_min); | 2037 CalculateNearestTileForVertex(pt, &nearest_tile, &d_min); |
| 2041 | 2038 |
| 2042 const int d_folder_dropping = | 2039 const int d_folder_dropping = |
| 2043 kFolderDroppingCircleRadius + kPreferredIconDimension / 2; | 2040 kFolderDroppingCircleRadius + kGridIconDimension / 2; |
| 2044 const int d_reorder = | 2041 const int d_reorder = kReorderDroppingCircleRadius + kGridIconDimension / 2; |
| 2045 kReorderDroppingCircleRadius + kPreferredIconDimension / 2; | |
| 2046 | 2042 |
| 2047 // If user drags an item across pages to the last page, and targets it | 2043 // If user drags an item across pages to the last page, and targets it |
| 2048 // to the last empty slot on it, push the last item for re-ordering. | 2044 // to the last empty slot on it, push the last item for re-ordering. |
| 2049 if (IsLastPossibleDropTarget(nearest_tile) && d_min < d_reorder) { | 2045 if (IsLastPossibleDropTarget(nearest_tile) && d_min < d_reorder) { |
| 2050 drop_attempt_ = DROP_FOR_REORDER; | 2046 drop_attempt_ = DROP_FOR_REORDER; |
| 2051 nearest_tile.slot = nearest_tile.slot - 1; | 2047 nearest_tile.slot = nearest_tile.slot - 1; |
| 2052 return nearest_tile; | 2048 return nearest_tile; |
| 2053 } | 2049 } |
| 2054 | 2050 |
| 2055 if (IsValidIndex(nearest_tile)) { | 2051 if (IsValidIndex(nearest_tile)) { |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2175 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, | 2171 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, |
| 2176 bool is_target_folder) { | 2172 bool is_target_folder) { |
| 2177 AppListItemView* target_view = | 2173 AppListItemView* target_view = |
| 2178 static_cast<AppListItemView*>( | 2174 static_cast<AppListItemView*>( |
| 2179 GetViewAtSlotOnCurrentPage(target_index.slot)); | 2175 GetViewAtSlotOnCurrentPage(target_index.slot)); |
| 2180 if (target_view) | 2176 if (target_view) |
| 2181 target_view->SetAsAttemptedFolderTarget(is_target_folder); | 2177 target_view->SetAsAttemptedFolderTarget(is_target_folder); |
| 2182 } | 2178 } |
| 2183 | 2179 |
| 2184 } // namespace app_list | 2180 } // namespace app_list |
| OLD | NEW |