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

Unified Diff: chrome/browser/ui/views/tabs/tab_drag_controller.cc

Issue 149393009: Fixes possible crash in tab dragging (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/views/tabs/tab_drag_controller.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/tabs/tab_drag_controller.cc
diff --git a/chrome/browser/ui/views/tabs/tab_drag_controller.cc b/chrome/browser/ui/views/tabs/tab_drag_controller.cc
index 658079119936d5461dfc62a5829bd4a95cbf95cb..f570ec6e084d4531d49eef7ec9fde66407c6ae54 100644
--- a/chrome/browser/ui/views/tabs/tab_drag_controller.cc
+++ b/chrome/browser/ui/views/tabs/tab_drag_controller.cc
@@ -1429,20 +1429,7 @@ void TabDragController::Detach(ReleaseCapture release_capture) {
attached_model->SetSelectionFromModel(selection_model_before_attach_);
} else if (attached_tabstrip_ == source_tabstrip_ &&
!initial_selection_model_.empty()) {
- // First time detaching from the source tabstrip. Reset selection model to
- // initial_selection_model_. Before resetting though we have to remove all
- // the tabs from initial_selection_model_ as it was created with the tabs
- // still there.
- ui::ListSelectionModel selection_model;
- selection_model.Copy(initial_selection_model_);
- for (DragData::const_reverse_iterator i(drag_data_.rbegin());
- i != drag_data_.rend(); ++i) {
- selection_model.DecrementFrom(i->source_model_index);
- }
- // We may have cleared out the selection model. Only reset it if it
- // contains something.
- if (!selection_model.empty())
- attached_model->SetSelectionFromModel(selection_model);
+ RestoreInitialSelection();
}
}
@@ -1881,6 +1868,31 @@ void TabDragController::ResetSelection(TabStripModel* model) {
model->SetSelectionFromModel(selection_model);
}
+void TabDragController::RestoreInitialSelection() {
+ // First time detaching from the source tabstrip. Reset selection model to
+ // initial_selection_model_. Before resetting though we have to remove all
+ // the tabs from initial_selection_model_ as it was created with the tabs
+ // still there.
+ ui::ListSelectionModel selection_model;
+ selection_model.Copy(initial_selection_model_);
+ for (DragData::const_reverse_iterator i(drag_data_.rbegin());
+ i != drag_data_.rend(); ++i) {
+ selection_model.DecrementFrom(i->source_model_index);
+ }
+ // We may have cleared out the selection model. Only reset it if it
+ // contains something.
+ if (selection_model.empty())
+ return;
+
+ // The anchor/active may have been among the tabs that were dragged out. Force
+ // the anchor/active to be valid.
+ if (selection_model.anchor() == ui::ListSelectionModel::kUnselectedIndex)
+ selection_model.set_anchor(selection_model.selected_indices()[0]);
+ if (selection_model.active() == ui::ListSelectionModel::kUnselectedIndex)
+ selection_model.set_active(selection_model.selected_indices()[0]);
+ GetModel(source_tabstrip_)->SetSelectionFromModel(selection_model);
+}
+
void TabDragController::RevertDragAt(size_t drag_index) {
DCHECK(started_drag_);
DCHECK(source_tabstrip_);
« no previous file with comments | « chrome/browser/ui/views/tabs/tab_drag_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698