| 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 } | 159 } |
| 160 void AnimationCanceled(const gfx::Animation* animation) override { | 160 void AnimationCanceled(const gfx::Animation* animation) override { |
| 161 view_->layer()->SetOpacity(1.0f); | 161 view_->layer()->SetOpacity(1.0f); |
| 162 view_->SchedulePaint(); | 162 view_->SchedulePaint(); |
| 163 } | 163 } |
| 164 | 164 |
| 165 private: | 165 private: |
| 166 // The view that needs to be wrapped. Owned by views hierarchy. | 166 // The view that needs to be wrapped. Owned by views hierarchy. |
| 167 views::View* view_; | 167 views::View* view_; |
| 168 | 168 |
| 169 scoped_ptr<ui::Layer> layer_; | 169 std::unique_ptr<ui::Layer> layer_; |
| 170 const gfx::Rect layer_start_; | 170 const gfx::Rect layer_start_; |
| 171 const gfx::Rect layer_target_; | 171 const gfx::Rect layer_target_; |
| 172 | 172 |
| 173 DISALLOW_COPY_AND_ASSIGN(RowMoveAnimationDelegate); | 173 DISALLOW_COPY_AND_ASSIGN(RowMoveAnimationDelegate); |
| 174 }; | 174 }; |
| 175 | 175 |
| 176 // ItemRemoveAnimationDelegate is used to show animation for removing an item. | 176 // ItemRemoveAnimationDelegate is used to show animation for removing an item. |
| 177 // This happens when user drags an item into a folder. The dragged item will | 177 // This happens when user drags an item into a folder. The dragged item will |
| 178 // be removed from the original list after it is dropped into the folder. | 178 // be removed from the original list after it is dropped into the folder. |
| 179 class ItemRemoveAnimationDelegate : public gfx::AnimationDelegate { | 179 class ItemRemoveAnimationDelegate : public gfx::AnimationDelegate { |
| 180 public: | 180 public: |
| 181 explicit ItemRemoveAnimationDelegate(views::View* view) | 181 explicit ItemRemoveAnimationDelegate(views::View* view) |
| 182 : view_(view) { | 182 : view_(view) { |
| 183 } | 183 } |
| 184 | 184 |
| 185 ~ItemRemoveAnimationDelegate() override {} | 185 ~ItemRemoveAnimationDelegate() override {} |
| 186 | 186 |
| 187 // gfx::AnimationDelegate overrides: | 187 // gfx::AnimationDelegate overrides: |
| 188 void AnimationProgressed(const gfx::Animation* animation) override { | 188 void AnimationProgressed(const gfx::Animation* animation) override { |
| 189 view_->layer()->SetOpacity(1 - animation->GetCurrentValue()); | 189 view_->layer()->SetOpacity(1 - animation->GetCurrentValue()); |
| 190 view_->layer()->ScheduleDraw(); | 190 view_->layer()->ScheduleDraw(); |
| 191 } | 191 } |
| 192 | 192 |
| 193 private: | 193 private: |
| 194 scoped_ptr<views::View> view_; | 194 std::unique_ptr<views::View> view_; |
| 195 | 195 |
| 196 DISALLOW_COPY_AND_ASSIGN(ItemRemoveAnimationDelegate); | 196 DISALLOW_COPY_AND_ASSIGN(ItemRemoveAnimationDelegate); |
| 197 }; | 197 }; |
| 198 | 198 |
| 199 // ItemMoveAnimationDelegate observes when an item finishes animating when it is | 199 // ItemMoveAnimationDelegate observes when an item finishes animating when it is |
| 200 // not moving between rows. This is to ensure an item is repainted for the | 200 // not moving between rows. This is to ensure an item is repainted for the |
| 201 // "zoom out" case when releasing an item being dragged. | 201 // "zoom out" case when releasing an item being dragged. |
| 202 class ItemMoveAnimationDelegate : public gfx::AnimationDelegate { | 202 class ItemMoveAnimationDelegate : public gfx::AnimationDelegate { |
| 203 public: | 203 public: |
| 204 explicit ItemMoveAnimationDelegate(views::View* view) : view_(view) {} | 204 explicit ItemMoveAnimationDelegate(views::View* view) : view_(view) {} |
| (...skipping 1085 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1290 const int y_diff = target.y() - current.y(); | 1290 const int y_diff = target.y() - current.y(); |
| 1291 if (visible && y_diff && y_diff % GetTotalTileSize().height() == 0) { | 1291 if (visible && y_diff && y_diff % GetTotalTileSize().height() == 0) { |
| 1292 AnimationBetweenRows(view, | 1292 AnimationBetweenRows(view, |
| 1293 current_visible, | 1293 current_visible, |
| 1294 current, | 1294 current, |
| 1295 target_visible, | 1295 target_visible, |
| 1296 target); | 1296 target); |
| 1297 } else if (visible || bounds_animator_.IsAnimating(view)) { | 1297 } else if (visible || bounds_animator_.IsAnimating(view)) { |
| 1298 bounds_animator_.AnimateViewTo(view, target); | 1298 bounds_animator_.AnimateViewTo(view, target); |
| 1299 bounds_animator_.SetAnimationDelegate( | 1299 bounds_animator_.SetAnimationDelegate( |
| 1300 view, | 1300 view, std::unique_ptr<gfx::AnimationDelegate>( |
| 1301 scoped_ptr<gfx::AnimationDelegate>( | 1301 new ItemMoveAnimationDelegate(view))); |
| 1302 new ItemMoveAnimationDelegate(view))); | |
| 1303 } else { | 1302 } else { |
| 1304 view->SetBoundsRect(target); | 1303 view->SetBoundsRect(target); |
| 1305 } | 1304 } |
| 1306 } | 1305 } |
| 1307 } | 1306 } |
| 1308 | 1307 |
| 1309 void AppsGridView::AnimationBetweenRows(AppListItemView* view, | 1308 void AppsGridView::AnimationBetweenRows(AppListItemView* view, |
| 1310 bool animate_current, | 1309 bool animate_current, |
| 1311 const gfx::Rect& current, | 1310 const gfx::Rect& current, |
| 1312 bool animate_target, | 1311 bool animate_target, |
| 1313 const gfx::Rect& target) { | 1312 const gfx::Rect& target) { |
| 1314 // Determine page of |current| and |target|. -1 means in the left invisible | 1313 // Determine page of |current| and |target|. -1 means in the left invisible |
| 1315 // page, 0 is the center visible page and 1 means in the right invisible page. | 1314 // page, 0 is the center visible page and 1 means in the right invisible page. |
| 1316 const int current_page = current.x() < 0 ? -1 : | 1315 const int current_page = current.x() < 0 ? -1 : |
| 1317 current.x() >= width() ? 1 : 0; | 1316 current.x() >= width() ? 1 : 0; |
| 1318 const int target_page = target.x() < 0 ? -1 : | 1317 const int target_page = target.x() < 0 ? -1 : |
| 1319 target.x() >= width() ? 1 : 0; | 1318 target.x() >= width() ? 1 : 0; |
| 1320 | 1319 |
| 1321 const int dir = current_page < target_page || | 1320 const int dir = current_page < target_page || |
| 1322 (current_page == target_page && current.y() < target.y()) ? 1 : -1; | 1321 (current_page == target_page && current.y() < target.y()) ? 1 : -1; |
| 1323 | 1322 |
| 1324 scoped_ptr<ui::Layer> layer; | 1323 std::unique_ptr<ui::Layer> layer; |
| 1325 if (animate_current) { | 1324 if (animate_current) { |
| 1326 layer = view->RecreateLayer(); | 1325 layer = view->RecreateLayer(); |
| 1327 layer->SuppressPaint(); | 1326 layer->SuppressPaint(); |
| 1328 | 1327 |
| 1329 view->layer()->SetFillsBoundsOpaquely(false); | 1328 view->layer()->SetFillsBoundsOpaquely(false); |
| 1330 view->layer()->SetOpacity(0.f); | 1329 view->layer()->SetOpacity(0.f); |
| 1331 } | 1330 } |
| 1332 | 1331 |
| 1333 gfx::Size total_tile_size = GetTotalTileSize(); | 1332 gfx::Size total_tile_size = GetTotalTileSize(); |
| 1334 gfx::Rect current_out(current); | 1333 gfx::Rect current_out(current); |
| 1335 current_out.Offset(dir * total_tile_size.width(), 0); | 1334 current_out.Offset(dir * total_tile_size.width(), 0); |
| 1336 | 1335 |
| 1337 gfx::Rect target_in(target); | 1336 gfx::Rect target_in(target); |
| 1338 if (animate_target) | 1337 if (animate_target) |
| 1339 target_in.Offset(-dir * total_tile_size.width(), 0); | 1338 target_in.Offset(-dir * total_tile_size.width(), 0); |
| 1340 view->SetBoundsRect(target_in); | 1339 view->SetBoundsRect(target_in); |
| 1341 bounds_animator_.AnimateViewTo(view, target); | 1340 bounds_animator_.AnimateViewTo(view, target); |
| 1342 | 1341 |
| 1343 bounds_animator_.SetAnimationDelegate( | 1342 bounds_animator_.SetAnimationDelegate( |
| 1344 view, | 1343 view, |
| 1345 scoped_ptr<gfx::AnimationDelegate>( | 1344 std::unique_ptr<gfx::AnimationDelegate>( |
| 1346 new RowMoveAnimationDelegate(view, layer.release(), current_out))); | 1345 new RowMoveAnimationDelegate(view, layer.release(), current_out))); |
| 1347 } | 1346 } |
| 1348 | 1347 |
| 1349 void AppsGridView::ExtractDragLocation(const ui::LocatedEvent& event, | 1348 void AppsGridView::ExtractDragLocation(const ui::LocatedEvent& event, |
| 1350 gfx::Point* drag_point) { | 1349 gfx::Point* drag_point) { |
| 1351 // Use root location of |event| instead of location in |drag_view_|'s | 1350 // Use root location of |event| instead of location in |drag_view_|'s |
| 1352 // coordinates because |drag_view_| has a scale transform and location | 1351 // coordinates because |drag_view_| has a scale transform and location |
| 1353 // could have integer round error and causes jitter. | 1352 // could have integer round error and causes jitter. |
| 1354 *drag_point = event.root_location(); | 1353 *drag_point = event.root_location(); |
| 1355 | 1354 |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1807 } else { | 1806 } else { |
| 1808 LOG(ERROR) << "Folder no longer in item_list: " << folder_item_id; | 1807 LOG(ERROR) << "Folder no longer in item_list: " << folder_item_id; |
| 1809 } | 1808 } |
| 1810 } | 1809 } |
| 1811 | 1810 |
| 1812 // Fade out the drag_view_ and delete it when animation ends. | 1811 // Fade out the drag_view_ and delete it when animation ends. |
| 1813 int drag_view_index = view_model_.GetIndexOfView(drag_view_); | 1812 int drag_view_index = view_model_.GetIndexOfView(drag_view_); |
| 1814 view_model_.Remove(drag_view_index); | 1813 view_model_.Remove(drag_view_index); |
| 1815 bounds_animator_.AnimateViewTo(drag_view_, drag_view_->bounds()); | 1814 bounds_animator_.AnimateViewTo(drag_view_, drag_view_->bounds()); |
| 1816 bounds_animator_.SetAnimationDelegate( | 1815 bounds_animator_.SetAnimationDelegate( |
| 1817 drag_view_, | 1816 drag_view_, std::unique_ptr<gfx::AnimationDelegate>( |
| 1818 scoped_ptr<gfx::AnimationDelegate>( | 1817 new ItemRemoveAnimationDelegate(drag_view_))); |
| 1819 new ItemRemoveAnimationDelegate(drag_view_))); | |
| 1820 UpdatePaging(); | 1818 UpdatePaging(); |
| 1821 } | 1819 } |
| 1822 | 1820 |
| 1823 void AppsGridView::ReparentItemForReorder(AppListItemView* item_view, | 1821 void AppsGridView::ReparentItemForReorder(AppListItemView* item_view, |
| 1824 const Index& target) { | 1822 const Index& target) { |
| 1825 item_list_->RemoveObserver(this); | 1823 item_list_->RemoveObserver(this); |
| 1826 model_->RemoveObserver(this); | 1824 model_->RemoveObserver(this); |
| 1827 | 1825 |
| 1828 AppListItem* reparent_item = item_view->item(); | 1826 AppListItem* reparent_item = item_view->item(); |
| 1829 DCHECK(reparent_item->IsInFolder()); | 1827 DCHECK(reparent_item->IsInFolder()); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1922 | 1920 |
| 1923 RemoveLastItemFromReparentItemFolderIfNecessary(source_folder_id); | 1921 RemoveLastItemFromReparentItemFolderIfNecessary(source_folder_id); |
| 1924 | 1922 |
| 1925 item_list_->AddObserver(this); | 1923 item_list_->AddObserver(this); |
| 1926 | 1924 |
| 1927 // Fade out the drag_view_ and delete it when animation ends. | 1925 // Fade out the drag_view_ and delete it when animation ends. |
| 1928 int drag_view_index = view_model_.GetIndexOfView(drag_view_); | 1926 int drag_view_index = view_model_.GetIndexOfView(drag_view_); |
| 1929 view_model_.Remove(drag_view_index); | 1927 view_model_.Remove(drag_view_index); |
| 1930 bounds_animator_.AnimateViewTo(drag_view_, drag_view_->bounds()); | 1928 bounds_animator_.AnimateViewTo(drag_view_, drag_view_->bounds()); |
| 1931 bounds_animator_.SetAnimationDelegate( | 1929 bounds_animator_.SetAnimationDelegate( |
| 1932 drag_view_, | 1930 drag_view_, std::unique_ptr<gfx::AnimationDelegate>( |
| 1933 scoped_ptr<gfx::AnimationDelegate>( | 1931 new ItemRemoveAnimationDelegate(drag_view_))); |
| 1934 new ItemRemoveAnimationDelegate(drag_view_))); | |
| 1935 UpdatePaging(); | 1932 UpdatePaging(); |
| 1936 | 1933 |
| 1937 return true; | 1934 return true; |
| 1938 } | 1935 } |
| 1939 | 1936 |
| 1940 // After moving the re-parenting item out of the folder, if there is only 1 item | 1937 // After moving the re-parenting item out of the folder, if there is only 1 item |
| 1941 // left, remove the last item out of the folder, delete the folder and insert it | 1938 // left, remove the last item out of the folder, delete the folder and insert it |
| 1942 // to the data model at the same position. Make the same change to view_model_ | 1939 // to the data model at the same position. Make the same change to view_model_ |
| 1943 // accordingly. | 1940 // accordingly. |
| 1944 void AppsGridView::RemoveLastItemFromReparentItemFolderIfNecessary( | 1941 void AppsGridView::RemoveLastItemFromReparentItemFolderIfNecessary( |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2184 | 2181 |
| 2185 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, | 2182 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, |
| 2186 bool is_target_folder) { | 2183 bool is_target_folder) { |
| 2187 AppListItemView* target_view = | 2184 AppListItemView* target_view = |
| 2188 GetViewDisplayedAtSlotOnCurrentPage(target_index.slot); | 2185 GetViewDisplayedAtSlotOnCurrentPage(target_index.slot); |
| 2189 if (target_view) | 2186 if (target_view) |
| 2190 target_view->SetAsAttemptedFolderTarget(is_target_folder); | 2187 target_view->SetAsAttemptedFolderTarget(is_target_folder); |
| 2191 } | 2188 } |
| 2192 | 2189 |
| 2193 } // namespace app_list | 2190 } // namespace app_list |
| OLD | NEW |