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

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

Issue 466693002: Fix app list DCHECKs getting hit when model updates occur during dragging (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add test comment Created 6 years, 4 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 | Annotate | Revision Log
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 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 // we'll enter the synchronous drag. 549 // we'll enter the synchronous drag.
550 // NOTE we don't Run() the drag here because that causes animations not to 550 // NOTE we don't Run() the drag here because that causes animations not to
551 // update for some reason. 551 // update for some reason.
552 synchronous_drag_->set_shortcut_path(path); 552 synchronous_drag_->set_shortcut_path(path);
553 DCHECK(synchronous_drag_->CanRun()); 553 DCHECK(synchronous_drag_->CanRun());
554 } 554 }
555 #endif 555 #endif
556 556
557 bool AppsGridView::UpdateDragFromItem(Pointer pointer, 557 bool AppsGridView::UpdateDragFromItem(Pointer pointer,
558 const ui::LocatedEvent& event) { 558 const ui::LocatedEvent& event) {
559 DCHECK(drag_view_); 559 if (!drag_view_)
560 return false; // Drag canceled.
560 561
561 gfx::Point drag_point_in_grid_view; 562 gfx::Point drag_point_in_grid_view;
562 ExtractDragLocation(event, &drag_point_in_grid_view); 563 ExtractDragLocation(event, &drag_point_in_grid_view);
563 UpdateDrag(pointer, drag_point_in_grid_view); 564 UpdateDrag(pointer, drag_point_in_grid_view);
564 if (!dragging()) 565 if (!dragging())
565 return false; 566 return false;
566 567
567 // If a drag and drop host is provided, see if the drag operation needs to be 568 // If a drag and drop host is provided, see if the drag operation needs to be
568 // forwarded. 569 // forwarded.
569 gfx::Point location_in_screen = drag_point_in_grid_view; 570 gfx::Point location_in_screen = drag_point_in_grid_view;
570 views::View::ConvertPointToScreen(this, &location_in_screen); 571 views::View::ConvertPointToScreen(this, &location_in_screen);
571 DispatchDragEventToDragAndDropHost(location_in_screen); 572 DispatchDragEventToDragAndDropHost(location_in_screen);
572 if (drag_and_drop_host_) 573 if (drag_and_drop_host_)
573 drag_and_drop_host_->UpdateDragIconProxy(location_in_screen); 574 drag_and_drop_host_->UpdateDragIconProxy(location_in_screen);
574 return true; 575 return true;
575 } 576 }
576 577
577 void AppsGridView::UpdateDrag(Pointer pointer, const gfx::Point& point) { 578 void AppsGridView::UpdateDrag(Pointer pointer, const gfx::Point& point) {
578 if (folder_delegate_) 579 if (folder_delegate_)
579 UpdateDragStateInsideFolder(pointer, point); 580 UpdateDragStateInsideFolder(pointer, point);
580 581
581 // EndDrag was called before if |drag_view_| is NULL.
582 if (!drag_view_) 582 if (!drag_view_)
583 return; 583 return; // Drag canceled.
584 584
585 if (RunSynchronousDrag()) 585 if (RunSynchronousDrag())
586 return; 586 return;
587 587
588 gfx::Vector2d drag_vector(point - drag_start_grid_view_); 588 gfx::Vector2d drag_vector(point - drag_start_grid_view_);
589 if (!dragging() && ExceededDragThreshold(drag_vector)) { 589 if (!dragging() && ExceededDragThreshold(drag_vector)) {
590 drag_pointer_ = pointer; 590 drag_pointer_ = pointer;
591 // Move the view to the front so that it appears on top of other views. 591 // Move the view to the front so that it appears on top of other views.
592 ReorderChildView(drag_view_, -1); 592 ReorderChildView(drag_view_, -1);
593 bounds_animator_.StopAnimatingView(drag_view_); 593 bounds_animator_.StopAnimatingView(drag_view_);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 } else { 667 } else {
668 if (IsDraggingForReparentInHiddenGridView()) { 668 if (IsDraggingForReparentInHiddenGridView()) {
669 // Forward the EndDrag event to the root level grid view. 669 // Forward the EndDrag event to the root level grid view.
670 folder_delegate_->DispatchEndDragEventForReparent( 670 folder_delegate_->DispatchEndDragEventForReparent(
671 false /* events_forwarded_to_drag_drop_host */, 671 false /* events_forwarded_to_drag_drop_host */,
672 cancel /* cancel_drag */); 672 cancel /* cancel_drag */);
673 EndDragForReparentInHiddenFolderGridView(); 673 EndDragForReparentInHiddenFolderGridView();
674 return; 674 return;
675 } 675 }
676 676
677 if (IsDraggingForReparentInRootLevelGridView()) {
678 // An EndDrag can be received during a reparent via a model change. This
679 // is always a cancel and needs to be forwarded to the folder.
680 DCHECK(cancel);
681 delegate_->CancelDragInActiveFolder();
682 return;
683 }
684
677 if (!cancel && dragging()) { 685 if (!cancel && dragging()) {
678 // Regular drag ending path, ie, not for reparenting. 686 // Regular drag ending path, ie, not for reparenting.
679 CalculateDropTarget(last_drag_point_, true); 687 CalculateDropTarget(last_drag_point_, true);
680 if (IsValidIndex(drop_target_)) { 688 if (IsValidIndex(drop_target_)) {
681 if (!EnableFolderDragDropUI()) { 689 if (!EnableFolderDragDropUI()) {
682 MoveItemInModel(drag_view_, drop_target_); 690 MoveItemInModel(drag_view_, drop_target_);
683 } else { 691 } else {
684 if (drop_attempt_ == DROP_FOR_REORDER) 692 if (drop_attempt_ == DROP_FOR_REORDER)
685 MoveItemInModel(drag_view_, drop_target_); 693 MoveItemInModel(drag_view_, drop_target_);
686 else if (drop_attempt_ == DROP_FOR_FOLDER) 694 else if (drop_attempt_ == DROP_FOR_FOLDER)
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 drag_start_grid_view_ = drag_point; 798 drag_start_grid_view_ = drag_point;
791 799
792 drag_view_start_ = gfx::Point(drag_view_->x(), drag_view_->y()); 800 drag_view_start_ = gfx::Point(drag_view_->x(), drag_view_->y());
793 801
794 // Set the flag in root level grid view. 802 // Set the flag in root level grid view.
795 dragging_for_reparent_item_ = true; 803 dragging_for_reparent_item_ = true;
796 } 804 }
797 805
798 void AppsGridView::UpdateDragFromReparentItem(Pointer pointer, 806 void AppsGridView::UpdateDragFromReparentItem(Pointer pointer,
799 const gfx::Point& drag_point) { 807 const gfx::Point& drag_point) {
808 // Note that if a cancel ocurrs while reparenting, the |drag_view_| in both
809 // root and folder grid views is cleared, so the check in UpdateDragFromItem()
810 // for |drag_view_| being NULL (in the folder grid) is sufficient.
800 DCHECK(drag_view_); 811 DCHECK(drag_view_);
801 DCHECK(IsDraggingForReparentInRootLevelGridView()); 812 DCHECK(IsDraggingForReparentInRootLevelGridView());
802 813
803 UpdateDrag(pointer, drag_point); 814 UpdateDrag(pointer, drag_point);
804 } 815 }
805 816
806 bool AppsGridView::IsDraggedView(const views::View* view) const { 817 bool AppsGridView::IsDraggedView(const views::View* view) const {
807 return drag_view_ == view; 818 return drag_view_ == view;
808 } 819 }
809 820
(...skipping 1354 matching lines...) Expand 10 before | Expand all | Expand 10 after
2164 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, 2175 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index,
2165 bool is_target_folder) { 2176 bool is_target_folder) {
2166 AppListItemView* target_view = 2177 AppListItemView* target_view =
2167 static_cast<AppListItemView*>( 2178 static_cast<AppListItemView*>(
2168 GetViewAtSlotOnCurrentPage(target_index.slot)); 2179 GetViewAtSlotOnCurrentPage(target_index.slot));
2169 if (target_view) 2180 if (target_view)
2170 target_view->SetAsAttemptedFolderTarget(is_target_folder); 2181 target_view->SetAsAttemptedFolderTarget(is_target_folder);
2171 } 2182 }
2172 2183
2173 } // namespace app_list 2184 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/views/app_list_main_view_unittest.cc ('k') | ui/app_list/views/apps_grid_view_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698