Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(231)

Side by Side Diff: ui/app_list/views/apps_grid_view.cc

Issue 557673002: Split app list drop target into reorder and folder drop targets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fasdaj
Patch Set: address comments Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/app_list/views/apps_grid_view.h ('k') | ui/app_list/views/apps_grid_view_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 598 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 609
610 StartSettingUpSynchronousDrag(); 610 StartSettingUpSynchronousDrag();
611 if (!dragging_for_reparent_item_) 611 if (!dragging_for_reparent_item_)
612 StartDragAndDropHostDrag(point); 612 StartDragAndDropHostDrag(point);
613 } 613 }
614 614
615 if (drag_pointer_ != pointer) 615 if (drag_pointer_ != pointer)
616 return; 616 return;
617 617
618 last_drag_point_ = point; 618 last_drag_point_ = point;
619 const Index last_drop_target = drop_target_; 619 const Index last_reorder_drop_target = reorder_drop_target_;
620 const Index last_folder_drop_target = folder_drop_target_;
620 DropAttempt last_drop_attempt = drop_attempt_; 621 DropAttempt last_drop_attempt = drop_attempt_;
621 CalculateDropTarget(last_drag_point_, false); 622 CalculateDropTarget(last_drag_point_, false);
622 623
623 if (IsPointWithinDragBuffer(last_drag_point_)) 624 if (IsPointWithinDragBuffer(last_drag_point_))
624 MaybeStartPageFlipTimer(last_drag_point_); 625 MaybeStartPageFlipTimer(last_drag_point_);
625 else 626 else
626 StopPageFlipTimer(); 627 StopPageFlipTimer();
627 628
628 if (page_switcher_view_) { 629 if (page_switcher_view_) {
629 gfx::Point page_switcher_point(last_drag_point_); 630 gfx::Point page_switcher_point(last_drag_point_);
630 views::View::ConvertPointToTarget( 631 views::View::ConvertPointToTarget(
631 this, page_switcher_view_, &page_switcher_point); 632 this, page_switcher_view_, &page_switcher_point);
632 page_switcher_view_->UpdateUIForDragPoint(page_switcher_point); 633 page_switcher_view_->UpdateUIForDragPoint(page_switcher_point);
633 } 634 }
634 635
635 if (!EnableFolderDragDropUI()) { 636 if (!EnableFolderDragDropUI()) {
636 if (last_drop_target != drop_target_) 637 if (last_reorder_drop_target != reorder_drop_target_)
637 AnimateToIdealBounds(); 638 AnimateToIdealBounds();
638 drag_view_->SetPosition(drag_view_start_ + drag_vector); 639 drag_view_->SetPosition(drag_view_start_ + drag_vector);
639 return; 640 return;
640 } 641 }
641 642
642 // Update drag with folder UI enabled. 643 // Update drag with folder UI enabled.
643 if (last_drop_target != drop_target_ || 644 if (last_folder_drop_target != folder_drop_target_ ||
645 last_reorder_drop_target != reorder_drop_target_ ||
644 last_drop_attempt != drop_attempt_) { 646 last_drop_attempt != drop_attempt_) {
645 if (drop_attempt_ == DROP_FOR_REORDER) { 647 if (drop_attempt_ == DROP_FOR_REORDER) {
646 folder_dropping_timer_.Stop(); 648 folder_dropping_timer_.Stop();
647 reorder_timer_.Start(FROM_HERE, 649 reorder_timer_.Start(FROM_HERE,
648 base::TimeDelta::FromMilliseconds(kReorderDelay), 650 base::TimeDelta::FromMilliseconds(kReorderDelay),
649 this, &AppsGridView::OnReorderTimer); 651 this, &AppsGridView::OnReorderTimer);
650 } else if (drop_attempt_ == DROP_FOR_FOLDER) { 652 } else if (drop_attempt_ == DROP_FOR_FOLDER) {
651 reorder_timer_.Stop(); 653 reorder_timer_.Stop();
652 folder_dropping_timer_.Start(FROM_HERE, 654 folder_dropping_timer_.Start(FROM_HERE,
653 base::TimeDelta::FromMilliseconds(kFolderDroppingDelay), 655 base::TimeDelta::FromMilliseconds(kFolderDroppingDelay),
654 this, &AppsGridView::OnFolderDroppingTimer); 656 this, &AppsGridView::OnFolderDroppingTimer);
655 } 657 }
656 658
657 // Reset the previous drop target. 659 // Reset the previous drop target.
658 SetAsFolderDroppingTarget(last_drop_target, false); 660 SetAsFolderDroppingTarget(last_folder_drop_target, false);
659 } 661 }
660 662
661 drag_view_->SetPosition(drag_view_start_ + drag_vector); 663 drag_view_->SetPosition(drag_view_start_ + drag_vector);
662 } 664 }
663 665
664 void AppsGridView::EndDrag(bool cancel) { 666 void AppsGridView::EndDrag(bool cancel) {
665 // EndDrag was called before if |drag_view_| is NULL. 667 // EndDrag was called before if |drag_view_| is NULL.
666 if (!drag_view_) 668 if (!drag_view_)
667 return; 669 return;
668 670
(...skipping 22 matching lines...) Expand all
691 // An EndDrag can be received during a reparent via a model change. This 693 // An EndDrag can be received during a reparent via a model change. This
692 // is always a cancel and needs to be forwarded to the folder. 694 // is always a cancel and needs to be forwarded to the folder.
693 DCHECK(cancel); 695 DCHECK(cancel);
694 delegate_->CancelDragInActiveFolder(); 696 delegate_->CancelDragInActiveFolder();
695 return; 697 return;
696 } 698 }
697 699
698 if (!cancel && dragging()) { 700 if (!cancel && dragging()) {
699 // Regular drag ending path, ie, not for reparenting. 701 // Regular drag ending path, ie, not for reparenting.
700 CalculateDropTarget(last_drag_point_, true); 702 CalculateDropTarget(last_drag_point_, true);
701 if (IsValidIndex(drop_target_)) { 703 if (EnableFolderDragDropUI() && drop_attempt_ == DROP_FOR_FOLDER &&
702 if (!EnableFolderDragDropUI()) { 704 IsValidIndex(folder_drop_target_)) {
703 MoveItemInModel(drag_view_, drop_target_); 705 MoveItemToFolder(drag_view_, folder_drop_target_);
704 } else { 706 } else if (IsValidIndex(reorder_drop_target_)) {
705 if (drop_attempt_ == DROP_FOR_REORDER) 707 MoveItemInModel(drag_view_, reorder_drop_target_);
706 MoveItemInModel(drag_view_, drop_target_);
707 else if (drop_attempt_ == DROP_FOR_FOLDER)
708 MoveItemToFolder(drag_view_, drop_target_);
709 }
710 } 708 }
711 } 709 }
712 } 710 }
713 711
714 if (drag_and_drop_host_) { 712 if (drag_and_drop_host_) {
715 // If we had a drag and drop proxy icon, we delete it and make the real 713 // If we had a drag and drop proxy icon, we delete it and make the real
716 // item visible again. 714 // item visible again.
717 drag_and_drop_host_->DestroyDragIconProxy(); 715 drag_and_drop_host_->DestroyDragIconProxy();
718 if (landed_in_drag_and_drop_host) { 716 if (landed_in_drag_and_drop_host) {
719 // Move the item directly to the target location, avoiding the "zip back" 717 // Move the item directly to the target location, avoiding the "zip back"
720 // animation if the user was pinning it to the shelf. 718 // animation if the user was pinning it to the shelf.
721 int i = drop_target_.slot; 719 int i = reorder_drop_target_.slot;
722 gfx::Rect bounds = view_model_.ideal_bounds(i); 720 gfx::Rect bounds = view_model_.ideal_bounds(i);
723 drag_view_->SetBoundsRect(bounds); 721 drag_view_->SetBoundsRect(bounds);
724 } 722 }
725 // Fade in slowly if it landed in the shelf. 723 // Fade in slowly if it landed in the shelf.
726 SetViewHidden(drag_view_, 724 SetViewHidden(drag_view_,
727 false /* show */, 725 false /* show */,
728 !landed_in_drag_and_drop_host /* animate */); 726 !landed_in_drag_and_drop_host /* animate */);
729 } 727 }
730 728
731 // The drag can be ended after the synchronous drag is created but before it 729 // The drag can be ended after the synchronous drag is created but before it
732 // is Run(). 730 // is Run().
733 CleanUpSynchronousDrag(); 731 CleanUpSynchronousDrag();
734 732
735 SetAsFolderDroppingTarget(drop_target_, false); 733 SetAsFolderDroppingTarget(folder_drop_target_, false);
736 ClearDragState(); 734 ClearDragState();
737 AnimateToIdealBounds(); 735 AnimateToIdealBounds();
738 736
739 StopPageFlipTimer(); 737 StopPageFlipTimer();
740 738
741 // If user releases mouse inside a folder's grid view, burst the folder 739 // If user releases mouse inside a folder's grid view, burst the folder
742 // container ink bubble. 740 // container ink bubble.
743 if (folder_delegate_ && !IsDraggingForReparentInHiddenGridView()) 741 if (folder_delegate_ && !IsDraggingForReparentInHiddenGridView())
744 folder_delegate_->UpdateFolderViewBackground(false); 742 folder_delegate_->UpdateFolderViewBackground(false);
745 } 743 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 UpdateDrag(pointer, drag_point); 824 UpdateDrag(pointer, drag_point);
827 } 825 }
828 826
829 bool AppsGridView::IsDraggedView(const views::View* view) const { 827 bool AppsGridView::IsDraggedView(const views::View* view) const {
830 return drag_view_ == view; 828 return drag_view_ == view;
831 } 829 }
832 830
833 void AppsGridView::ClearDragState() { 831 void AppsGridView::ClearDragState() {
834 drop_attempt_ = DROP_FOR_NONE; 832 drop_attempt_ = DROP_FOR_NONE;
835 drag_pointer_ = NONE; 833 drag_pointer_ = NONE;
836 drop_target_ = Index(); 834 reorder_drop_target_ = Index();
835 folder_drop_target_ = Index();
837 drag_start_grid_view_ = gfx::Point(); 836 drag_start_grid_view_ = gfx::Point();
838 drag_start_page_ = -1; 837 drag_start_page_ = -1;
839 drag_view_offset_ = gfx::Point(); 838 drag_view_offset_ = gfx::Point();
840 839
841 if (drag_view_) { 840 if (drag_view_) {
842 drag_view_->OnDragEnded(); 841 drag_view_->OnDragEnded();
843 if (IsDraggingForReparentInRootLevelGridView()) { 842 if (IsDraggingForReparentInRootLevelGridView()) {
844 const int drag_view_index = view_model_.GetIndexOfView(drag_view_); 843 const int drag_view_index = view_model_.GetIndexOfView(drag_view_);
845 CHECK_EQ(view_model_.view_size() - 1, drag_view_index); 844 CHECK_EQ(view_model_.view_size() - 1, drag_view_index);
846 DeleteItemViewAtIndex(drag_view_index); 845 DeleteItemViewAtIndex(drag_view_index);
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 int slot_index = 0; 1179 int slot_index = 0;
1181 for (int i = 0; i < total_views; ++i) { 1180 for (int i = 0; i < total_views; ++i) {
1182 if (i < view_model_.view_size() && view_model_.view_at(i) == drag_view_) { 1181 if (i < view_model_.view_size() && view_model_.view_at(i) == drag_view_) {
1183 if (EnableFolderDragDropUI() && drop_attempt_ == DROP_FOR_FOLDER) 1182 if (EnableFolderDragDropUI() && drop_attempt_ == DROP_FOR_FOLDER)
1184 ++slot_index; 1183 ++slot_index;
1185 continue; 1184 continue;
1186 } 1185 }
1187 1186
1188 Index view_index = GetIndexFromModelIndex(slot_index); 1187 Index view_index = GetIndexFromModelIndex(slot_index);
1189 1188
1190 if (drop_target_ == view_index) { 1189 // Leaves a blank space in the grid for the current reorder drop target.
1191 if (EnableFolderDragDropUI() && drop_attempt_ == DROP_FOR_FOLDER) { 1190 if (reorder_drop_target_ == view_index &&
1192 view_index = GetIndexFromModelIndex(slot_index); 1191 drop_attempt_ == DROP_FOR_REORDER) {
1193 } else if (!EnableFolderDragDropUI() || 1192 ++slot_index;
1194 drop_attempt_ == DROP_FOR_REORDER) { 1193 view_index = GetIndexFromModelIndex(slot_index);
1195 ++slot_index;
1196 view_index = GetIndexFromModelIndex(slot_index);
1197 }
1198 } 1194 }
1199 1195
1200 // Decide the x or y offset for current item. 1196 // Decide the x or y offset for current item.
1201 int x_offset = 0; 1197 int x_offset = 0;
1202 int y_offset = 0; 1198 int y_offset = 0;
1203 1199
1204 if (pagination_controller_->scroll_axis() == 1200 if (pagination_controller_->scroll_axis() ==
1205 PaginationController::SCROLL_AXIS_HORIZONTAL) { 1201 PaginationController::SCROLL_AXIS_HORIZONTAL) {
1206 if (view_index.page < current_page) 1202 if (view_index.page < current_page)
1207 x_offset = -page_width; 1203 x_offset = -page_width;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1345 #endif 1341 #endif
1346 } 1342 }
1347 1343
1348 void AppsGridView::CalculateDropTarget(const gfx::Point& drag_point, 1344 void AppsGridView::CalculateDropTarget(const gfx::Point& drag_point,
1349 bool use_page_button_hovering) { 1345 bool use_page_button_hovering) {
1350 if (EnableFolderDragDropUI()) { 1346 if (EnableFolderDragDropUI()) {
1351 CalculateDropTargetWithFolderEnabled(drag_point, use_page_button_hovering); 1347 CalculateDropTargetWithFolderEnabled(drag_point, use_page_button_hovering);
1352 return; 1348 return;
1353 } 1349 }
1354 1350
1351 drop_attempt_ = DROP_FOR_REORDER;
1352
1355 int current_page = pagination_model_.selected_page(); 1353 int current_page = pagination_model_.selected_page();
1356 gfx::Point point(drag_point); 1354 gfx::Point point(drag_point);
1357 if (!IsPointWithinDragBuffer(drag_point)) { 1355 if (!IsPointWithinDragBuffer(drag_point)) {
1358 point = drag_start_grid_view_; 1356 point = drag_start_grid_view_;
1359 current_page = drag_start_page_; 1357 current_page = drag_start_page_;
1360 } 1358 }
1361 1359
1362 if (use_page_button_hovering && page_switcher_view_ && 1360 if (use_page_button_hovering && page_switcher_view_ &&
1363 page_switcher_view_->bounds().Contains(point)) { 1361 page_switcher_view_->bounds().Contains(point)) {
1364 gfx::Point page_switcher_point(point); 1362 gfx::Point page_switcher_point(point);
1365 views::View::ConvertPointToTarget(this, page_switcher_view_, 1363 views::View::ConvertPointToTarget(this, page_switcher_view_,
1366 &page_switcher_point); 1364 &page_switcher_point);
1367 int page = page_switcher_view_->GetPageForPoint(page_switcher_point); 1365 int page = page_switcher_view_->GetPageForPoint(page_switcher_point);
1368 if (pagination_model_.is_valid_page(page)) { 1366 if (pagination_model_.is_valid_page(page)) {
1369 drop_target_.page = page; 1367 reorder_drop_target_.page = page;
1370 drop_target_.slot = tiles_per_page() - 1; 1368 reorder_drop_target_.slot = tiles_per_page() - 1;
1371 } 1369 }
1372 } else { 1370 } else {
1373 gfx::Rect bounds(GetContentsBounds()); 1371 gfx::Rect bounds(GetContentsBounds());
1374 const int drop_row = (point.y() - bounds.y()) / kPreferredTileHeight; 1372 const int drop_row = (point.y() - bounds.y()) / kPreferredTileHeight;
1375 const int drop_col = std::min(cols_ - 1, 1373 const int drop_col = std::min(cols_ - 1,
1376 (point.x() - bounds.x()) / kPreferredTileWidth); 1374 (point.x() - bounds.x()) / kPreferredTileWidth);
1377 1375
1378 drop_target_.page = current_page; 1376 reorder_drop_target_.page = current_page;
1379 drop_target_.slot = std::max(0, std::min( 1377 reorder_drop_target_.slot = std::max(
1380 tiles_per_page() - 1, 1378 0, std::min(tiles_per_page() - 1, drop_row * cols_ + drop_col));
1381 drop_row * cols_ + drop_col));
1382 } 1379 }
1383 1380
1384 // Limits to the last possible slot on last page. 1381 // Limits to the last possible slot on last page.
1385 if (drop_target_.page == pagination_model_.total_pages() - 1) { 1382 if (reorder_drop_target_.page == pagination_model_.total_pages() - 1) {
1386 drop_target_.slot = std::min( 1383 reorder_drop_target_.slot =
1387 (view_model_.view_size() - 1) % tiles_per_page(), 1384 std::min((view_model_.view_size() - 1) % tiles_per_page(),
1388 drop_target_.slot); 1385 reorder_drop_target_.slot);
1389 } 1386 }
1390 } 1387 }
1391 1388
1392 1389
1393 void AppsGridView::CalculateDropTargetWithFolderEnabled( 1390 void AppsGridView::CalculateDropTargetWithFolderEnabled(
1394 const gfx::Point& drag_point, 1391 const gfx::Point& drag_point,
1395 bool use_page_button_hovering) { 1392 bool use_page_button_hovering) {
1396 gfx::Point point(drag_point); 1393 gfx::Point point(drag_point);
1397 if (!IsPointWithinDragBuffer(drag_point)) { 1394 if (!IsPointWithinDragBuffer(drag_point)) {
1398 point = drag_start_grid_view_; 1395 point = drag_start_grid_view_;
1399 } 1396 }
1400 1397
1401 if (use_page_button_hovering && page_switcher_view_ && 1398 if (use_page_button_hovering && page_switcher_view_ &&
1402 page_switcher_view_->bounds().Contains(point)) { 1399 page_switcher_view_->bounds().Contains(point)) {
1403 gfx::Point page_switcher_point(point); 1400 gfx::Point page_switcher_point(point);
1404 views::View::ConvertPointToTarget(this, page_switcher_view_, 1401 views::View::ConvertPointToTarget(this, page_switcher_view_,
1405 &page_switcher_point); 1402 &page_switcher_point);
1406 int page = page_switcher_view_->GetPageForPoint(page_switcher_point); 1403 int page = page_switcher_view_->GetPageForPoint(page_switcher_point);
1407 if (pagination_model_.is_valid_page(page)) 1404 if (pagination_model_.is_valid_page(page))
1408 drop_attempt_ = DROP_FOR_NONE; 1405 drop_attempt_ = DROP_FOR_NONE;
1409 } else { 1406 } else {
1410 DCHECK(drag_view_); 1407 DCHECK(drag_view_);
1411 // Try to find the nearest target for folder dropping or re-ordering. 1408 // Try to find the nearest target for folder dropping or re-ordering.
1412 drop_target_ = GetNearestTileForDragView(); 1409 CalculateNearestTileForDragView();
1413 } 1410 }
1414 } 1411 }
1415 1412
1416 void AppsGridView::OnReorderTimer() { 1413 void AppsGridView::OnReorderTimer() {
1417 if (drop_attempt_ == DROP_FOR_REORDER) 1414 if (drop_attempt_ == DROP_FOR_REORDER)
1418 AnimateToIdealBounds(); 1415 AnimateToIdealBounds();
1419 } 1416 }
1420 1417
1421 void AppsGridView::OnFolderItemReparentTimer() { 1418 void AppsGridView::OnFolderItemReparentTimer() {
1422 DCHECK(folder_delegate_); 1419 DCHECK(folder_delegate_);
1423 if (drag_out_of_folder_container_ && drag_view_) { 1420 if (drag_out_of_folder_container_ && drag_view_) {
1424 folder_delegate_->ReparentItem(drag_view_, last_drag_point_); 1421 folder_delegate_->ReparentItem(drag_view_, last_drag_point_);
1425 1422
1426 // Set the flag in the folder's grid view. 1423 // Set the flag in the folder's grid view.
1427 dragging_for_reparent_item_ = true; 1424 dragging_for_reparent_item_ = true;
1428 1425
1429 // Do not observe any data change since it is going to be hidden. 1426 // Do not observe any data change since it is going to be hidden.
1430 item_list_->RemoveObserver(this); 1427 item_list_->RemoveObserver(this);
1431 item_list_ = NULL; 1428 item_list_ = NULL;
1432 } 1429 }
1433 } 1430 }
1434 1431
1435 void AppsGridView::OnFolderDroppingTimer() { 1432 void AppsGridView::OnFolderDroppingTimer() {
1436 if (drop_attempt_ == DROP_FOR_FOLDER) 1433 if (drop_attempt_ == DROP_FOR_FOLDER)
1437 SetAsFolderDroppingTarget(drop_target_, true); 1434 SetAsFolderDroppingTarget(folder_drop_target_, true);
1438 } 1435 }
1439 1436
1440 void AppsGridView::UpdateDragStateInsideFolder(Pointer pointer, 1437 void AppsGridView::UpdateDragStateInsideFolder(Pointer pointer,
1441 const gfx::Point& drag_point) { 1438 const gfx::Point& drag_point) {
1442 if (IsUnderOEMFolder()) 1439 if (IsUnderOEMFolder())
1443 return; 1440 return;
1444 1441
1445 if (IsDraggingForReparentInHiddenGridView()) { 1442 if (IsDraggingForReparentInHiddenGridView()) {
1446 // Dispatch drag event to root level grid view for re-parenting folder 1443 // Dispatch drag event to root level grid view for re-parenting folder
1447 // folder item purpose. 1444 // folder item purpose.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1510 bool events_forwarded_to_drag_drop_host, 1507 bool events_forwarded_to_drag_drop_host,
1511 bool cancel_drag) { 1508 bool cancel_drag) {
1512 // EndDrag was called before if |drag_view_| is NULL. 1509 // EndDrag was called before if |drag_view_| is NULL.
1513 if (!drag_view_) 1510 if (!drag_view_)
1514 return; 1511 return;
1515 1512
1516 DCHECK(IsDraggingForReparentInRootLevelGridView()); 1513 DCHECK(IsDraggingForReparentInRootLevelGridView());
1517 bool cancel_reparent = cancel_drag || drop_attempt_ == DROP_FOR_NONE; 1514 bool cancel_reparent = cancel_drag || drop_attempt_ == DROP_FOR_NONE;
1518 if (!events_forwarded_to_drag_drop_host && !cancel_reparent) { 1515 if (!events_forwarded_to_drag_drop_host && !cancel_reparent) {
1519 CalculateDropTarget(last_drag_point_, true); 1516 CalculateDropTarget(last_drag_point_, true);
1520 if (IsValidIndex(drop_target_)) { 1517 if (drop_attempt_ == DROP_FOR_REORDER &&
1521 if (drop_attempt_ == DROP_FOR_REORDER) { 1518 IsValidIndex(reorder_drop_target_)) {
1522 ReparentItemForReorder(drag_view_, drop_target_); 1519 ReparentItemForReorder(drag_view_, reorder_drop_target_);
1523 } else if (drop_attempt_ == DROP_FOR_FOLDER) { 1520 } else if (drop_attempt_ == DROP_FOR_FOLDER &&
1524 ReparentItemToAnotherFolder(drag_view_, drop_target_); 1521 IsValidIndex(folder_drop_target_)) {
1525 } 1522 ReparentItemToAnotherFolder(drag_view_, folder_drop_target_);
1526 } 1523 }
1527 SetViewHidden(drag_view_, false /* show */, true /* no animate */); 1524 SetViewHidden(drag_view_, false /* show */, true /* no animate */);
1528 } 1525 }
1529 1526
1530 // The drag can be ended after the synchronous drag is created but before it 1527 // The drag can be ended after the synchronous drag is created but before it
1531 // is Run(). 1528 // is Run().
1532 CleanUpSynchronousDrag(); 1529 CleanUpSynchronousDrag();
1533 1530
1534 SetAsFolderDroppingTarget(drop_target_, false); 1531 SetAsFolderDroppingTarget(folder_drop_target_, false);
1535 if (cancel_reparent) { 1532 if (cancel_reparent) {
1536 CancelFolderItemReparent(drag_view_); 1533 CancelFolderItemReparent(drag_view_);
1537 } else { 1534 } else {
1538 // By setting |drag_view_| to NULL here, we prevent ClearDragState() from 1535 // By setting |drag_view_| to NULL here, we prevent ClearDragState() from
1539 // cleaning up the newly created AppListItemView, effectively claiming 1536 // cleaning up the newly created AppListItemView, effectively claiming
1540 // ownership of the newly created drag view. 1537 // ownership of the newly created drag view.
1541 drag_view_->OnDragEnded(); 1538 drag_view_->OnDragEnded();
1542 drag_view_ = NULL; 1539 drag_view_ = NULL;
1543 } 1540 }
1544 ClearDragState(); 1541 ClearDragState();
1545 AnimateToIdealBounds(); 1542 AnimateToIdealBounds();
1546 1543
1547 StopPageFlipTimer(); 1544 StopPageFlipTimer();
1548 } 1545 }
1549 1546
1550 void AppsGridView::EndDragForReparentInHiddenFolderGridView() { 1547 void AppsGridView::EndDragForReparentInHiddenFolderGridView() {
1551 if (drag_and_drop_host_) { 1548 if (drag_and_drop_host_) {
1552 // If we had a drag and drop proxy icon, we delete it and make the real 1549 // If we had a drag and drop proxy icon, we delete it and make the real
1553 // item visible again. 1550 // item visible again.
1554 drag_and_drop_host_->DestroyDragIconProxy(); 1551 drag_and_drop_host_->DestroyDragIconProxy();
1555 } 1552 }
1556 1553
1557 // The drag can be ended after the synchronous drag is created but before it 1554 // The drag can be ended after the synchronous drag is created but before it
1558 // is Run(). 1555 // is Run().
1559 CleanUpSynchronousDrag(); 1556 CleanUpSynchronousDrag();
1560 1557
1561 SetAsFolderDroppingTarget(drop_target_, false); 1558 SetAsFolderDroppingTarget(folder_drop_target_, false);
1562 ClearDragState(); 1559 ClearDragState();
1563 } 1560 }
1564 1561
1565 void AppsGridView::OnFolderItemRemoved() { 1562 void AppsGridView::OnFolderItemRemoved() {
1566 DCHECK(folder_delegate_); 1563 DCHECK(folder_delegate_);
1567 item_list_ = NULL; 1564 item_list_ = NULL;
1568 } 1565 }
1569 1566
1570 void AppsGridView::StartDragAndDropHostDrag(const gfx::Point& grid_location) { 1567 void AppsGridView::StartDragAndDropHostDrag(const gfx::Point& grid_location) {
1571 // When a drag and drop host is given, the item can be dragged out of the app 1568 // When a drag and drop host is given, the item can be dragged out of the app
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
2040 2037
2041 void AppsGridView::OnImplicitAnimationsCompleted() { 2038 void AppsGridView::OnImplicitAnimationsCompleted() {
2042 if (layer()->opacity() == 0.0f) 2039 if (layer()->opacity() == 0.0f)
2043 SetVisible(false); 2040 SetVisible(false);
2044 } 2041 }
2045 2042
2046 bool AppsGridView::EnableFolderDragDropUI() { 2043 bool AppsGridView::EnableFolderDragDropUI() {
2047 // Enable drag and drop folder UI only if it is at the app list root level 2044 // Enable drag and drop folder UI only if it is at the app list root level
2048 // and the switch is on and the target folder can still accept new items. 2045 // and the switch is on and the target folder can still accept new items.
2049 return model_->folders_enabled() && !folder_delegate_ && 2046 return model_->folders_enabled() && !folder_delegate_ &&
2050 CanDropIntoTarget(drop_target_); 2047 CanDropIntoTarget(folder_drop_target_);
2051 } 2048 }
2052 2049
2053 bool AppsGridView::CanDropIntoTarget(const Index& drop_target) { 2050 bool AppsGridView::CanDropIntoTarget(const Index& drop_target) {
2054 views::View* target_view = GetViewAtSlotOnCurrentPage(drop_target.slot); 2051 views::View* target_view = GetViewAtSlotOnCurrentPage(drop_target.slot);
2055 if (!target_view) 2052 if (!target_view)
2056 return true; 2053 return true;
2057 2054
2058 AppListItem* target_item = 2055 AppListItem* target_item =
2059 static_cast<AppListItemView*>(target_view)->item(); 2056 static_cast<AppListItemView*>(target_view)->item();
2060 // Items can be dropped into non-folders (which have no children) or folders 2057 // Items can be dropped into non-folders (which have no children) or folders
2061 // that have fewer than the max allowed items. 2058 // that have fewer than the max allowed items.
2062 // OEM folder does not allow to drag/drop other items in it. 2059 // OEM folder does not allow to drag/drop other items in it.
2063 return target_item->ChildItemCount() < kMaxFolderItems && 2060 return target_item->ChildItemCount() < kMaxFolderItems &&
2064 !IsOEMFolderItem(target_item); 2061 !IsOEMFolderItem(target_item);
2065 } 2062 }
2066 2063
2067 // TODO(jennyz): Optimize the calculation for finding nearest tile. 2064 // TODO(jennyz): Optimize the calculation for finding nearest tile.
2068 AppsGridView::Index AppsGridView::GetNearestTileForDragView() { 2065 void AppsGridView::CalculateNearestTileForDragView() {
2069 Index nearest_tile; 2066 Index nearest_tile;
2070 nearest_tile.page = -1; 2067 nearest_tile.page = -1;
2071 nearest_tile.slot = -1; 2068 nearest_tile.slot = -1;
2072 int d_min = -1; 2069 int d_min = -1;
2073 2070
2074 // Calculate the top left tile |drag_view| intersects. 2071 // Calculate the top left tile |drag_view| intersects.
2075 gfx::Point pt = drag_view_->bounds().origin(); 2072 gfx::Point pt = drag_view_->bounds().origin();
2076 CalculateNearestTileForVertex(pt, &nearest_tile, &d_min); 2073 CalculateNearestTileForVertex(pt, &nearest_tile, &d_min);
2077 2074
2078 // Calculate the top right tile |drag_view| intersects. 2075 // Calculate the top right tile |drag_view| intersects.
(...skipping 10 matching lines...) Expand all
2089 2086
2090 const int d_folder_dropping = 2087 const int d_folder_dropping =
2091 kFolderDroppingCircleRadius + kGridIconDimension / 2; 2088 kFolderDroppingCircleRadius + kGridIconDimension / 2;
2092 const int d_reorder = kReorderDroppingCircleRadius + kGridIconDimension / 2; 2089 const int d_reorder = kReorderDroppingCircleRadius + kGridIconDimension / 2;
2093 2090
2094 // If user drags an item across pages to the last page, and targets it 2091 // If user drags an item across pages to the last page, and targets it
2095 // to the last empty slot on it, push the last item for re-ordering. 2092 // to the last empty slot on it, push the last item for re-ordering.
2096 if (IsLastPossibleDropTarget(nearest_tile) && d_min < d_reorder) { 2093 if (IsLastPossibleDropTarget(nearest_tile) && d_min < d_reorder) {
2097 drop_attempt_ = DROP_FOR_REORDER; 2094 drop_attempt_ = DROP_FOR_REORDER;
2098 nearest_tile.slot = nearest_tile.slot - 1; 2095 nearest_tile.slot = nearest_tile.slot - 1;
2099 return nearest_tile; 2096 reorder_drop_target_ = nearest_tile;
2097 return;
2100 } 2098 }
2101 2099
2102 if (IsValidIndex(nearest_tile)) { 2100 if (IsValidIndex(nearest_tile)) {
2103 if (d_min < d_folder_dropping) { 2101 if (d_min < d_folder_dropping) {
2104 views::View* target_view = GetViewAtSlotOnCurrentPage(nearest_tile.slot); 2102 views::View* target_view = GetViewAtSlotOnCurrentPage(nearest_tile.slot);
2105 if (target_view && 2103 if (target_view &&
2106 !IsFolderItem(static_cast<AppListItemView*>(drag_view_)->item())) { 2104 !IsFolderItem(static_cast<AppListItemView*>(drag_view_)->item())) {
2107 // If a non-folder item is dragged to the target slot with an item 2105 // If a non-folder item is dragged to the target slot with an item
2108 // sitting on it, attempt to drop the dragged item into the folder 2106 // sitting on it, attempt to drop the dragged item into the folder
2109 // containing the item on nearest_tile. 2107 // containing the item on nearest_tile.
2110 drop_attempt_ = DROP_FOR_FOLDER; 2108 drop_attempt_ = DROP_FOR_FOLDER;
2111 return nearest_tile; 2109 folder_drop_target_ = nearest_tile;
2110 return;
2112 } else { 2111 } else {
2113 // If the target slot is blank, or the dragged item is a folder, attempt 2112 // If the target slot is blank, or the dragged item is a folder, attempt
2114 // to re-order. 2113 // to re-order.
2115 drop_attempt_ = DROP_FOR_REORDER; 2114 drop_attempt_ = DROP_FOR_REORDER;
2116 return nearest_tile; 2115 reorder_drop_target_ = nearest_tile;
2116 return;
2117 } 2117 }
2118 } else if (d_min < d_reorder) { 2118 } else if (d_min < d_reorder) {
2119 // Entering the re-order circle of the slot. 2119 // Entering the re-order circle of the slot.
2120 drop_attempt_ = DROP_FOR_REORDER; 2120 drop_attempt_ = DROP_FOR_REORDER;
2121 return nearest_tile; 2121 reorder_drop_target_ = nearest_tile;
2122 return;
2122 } 2123 }
2123 } 2124 }
2124 2125
2125 // If |drag_view| is not entering the re-order or fold dropping region of 2126 // If |drag_view| is not entering the re-order or folder dropping region of
2126 // any items, cancel any previous re-order or folder dropping timer, and 2127 // any items, cancel any previous re-order or folder dropping timer.
2127 // return itself.
2128 drop_attempt_ = DROP_FOR_NONE; 2128 drop_attempt_ = DROP_FOR_NONE;
2129 reorder_timer_.Stop(); 2129 reorder_timer_.Stop();
2130 folder_dropping_timer_.Stop(); 2130 folder_dropping_timer_.Stop();
2131 2131
2132 // When dragging for reparent a folder item, it should go back to its parent 2132 // When dragging for reparent a folder item, it should go back to its parent
2133 // folder item if there is no drop target. 2133 // folder item if there is no drop target.
2134 if (IsDraggingForReparentInRootLevelGridView()) { 2134 if (IsDraggingForReparentInRootLevelGridView()) {
2135 DCHECK(activated_folder_item_view_); 2135 DCHECK(activated_folder_item_view_);
2136 return GetIndexOfView(activated_folder_item_view_); 2136 folder_drop_target_ = GetIndexOfView(activated_folder_item_view_);
2137 } 2137 }
2138
2139 return GetIndexOfView(drag_view_);
2140 } 2138 }
2141 2139
2142 void AppsGridView::CalculateNearestTileForVertex(const gfx::Point& vertex, 2140 void AppsGridView::CalculateNearestTileForVertex(const gfx::Point& vertex,
2143 Index* nearest_tile, 2141 Index* nearest_tile,
2144 int* d_min) { 2142 int* d_min) {
2145 Index target_index; 2143 Index target_index;
2146 gfx::Rect target_bounds = GetTileBoundsForPoint(vertex, &target_index); 2144 gfx::Rect target_bounds = GetTileBoundsForPoint(vertex, &target_index);
2147 2145
2148 if (target_bounds.IsEmpty() || target_index == *nearest_tile) 2146 if (target_bounds.IsEmpty() || target_index == *nearest_tile)
2149 return; 2147 return;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
2223 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, 2221 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index,
2224 bool is_target_folder) { 2222 bool is_target_folder) {
2225 AppListItemView* target_view = 2223 AppListItemView* target_view =
2226 static_cast<AppListItemView*>( 2224 static_cast<AppListItemView*>(
2227 GetViewAtSlotOnCurrentPage(target_index.slot)); 2225 GetViewAtSlotOnCurrentPage(target_index.slot));
2228 if (target_view) 2226 if (target_view)
2229 target_view->SetAsAttemptedFolderTarget(is_target_folder); 2227 target_view->SetAsAttemptedFolderTarget(is_target_folder);
2230 } 2228 }
2231 2229
2232 } // namespace app_list 2230 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/views/apps_grid_view.h ('k') | ui/app_list/views/apps_grid_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698