| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 | 53 |
| 54 namespace { | 54 namespace { |
| 55 | 55 |
| 56 // Distance a drag needs to be from the app grid to be considered 'outside', at | 56 // Distance a drag needs to be from the app grid to be considered 'outside', at |
| 57 // which point we rearrange the apps to their pre-drag configuration, as a drop | 57 // which point we rearrange the apps to their pre-drag configuration, as a drop |
| 58 // then would be canceled. We have a buffer to make it easier to drag apps to | 58 // then would be canceled. We have a buffer to make it easier to drag apps to |
| 59 // other pages. | 59 // other pages. |
| 60 const int kDragBufferPx = 20; | 60 const int kDragBufferPx = 20; |
| 61 | 61 |
| 62 // Padding space in pixels for fixed layout. | 62 // Padding space in pixels for fixed layout. |
| 63 const int kBottomPadding = 3; | 63 const int kBottomPadding = 2; |
| 64 const int kLeftRightPadding = 24; | 64 const int kLeftRightPadding = 24; |
| 65 | 65 |
| 66 // Padding space in pixels between pages. | 66 // Padding space in pixels between pages. |
| 67 const int kPagePadding = 40; | 67 const int kPagePadding = 40; |
| 68 | 68 |
| 69 // Preferred tile size when showing in fixed layout. | 69 // Preferred tile size when showing in fixed layout. |
| 70 const int kPreferredTileWidth = 88; | 70 const int kPreferredTileWidth = 88; |
| 71 const int kPreferredTileHeight = 98; | 71 const int kPreferredTileHeight = 98; |
| 72 | 72 |
| 73 const int kExperimentalPreferredTileWidth = 90; | 73 const int kExperimentalPreferredTileWidth = 100; |
| 74 const int kExperimentalPreferredTileHeight = 90; | 74 const int kExperimentalPreferredTileHeight = 100; |
| 75 | 75 |
| 76 // Padding on each side of a tile. | 76 // Padding on each side of a tile. |
| 77 const int kExperimentalTileLeftRightPadding = 15; | 77 const int kExperimentalTileLeftRightPadding = 10; |
| 78 const int kExperimentalTileTopBottomPadding = 11; | 78 const int kExperimentalTileBottomPadding = 12; |
| 79 const int kExperimentalTileTopPadding = 6; |
| 79 | 80 |
| 80 // Width in pixels of the area on the sides that triggers a page flip. | 81 // Width in pixels of the area on the sides that triggers a page flip. |
| 81 const int kPageFlipZoneSize = 40; | 82 const int kPageFlipZoneSize = 40; |
| 82 | 83 |
| 83 // Delay in milliseconds to do the page flip. | 84 // Delay in milliseconds to do the page flip. |
| 84 const int kPageFlipDelayInMs = 1000; | 85 const int kPageFlipDelayInMs = 1000; |
| 85 | 86 |
| 86 // How many pages on either side of the selected one we prerender. Currently 0 | 87 // How many pages on either side of the selected one we prerender. Currently 0 |
| 87 // to test impact of prerendering on UI jank for http://crbug.com/440224. Was 1. | 88 // to test impact of prerendering on UI jank for http://crbug.com/440224. Was 1. |
| 88 const int kPrerenderPages = 0; | 89 const int kPrerenderPages = 0; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 104 const int kFolderDroppingCircleRadius = 39; | 105 const int kFolderDroppingCircleRadius = 39; |
| 105 | 106 |
| 106 // Returns the size of a tile view excluding its padding. | 107 // Returns the size of a tile view excluding its padding. |
| 107 gfx::Size GetTileViewSize() { | 108 gfx::Size GetTileViewSize() { |
| 108 return switches::IsExperimentalAppListEnabled() | 109 return switches::IsExperimentalAppListEnabled() |
| 109 ? gfx::Size(kExperimentalPreferredTileWidth, | 110 ? gfx::Size(kExperimentalPreferredTileWidth, |
| 110 kExperimentalPreferredTileHeight) | 111 kExperimentalPreferredTileHeight) |
| 111 : gfx::Size(kPreferredTileWidth, kPreferredTileHeight); | 112 : gfx::Size(kPreferredTileWidth, kPreferredTileHeight); |
| 112 } | 113 } |
| 113 | 114 |
| 115 // Returns the padding around a tile view. |
| 116 gfx::Insets GetTilePadding() { |
| 117 if (!switches::IsExperimentalAppListEnabled()) |
| 118 return gfx::Insets(); |
| 119 |
| 120 return gfx::Insets( |
| 121 -kExperimentalTileLeftRightPadding, -kExperimentalTileTopPadding, |
| 122 -kExperimentalTileLeftRightPadding, -kExperimentalTileBottomPadding); |
| 123 } |
| 124 |
| 114 // RowMoveAnimationDelegate is used when moving an item into a different row. | 125 // RowMoveAnimationDelegate is used when moving an item into a different row. |
| 115 // Before running the animation, the item's layer is re-created and kept in | 126 // Before running the animation, the item's layer is re-created and kept in |
| 116 // the original position, then the item is moved to just before its target | 127 // the original position, then the item is moved to just before its target |
| 117 // position and opacity set to 0. When the animation runs, this delegate moves | 128 // position and opacity set to 0. When the animation runs, this delegate moves |
| 118 // the layer and fades it out while fading in the item at the same time. | 129 // the layer and fades it out while fading in the item at the same time. |
| 119 class RowMoveAnimationDelegate : public gfx::AnimationDelegate { | 130 class RowMoveAnimationDelegate : public gfx::AnimationDelegate { |
| 120 public: | 131 public: |
| 121 RowMoveAnimationDelegate(views::View* view, | 132 RowMoveAnimationDelegate(views::View* view, |
| 122 ui::Layer* layer, | 133 ui::Layer* layer, |
| 123 const gfx::Rect& layer_target) | 134 const gfx::Rect& layer_target) |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 view_model_.Clear(); | 411 view_model_.Clear(); |
| 401 RemoveAllChildViews(true); | 412 RemoveAllChildViews(true); |
| 402 } | 413 } |
| 403 | 414 |
| 404 void AppsGridView::SetLayout(int cols, int rows_per_page) { | 415 void AppsGridView::SetLayout(int cols, int rows_per_page) { |
| 405 cols_ = cols; | 416 cols_ = cols; |
| 406 rows_per_page_ = rows_per_page; | 417 rows_per_page_ = rows_per_page; |
| 407 | 418 |
| 408 if (switches::IsExperimentalAppListEnabled()) { | 419 if (switches::IsExperimentalAppListEnabled()) { |
| 409 SetBorder(views::Border::CreateEmptyBorder( | 420 SetBorder(views::Border::CreateEmptyBorder( |
| 410 0, kExperimentalWindowPadding, 0, kExperimentalWindowPadding)); | 421 0, kExperimentalAppsGridPadding, 0, kExperimentalAppsGridPadding)); |
| 411 } else { | 422 } else { |
| 412 SetBorder(views::Border::CreateEmptyBorder( | 423 SetBorder(views::Border::CreateEmptyBorder( |
| 413 0, kLeftRightPadding, kBottomPadding, kLeftRightPadding)); | 424 0, kLeftRightPadding, kBottomPadding, kLeftRightPadding)); |
| 414 } | 425 } |
| 415 } | 426 } |
| 416 | 427 |
| 417 // static | 428 // static |
| 418 gfx::Size AppsGridView::GetTotalTileSize() { | 429 gfx::Size AppsGridView::GetTotalTileSize() { |
| 419 gfx::Size size = GetTileViewSize(); | 430 gfx::Size size = GetTileViewSize(); |
| 420 if (switches::IsExperimentalAppListEnabled()) { | 431 if (switches::IsExperimentalAppListEnabled()) { |
| 421 size.Enlarge(2 * kExperimentalTileLeftRightPadding, | 432 size.Enlarge(2 * kExperimentalTileLeftRightPadding, |
| 422 2 * kExperimentalTileTopBottomPadding); | 433 kExperimentalTileBottomPadding); |
| 423 } | 434 } |
| 424 return size; | 435 return size; |
| 425 } | 436 } |
| 426 | 437 |
| 427 void AppsGridView::ResetForShowApps() { | 438 void AppsGridView::ResetForShowApps() { |
| 428 activated_folder_item_view_ = NULL; | 439 activated_folder_item_view_ = NULL; |
| 429 ClearDragState(); | 440 ClearDragState(); |
| 430 layer()->SetOpacity(1.0f); | 441 layer()->SetOpacity(1.0f); |
| 431 SetVisible(true); | 442 SetVisible(true); |
| 432 // Set all views to visible in case they weren't made visible again by an | 443 // Set all views to visible in case they weren't made visible again by an |
| (...skipping 1680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2113 (point.x() - bounds.x()) / total_tile_size.width(), 0, cols_ - 1); | 2124 (point.x() - bounds.x()) / total_tile_size.width(), 0, cols_ - 1); |
| 2114 int row = ClampToRange((point.y() - bounds.y()) / total_tile_size.height(), | 2125 int row = ClampToRange((point.y() - bounds.y()) / total_tile_size.height(), |
| 2115 0, | 2126 0, |
| 2116 rows_per_page_ - 1); | 2127 rows_per_page_ - 1); |
| 2117 return Index(pagination_model_.selected_page(), row * cols_ + col); | 2128 return Index(pagination_model_.selected_page(), row * cols_ + col); |
| 2118 } | 2129 } |
| 2119 | 2130 |
| 2120 gfx::Size AppsGridView::GetTileGridSize() const { | 2131 gfx::Size AppsGridView::GetTileGridSize() const { |
| 2121 gfx::Rect bounds = GetExpectedTileBounds(0, 0); | 2132 gfx::Rect bounds = GetExpectedTileBounds(0, 0); |
| 2122 bounds.Union(GetExpectedTileBounds(rows_per_page_ - 1, cols_ - 1)); | 2133 bounds.Union(GetExpectedTileBounds(rows_per_page_ - 1, cols_ - 1)); |
| 2123 if (switches::IsExperimentalAppListEnabled()) | 2134 bounds.Inset(GetTilePadding()); |
| 2124 bounds.Inset(-kExperimentalTileLeftRightPadding, | |
| 2125 -kExperimentalTileTopBottomPadding); | |
| 2126 return bounds.size(); | 2135 return bounds.size(); |
| 2127 } | 2136 } |
| 2128 | 2137 |
| 2129 gfx::Rect AppsGridView::GetExpectedTileBounds(int slot) const { | 2138 gfx::Rect AppsGridView::GetExpectedTileBounds(int slot) const { |
| 2130 return GetExpectedTileBounds(slot / cols_, slot % cols_); | 2139 return GetExpectedTileBounds(slot / cols_, slot % cols_); |
| 2131 } | 2140 } |
| 2132 | 2141 |
| 2133 gfx::Rect AppsGridView::GetExpectedTileBounds(int row, int col) const { | 2142 gfx::Rect AppsGridView::GetExpectedTileBounds(int row, int col) const { |
| 2134 gfx::Rect bounds(GetContentsBounds()); | 2143 gfx::Rect bounds(GetContentsBounds()); |
| 2135 gfx::Size total_tile_size = GetTotalTileSize(); | 2144 gfx::Size total_tile_size = GetTotalTileSize(); |
| 2136 gfx::Rect tile_bounds(gfx::Point(bounds.x() + col * total_tile_size.width(), | 2145 gfx::Rect tile_bounds(gfx::Point(bounds.x() + col * total_tile_size.width(), |
| 2137 bounds.y() + row * total_tile_size.height()), | 2146 bounds.y() + row * total_tile_size.height()), |
| 2138 total_tile_size); | 2147 total_tile_size); |
| 2139 tile_bounds.ClampToCenteredSize(GetTileViewSize()); | 2148 tile_bounds.Inset(-GetTilePadding()); |
| 2140 return tile_bounds; | 2149 return tile_bounds; |
| 2141 } | 2150 } |
| 2142 | 2151 |
| 2143 AppListItemView* AppsGridView::GetViewDisplayedAtSlotOnCurrentPage( | 2152 AppListItemView* AppsGridView::GetViewDisplayedAtSlotOnCurrentPage( |
| 2144 int slot) const { | 2153 int slot) const { |
| 2145 if (slot < 0) | 2154 if (slot < 0) |
| 2146 return NULL; | 2155 return NULL; |
| 2147 | 2156 |
| 2148 // Calculate the original bound of the tile at |index|. | 2157 // Calculate the original bound of the tile at |index|. |
| 2149 int row = slot / cols_; | 2158 int row = slot / cols_; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2160 | 2169 |
| 2161 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, | 2170 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, |
| 2162 bool is_target_folder) { | 2171 bool is_target_folder) { |
| 2163 AppListItemView* target_view = | 2172 AppListItemView* target_view = |
| 2164 GetViewDisplayedAtSlotOnCurrentPage(target_index.slot); | 2173 GetViewDisplayedAtSlotOnCurrentPage(target_index.slot); |
| 2165 if (target_view) | 2174 if (target_view) |
| 2166 target_view->SetAsAttemptedFolderTarget(is_target_folder); | 2175 target_view->SetAsAttemptedFolderTarget(is_target_folder); |
| 2167 } | 2176 } |
| 2168 | 2177 |
| 2169 } // namespace app_list | 2178 } // namespace app_list |
| OLD | NEW |