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

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: 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
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 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 int slot_index = 0; 1180 int slot_index = 0;
1182 for (int i = 0; i < total_views; ++i) { 1181 for (int i = 0; i < total_views; ++i) {
1183 if (i < view_model_.view_size() && view_model_.view_at(i) == drag_view_) { 1182 if (i < view_model_.view_size() && view_model_.view_at(i) == drag_view_) {
1184 if (EnableFolderDragDropUI() && drop_attempt_ == DROP_FOR_FOLDER) 1183 if (EnableFolderDragDropUI() && drop_attempt_ == DROP_FOR_FOLDER)
1185 ++slot_index; 1184 ++slot_index;
1186 continue; 1185 continue;
1187 } 1186 }
1188 1187
1189 Index view_index = GetIndexFromModelIndex(slot_index); 1188 Index view_index = GetIndexFromModelIndex(slot_index);
1190 1189
1191 if (drop_target_ == view_index) { 1190 if (reorder_drop_target_ == view_index &&
Matt Giuca 2014/09/11 03:35:39 Can you add a comment saying what this does? Als
calamity 2014/09/11 07:05:17 Done.
1192 if (EnableFolderDragDropUI() && drop_attempt_ == DROP_FOR_FOLDER) { 1191 (!EnableFolderDragDropUI() || drop_attempt_ == DROP_FOR_REORDER)) {
1193 view_index = GetIndexFromModelIndex(slot_index); 1192 ++slot_index;
1194 } else if (!EnableFolderDragDropUI() || 1193 view_index = GetIndexFromModelIndex(slot_index);
1195 drop_attempt_ == DROP_FOR_REORDER) {
1196 ++slot_index;
1197 view_index = GetIndexFromModelIndex(slot_index);
1198 }
1199 } 1194 }
1200 1195
1201 // Decide the x or y offset for current item. 1196 // Decide the x or y offset for current item.
1202 int x_offset = 0; 1197 int x_offset = 0;
1203 int y_offset = 0; 1198 int y_offset = 0;
1204 1199
1205 if (pagination_controller_->scroll_axis() == 1200 if (pagination_controller_->scroll_axis() ==
1206 PaginationController::SCROLL_AXIS_HORIZONTAL) { 1201 PaginationController::SCROLL_AXIS_HORIZONTAL) {
1207 if (view_index.page < current_page) 1202 if (view_index.page < current_page)
1208 x_offset = -page_width; 1203 x_offset = -page_width;
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1360 current_page = drag_start_page_; 1355 current_page = drag_start_page_;
1361 } 1356 }
1362 1357
1363 if (use_page_button_hovering && page_switcher_view_ && 1358 if (use_page_button_hovering && page_switcher_view_ &&
1364 page_switcher_view_->bounds().Contains(point)) { 1359 page_switcher_view_->bounds().Contains(point)) {
1365 gfx::Point page_switcher_point(point); 1360 gfx::Point page_switcher_point(point);
1366 views::View::ConvertPointToTarget(this, page_switcher_view_, 1361 views::View::ConvertPointToTarget(this, page_switcher_view_,
1367 &page_switcher_point); 1362 &page_switcher_point);
1368 int page = page_switcher_view_->GetPageForPoint(page_switcher_point); 1363 int page = page_switcher_view_->GetPageForPoint(page_switcher_point);
1369 if (pagination_model_.is_valid_page(page)) { 1364 if (pagination_model_.is_valid_page(page)) {
1370 drop_target_.page = page; 1365 reorder_drop_target_.page = page;
1371 drop_target_.slot = tiles_per_page() - 1; 1366 reorder_drop_target_.slot = tiles_per_page() - 1;
1372 } 1367 }
1373 } else { 1368 } else {
1374 gfx::Rect bounds(GetContentsBounds()); 1369 gfx::Rect bounds(GetContentsBounds());
1375 const int drop_row = (point.y() - bounds.y()) / kPreferredTileHeight; 1370 const int drop_row = (point.y() - bounds.y()) / kPreferredTileHeight;
1376 const int drop_col = std::min(cols_ - 1, 1371 const int drop_col = std::min(cols_ - 1,
1377 (point.x() - bounds.x()) / kPreferredTileWidth); 1372 (point.x() - bounds.x()) / kPreferredTileWidth);
1378 1373
1379 drop_target_.page = current_page; 1374 reorder_drop_target_.page = current_page;
1380 drop_target_.slot = std::max(0, std::min( 1375 reorder_drop_target_.slot = std::max(
1381 tiles_per_page() - 1, 1376 0, std::min(tiles_per_page() - 1, drop_row * cols_ + drop_col));
1382 drop_row * cols_ + drop_col));
1383 } 1377 }
1384 1378
1385 // Limits to the last possible slot on last page. 1379 // Limits to the last possible slot on last page.
1386 if (drop_target_.page == pagination_model_.total_pages() - 1) { 1380 if (reorder_drop_target_.page == pagination_model_.total_pages() - 1) {
1387 drop_target_.slot = std::min( 1381 reorder_drop_target_.slot =
1388 (view_model_.view_size() - 1) % tiles_per_page(), 1382 std::min((view_model_.view_size() - 1) % tiles_per_page(),
1389 drop_target_.slot); 1383 reorder_drop_target_.slot);
1390 } 1384 }
1391 } 1385 }
1392 1386
1393 1387
1394 void AppsGridView::CalculateDropTargetWithFolderEnabled( 1388 void AppsGridView::CalculateDropTargetWithFolderEnabled(
1395 const gfx::Point& drag_point, 1389 const gfx::Point& drag_point,
1396 bool use_page_button_hovering) { 1390 bool use_page_button_hovering) {
1397 gfx::Point point(drag_point); 1391 gfx::Point point(drag_point);
1398 if (!IsPointWithinDragBuffer(drag_point)) { 1392 if (!IsPointWithinDragBuffer(drag_point)) {
1399 point = drag_start_grid_view_; 1393 point = drag_start_grid_view_;
1400 } 1394 }
1401 1395
1402 if (use_page_button_hovering && page_switcher_view_ && 1396 if (use_page_button_hovering && page_switcher_view_ &&
1403 page_switcher_view_->bounds().Contains(point)) { 1397 page_switcher_view_->bounds().Contains(point)) {
1404 gfx::Point page_switcher_point(point); 1398 gfx::Point page_switcher_point(point);
1405 views::View::ConvertPointToTarget(this, page_switcher_view_, 1399 views::View::ConvertPointToTarget(this, page_switcher_view_,
1406 &page_switcher_point); 1400 &page_switcher_point);
1407 int page = page_switcher_view_->GetPageForPoint(page_switcher_point); 1401 int page = page_switcher_view_->GetPageForPoint(page_switcher_point);
1408 if (pagination_model_.is_valid_page(page)) 1402 if (pagination_model_.is_valid_page(page))
1409 drop_attempt_ = DROP_FOR_NONE; 1403 drop_attempt_ = DROP_FOR_NONE;
1410 } else { 1404 } else {
1411 DCHECK(drag_view_); 1405 DCHECK(drag_view_);
1412 // Try to find the nearest target for folder dropping or re-ordering. 1406 // Try to find the nearest target for folder dropping or re-ordering.
1413 drop_target_ = GetNearestTileForDragView(); 1407 CalculateNearestTileForDragView();
1414 } 1408 }
1415 } 1409 }
1416 1410
1417 void AppsGridView::OnReorderTimer() { 1411 void AppsGridView::OnReorderTimer() {
1418 if (drop_attempt_ == DROP_FOR_REORDER) 1412 if (drop_attempt_ == DROP_FOR_REORDER)
1419 AnimateToIdealBounds(); 1413 AnimateToIdealBounds();
1420 } 1414 }
1421 1415
1422 void AppsGridView::OnFolderItemReparentTimer() { 1416 void AppsGridView::OnFolderItemReparentTimer() {
1423 DCHECK(folder_delegate_); 1417 DCHECK(folder_delegate_);
1424 if (drag_out_of_folder_container_ && drag_view_) { 1418 if (drag_out_of_folder_container_ && drag_view_) {
1425 folder_delegate_->ReparentItem(drag_view_, last_drag_point_); 1419 folder_delegate_->ReparentItem(drag_view_, last_drag_point_);
1426 1420
1427 // Set the flag in the folder's grid view. 1421 // Set the flag in the folder's grid view.
1428 dragging_for_reparent_item_ = true; 1422 dragging_for_reparent_item_ = true;
1429 1423
1430 // Do not observe any data change since it is going to be hidden. 1424 // Do not observe any data change since it is going to be hidden.
1431 item_list_->RemoveObserver(this); 1425 item_list_->RemoveObserver(this);
1432 item_list_ = NULL; 1426 item_list_ = NULL;
1433 } 1427 }
1434 } 1428 }
1435 1429
1436 void AppsGridView::OnFolderDroppingTimer() { 1430 void AppsGridView::OnFolderDroppingTimer() {
1437 if (drop_attempt_ == DROP_FOR_FOLDER) 1431 if (drop_attempt_ == DROP_FOR_FOLDER)
1438 SetAsFolderDroppingTarget(drop_target_, true); 1432 SetAsFolderDroppingTarget(folder_drop_target_, true);
1439 } 1433 }
1440 1434
1441 void AppsGridView::UpdateDragStateInsideFolder(Pointer pointer, 1435 void AppsGridView::UpdateDragStateInsideFolder(Pointer pointer,
1442 const gfx::Point& drag_point) { 1436 const gfx::Point& drag_point) {
1443 if (IsUnderOEMFolder()) 1437 if (IsUnderOEMFolder())
1444 return; 1438 return;
1445 1439
1446 if (IsDraggingForReparentInHiddenGridView()) { 1440 if (IsDraggingForReparentInHiddenGridView()) {
1447 // Dispatch drag event to root level grid view for re-parenting folder 1441 // Dispatch drag event to root level grid view for re-parenting folder
1448 // folder item purpose. 1442 // folder item purpose.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1511 bool events_forwarded_to_drag_drop_host, 1505 bool events_forwarded_to_drag_drop_host,
1512 bool cancel_drag) { 1506 bool cancel_drag) {
1513 // EndDrag was called before if |drag_view_| is NULL. 1507 // EndDrag was called before if |drag_view_| is NULL.
1514 if (!drag_view_) 1508 if (!drag_view_)
1515 return; 1509 return;
1516 1510
1517 DCHECK(IsDraggingForReparentInRootLevelGridView()); 1511 DCHECK(IsDraggingForReparentInRootLevelGridView());
1518 bool cancel_reparent = cancel_drag || drop_attempt_ == DROP_FOR_NONE; 1512 bool cancel_reparent = cancel_drag || drop_attempt_ == DROP_FOR_NONE;
1519 if (!events_forwarded_to_drag_drop_host && !cancel_reparent) { 1513 if (!events_forwarded_to_drag_drop_host && !cancel_reparent) {
1520 CalculateDropTarget(last_drag_point_, true); 1514 CalculateDropTarget(last_drag_point_, true);
1521 if (IsValidIndex(drop_target_)) { 1515 if (drop_attempt_ == DROP_FOR_REORDER &&
1522 if (drop_attempt_ == DROP_FOR_REORDER) { 1516 IsValidIndex(reorder_drop_target_)) {
1523 ReparentItemForReorder(drag_view_, drop_target_); 1517 ReparentItemForReorder(drag_view_, reorder_drop_target_);
1524 } else if (drop_attempt_ == DROP_FOR_FOLDER) { 1518 } else if (drop_attempt_ == DROP_FOR_FOLDER &&
1525 ReparentItemToAnotherFolder(drag_view_, drop_target_); 1519 IsValidIndex(folder_drop_target_)) {
1526 } 1520 ReparentItemToAnotherFolder(drag_view_, folder_drop_target_);
1527 } 1521 }
1528 SetViewHidden(drag_view_, false /* show */, true /* no animate */); 1522 SetViewHidden(drag_view_, false /* show */, true /* no animate */);
1529 } 1523 }
1530 1524
1531 // The drag can be ended after the synchronous drag is created but before it 1525 // The drag can be ended after the synchronous drag is created but before it
1532 // is Run(). 1526 // is Run().
1533 CleanUpSynchronousDrag(); 1527 CleanUpSynchronousDrag();
1534 1528
1535 SetAsFolderDroppingTarget(drop_target_, false); 1529 SetAsFolderDroppingTarget(folder_drop_target_, false);
1536 if (cancel_reparent) { 1530 if (cancel_reparent) {
1537 CancelFolderItemReparent(drag_view_); 1531 CancelFolderItemReparent(drag_view_);
1538 } else { 1532 } else {
1539 // By setting |drag_view_| to NULL here, we prevent ClearDragState() from 1533 // By setting |drag_view_| to NULL here, we prevent ClearDragState() from
1540 // cleaning up the newly created AppListItemView, effectively claiming 1534 // cleaning up the newly created AppListItemView, effectively claiming
1541 // ownership of the newly created drag view. 1535 // ownership of the newly created drag view.
1542 drag_view_->OnDragEnded(); 1536 drag_view_->OnDragEnded();
1543 drag_view_ = NULL; 1537 drag_view_ = NULL;
1544 } 1538 }
1545 ClearDragState(); 1539 ClearDragState();
1546 AnimateToIdealBounds(); 1540 AnimateToIdealBounds();
1547 1541
1548 StopPageFlipTimer(); 1542 StopPageFlipTimer();
1549 } 1543 }
1550 1544
1551 void AppsGridView::EndDragForReparentInHiddenFolderGridView() { 1545 void AppsGridView::EndDragForReparentInHiddenFolderGridView() {
1552 if (drag_and_drop_host_) { 1546 if (drag_and_drop_host_) {
1553 // If we had a drag and drop proxy icon, we delete it and make the real 1547 // If we had a drag and drop proxy icon, we delete it and make the real
1554 // item visible again. 1548 // item visible again.
1555 drag_and_drop_host_->DestroyDragIconProxy(); 1549 drag_and_drop_host_->DestroyDragIconProxy();
1556 } 1550 }
1557 1551
1558 // The drag can be ended after the synchronous drag is created but before it 1552 // The drag can be ended after the synchronous drag is created but before it
1559 // is Run(). 1553 // is Run().
1560 CleanUpSynchronousDrag(); 1554 CleanUpSynchronousDrag();
1561 1555
1562 SetAsFolderDroppingTarget(drop_target_, false); 1556 SetAsFolderDroppingTarget(folder_drop_target_, false);
1563 ClearDragState(); 1557 ClearDragState();
1564 } 1558 }
1565 1559
1566 void AppsGridView::OnFolderItemRemoved() { 1560 void AppsGridView::OnFolderItemRemoved() {
1567 DCHECK(folder_delegate_); 1561 DCHECK(folder_delegate_);
1568 item_list_ = NULL; 1562 item_list_ = NULL;
1569 } 1563 }
1570 1564
1571 void AppsGridView::StartDragAndDropHostDrag(const gfx::Point& grid_location) { 1565 void AppsGridView::StartDragAndDropHostDrag(const gfx::Point& grid_location) {
1572 // When a drag and drop host is given, the item can be dragged out of the app 1566 // 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
2041 2035
2042 void AppsGridView::OnImplicitAnimationsCompleted() { 2036 void AppsGridView::OnImplicitAnimationsCompleted() {
2043 if (layer()->opacity() == 0.0f) 2037 if (layer()->opacity() == 0.0f)
2044 SetVisible(false); 2038 SetVisible(false);
2045 } 2039 }
2046 2040
2047 bool AppsGridView::EnableFolderDragDropUI() { 2041 bool AppsGridView::EnableFolderDragDropUI() {
2048 // Enable drag and drop folder UI only if it is at the app list root level 2042 // Enable drag and drop folder UI only if it is at the app list root level
2049 // and the switch is on and the target folder can still accept new items. 2043 // and the switch is on and the target folder can still accept new items.
2050 return model_->folders_enabled() && !folder_delegate_ && 2044 return model_->folders_enabled() && !folder_delegate_ &&
2051 CanDropIntoTarget(drop_target_); 2045 CanDropIntoTarget(folder_drop_target_);
2052 } 2046 }
2053 2047
2054 bool AppsGridView::CanDropIntoTarget(const Index& drop_target) { 2048 bool AppsGridView::CanDropIntoTarget(const Index& drop_target) {
2055 views::View* target_view = GetViewAtSlotOnCurrentPage(drop_target.slot); 2049 views::View* target_view = GetViewAtSlotOnCurrentPage(drop_target.slot);
2056 if (!target_view) 2050 if (!target_view)
2057 return true; 2051 return true;
2058 2052
2059 AppListItem* target_item = 2053 AppListItem* target_item =
2060 static_cast<AppListItemView*>(target_view)->item(); 2054 static_cast<AppListItemView*>(target_view)->item();
2061 // Items can be dropped into non-folders (which have no children) or folders 2055 // Items can be dropped into non-folders (which have no children) or folders
2062 // that have fewer than the max allowed items. 2056 // that have fewer than the max allowed items.
2063 // OEM folder does not allow to drag/drop other items in it. 2057 // OEM folder does not allow to drag/drop other items in it.
2064 return target_item->ChildItemCount() < kMaxFolderItems && 2058 return target_item->ChildItemCount() < kMaxFolderItems &&
2065 !IsOEMFolderItem(target_item); 2059 !IsOEMFolderItem(target_item);
2066 } 2060 }
2067 2061
2068 // TODO(jennyz): Optimize the calculation for finding nearest tile. 2062 // TODO(jennyz): Optimize the calculation for finding nearest tile.
2069 AppsGridView::Index AppsGridView::GetNearestTileForDragView() { 2063 void AppsGridView::CalculateNearestTileForDragView() {
2070 Index nearest_tile; 2064 Index nearest_tile;
2071 nearest_tile.page = -1; 2065 nearest_tile.page = -1;
2072 nearest_tile.slot = -1; 2066 nearest_tile.slot = -1;
2073 int d_min = -1; 2067 int d_min = -1;
2074 2068
2075 // Calculate the top left tile |drag_view| intersects. 2069 // Calculate the top left tile |drag_view| intersects.
2076 gfx::Point pt = drag_view_->bounds().origin(); 2070 gfx::Point pt = drag_view_->bounds().origin();
2077 CalculateNearestTileForVertex(pt, &nearest_tile, &d_min); 2071 CalculateNearestTileForVertex(pt, &nearest_tile, &d_min);
2078 2072
2079 // Calculate the top right tile |drag_view| intersects. 2073 // Calculate the top right tile |drag_view| intersects.
(...skipping 10 matching lines...) Expand all
2090 2084
2091 const int d_folder_dropping = 2085 const int d_folder_dropping =
2092 kFolderDroppingCircleRadius + kGridIconDimension / 2; 2086 kFolderDroppingCircleRadius + kGridIconDimension / 2;
2093 const int d_reorder = kReorderDroppingCircleRadius + kGridIconDimension / 2; 2087 const int d_reorder = kReorderDroppingCircleRadius + kGridIconDimension / 2;
2094 2088
2095 // If user drags an item across pages to the last page, and targets it 2089 // If user drags an item across pages to the last page, and targets it
2096 // to the last empty slot on it, push the last item for re-ordering. 2090 // to the last empty slot on it, push the last item for re-ordering.
2097 if (IsLastPossibleDropTarget(nearest_tile) && d_min < d_reorder) { 2091 if (IsLastPossibleDropTarget(nearest_tile) && d_min < d_reorder) {
2098 drop_attempt_ = DROP_FOR_REORDER; 2092 drop_attempt_ = DROP_FOR_REORDER;
2099 nearest_tile.slot = nearest_tile.slot - 1; 2093 nearest_tile.slot = nearest_tile.slot - 1;
2100 return nearest_tile; 2094 reorder_drop_target_ = nearest_tile;
2095 return;
2101 } 2096 }
2102 2097
2103 if (IsValidIndex(nearest_tile)) { 2098 if (IsValidIndex(nearest_tile)) {
2104 if (d_min < d_folder_dropping) { 2099 if (d_min < d_folder_dropping) {
2105 views::View* target_view = GetViewAtSlotOnCurrentPage(nearest_tile.slot); 2100 views::View* target_view = GetViewAtSlotOnCurrentPage(nearest_tile.slot);
2106 if (target_view && 2101 if (target_view &&
2107 !IsFolderItem(static_cast<AppListItemView*>(drag_view_)->item())) { 2102 !IsFolderItem(static_cast<AppListItemView*>(drag_view_)->item())) {
2108 // If a non-folder item is dragged to the target slot with an item 2103 // If a non-folder item is dragged to the target slot with an item
2109 // sitting on it, attempt to drop the dragged item into the folder 2104 // sitting on it, attempt to drop the dragged item into the folder
2110 // containing the item on nearest_tile. 2105 // containing the item on nearest_tile.
2111 drop_attempt_ = DROP_FOR_FOLDER; 2106 drop_attempt_ = DROP_FOR_FOLDER;
2112 return nearest_tile; 2107 folder_drop_target_ = nearest_tile;
2108 return;
2113 } else { 2109 } else {
2114 // If the target slot is blank, or the dragged item is a folder, attempt 2110 // If the target slot is blank, or the dragged item is a folder, attempt
2115 // to re-order. 2111 // to re-order.
2116 drop_attempt_ = DROP_FOR_REORDER; 2112 drop_attempt_ = DROP_FOR_REORDER;
2117 return nearest_tile; 2113 reorder_drop_target_ = nearest_tile;
2114 return;
2118 } 2115 }
2119 } else if (d_min < d_reorder) { 2116 } else if (d_min < d_reorder) {
2120 // Entering the re-order circle of the slot. 2117 // Entering the re-order circle of the slot.
2121 drop_attempt_ = DROP_FOR_REORDER; 2118 drop_attempt_ = DROP_FOR_REORDER;
2122 return nearest_tile; 2119 reorder_drop_target_ = nearest_tile;
2120 return;
2123 } 2121 }
2124 } 2122 }
2125 2123
2126 // If |drag_view| is not entering the re-order or fold dropping region of 2124 // If |drag_view| is not entering the re-order or fold dropping region of
Matt Giuca 2014/09/11 03:35:39 nit: folder
calamity 2014/09/11 07:05:17 Done.
2127 // any items, cancel any previous re-order or folder dropping timer, and 2125 // any items, cancel any previous re-order or folder dropping timer.
2128 // return itself.
2129 drop_attempt_ = DROP_FOR_NONE; 2126 drop_attempt_ = DROP_FOR_NONE;
2130 reorder_timer_.Stop(); 2127 reorder_timer_.Stop();
2131 folder_dropping_timer_.Stop(); 2128 folder_dropping_timer_.Stop();
2132 2129
2133 // When dragging for reparent a folder item, it should go back to its parent 2130 // When dragging for reparent a folder item, it should go back to its parent
2134 // folder item if there is no drop target. 2131 // folder item if there is no drop target.
2135 if (IsDraggingForReparentInRootLevelGridView()) { 2132 if (IsDraggingForReparentInRootLevelGridView()) {
2136 DCHECK(activated_folder_item_view_); 2133 DCHECK(activated_folder_item_view_);
2137 return GetIndexOfView(activated_folder_item_view_); 2134 folder_drop_target_ = GetIndexOfView(activated_folder_item_view_);
2138 } 2135 }
2139
2140 return GetIndexOfView(drag_view_);
2141 } 2136 }
2142 2137
2143 void AppsGridView::CalculateNearestTileForVertex(const gfx::Point& vertex, 2138 void AppsGridView::CalculateNearestTileForVertex(const gfx::Point& vertex,
2144 Index* nearest_tile, 2139 Index* nearest_tile,
2145 int* d_min) { 2140 int* d_min) {
2146 Index target_index; 2141 Index target_index;
2147 gfx::Rect target_bounds = GetTileBoundsForPoint(vertex, &target_index); 2142 gfx::Rect target_bounds = GetTileBoundsForPoint(vertex, &target_index);
2148 2143
2149 if (target_bounds.IsEmpty() || target_index == *nearest_tile) 2144 if (target_bounds.IsEmpty() || target_index == *nearest_tile)
2150 return; 2145 return;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
2224 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, 2219 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index,
2225 bool is_target_folder) { 2220 bool is_target_folder) {
2226 AppListItemView* target_view = 2221 AppListItemView* target_view =
2227 static_cast<AppListItemView*>( 2222 static_cast<AppListItemView*>(
2228 GetViewAtSlotOnCurrentPage(target_index.slot)); 2223 GetViewAtSlotOnCurrentPage(target_index.slot));
2229 if (target_view) 2224 if (target_view)
2230 target_view->SetAsAttemptedFolderTarget(is_target_folder); 2225 target_view->SetAsAttemptedFolderTarget(is_target_folder);
2231 } 2226 }
2232 2227
2233 } // namespace app_list 2228 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698