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

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

Powered by Google App Engine
This is Rietveld 408576698