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

Side by Side 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, 10 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
« no previous file with comments | « chrome/browser/ui/views/tabs/tab_drag_controller.h ('k') | no next file » | 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 "chrome/browser/ui/views/tabs/tab_drag_controller.h" 5 #include "chrome/browser/ui/views/tabs/tab_drag_controller.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <set> 8 #include <set>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 1411 matching lines...) Expand 10 before | Expand all | Expand 10 after
1422 1422
1423 // If we've removed the last Tab from the TabStrip, hide the frame now. 1423 // If we've removed the last Tab from the TabStrip, hide the frame now.
1424 if (!attached_model->empty()) { 1424 if (!attached_model->empty()) {
1425 if (!selection_model_before_attach_.empty() && 1425 if (!selection_model_before_attach_.empty() &&
1426 selection_model_before_attach_.active() >= 0 && 1426 selection_model_before_attach_.active() >= 0 &&
1427 selection_model_before_attach_.active() < attached_model->count()) { 1427 selection_model_before_attach_.active() < attached_model->count()) {
1428 // Restore the selection. 1428 // Restore the selection.
1429 attached_model->SetSelectionFromModel(selection_model_before_attach_); 1429 attached_model->SetSelectionFromModel(selection_model_before_attach_);
1430 } else if (attached_tabstrip_ == source_tabstrip_ && 1430 } else if (attached_tabstrip_ == source_tabstrip_ &&
1431 !initial_selection_model_.empty()) { 1431 !initial_selection_model_.empty()) {
1432 // First time detaching from the source tabstrip. Reset selection model to 1432 RestoreInitialSelection();
1433 // initial_selection_model_. Before resetting though we have to remove all
1434 // the tabs from initial_selection_model_ as it was created with the tabs
1435 // still there.
1436 ui::ListSelectionModel selection_model;
1437 selection_model.Copy(initial_selection_model_);
1438 for (DragData::const_reverse_iterator i(drag_data_.rbegin());
1439 i != drag_data_.rend(); ++i) {
1440 selection_model.DecrementFrom(i->source_model_index);
1441 }
1442 // We may have cleared out the selection model. Only reset it if it
1443 // contains something.
1444 if (!selection_model.empty())
1445 attached_model->SetSelectionFromModel(selection_model);
1446 } 1433 }
1447 } 1434 }
1448 1435
1449 // Create the dragged view. 1436 // Create the dragged view.
1450 if (!detach_into_browser_) 1437 if (!detach_into_browser_)
1451 CreateDraggedView(tab_data, drag_bounds); 1438 CreateDraggedView(tab_data, drag_bounds);
1452 1439
1453 attached_tabstrip_->DraggedTabsDetached(); 1440 attached_tabstrip_->DraggedTabsDetached();
1454 attached_tabstrip_ = NULL; 1441 attached_tabstrip_ = NULL;
1455 } 1442 }
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
1874 has_one_valid_tab = true; 1861 has_one_valid_tab = true;
1875 } 1862 }
1876 } 1863 }
1877 } 1864 }
1878 if (!has_one_valid_tab) 1865 if (!has_one_valid_tab)
1879 return; 1866 return;
1880 1867
1881 model->SetSelectionFromModel(selection_model); 1868 model->SetSelectionFromModel(selection_model);
1882 } 1869 }
1883 1870
1871 void TabDragController::RestoreInitialSelection() {
1872 // First time detaching from the source tabstrip. Reset selection model to
1873 // initial_selection_model_. Before resetting though we have to remove all
1874 // the tabs from initial_selection_model_ as it was created with the tabs
1875 // still there.
1876 ui::ListSelectionModel selection_model;
1877 selection_model.Copy(initial_selection_model_);
1878 for (DragData::const_reverse_iterator i(drag_data_.rbegin());
1879 i != drag_data_.rend(); ++i) {
1880 selection_model.DecrementFrom(i->source_model_index);
1881 }
1882 // We may have cleared out the selection model. Only reset it if it
1883 // contains something.
1884 if (selection_model.empty())
1885 return;
1886
1887 // The anchor/active may have been among the tabs that were dragged out. Force
1888 // the anchor/active to be valid.
1889 if (selection_model.anchor() == ui::ListSelectionModel::kUnselectedIndex)
1890 selection_model.set_anchor(selection_model.selected_indices()[0]);
1891 if (selection_model.active() == ui::ListSelectionModel::kUnselectedIndex)
1892 selection_model.set_active(selection_model.selected_indices()[0]);
1893 GetModel(source_tabstrip_)->SetSelectionFromModel(selection_model);
1894 }
1895
1884 void TabDragController::RevertDragAt(size_t drag_index) { 1896 void TabDragController::RevertDragAt(size_t drag_index) {
1885 DCHECK(started_drag_); 1897 DCHECK(started_drag_);
1886 DCHECK(source_tabstrip_); 1898 DCHECK(source_tabstrip_);
1887 1899
1888 base::AutoReset<bool> setter(&is_mutating_, true); 1900 base::AutoReset<bool> setter(&is_mutating_, true);
1889 TabDragData* data = &(drag_data_[drag_index]); 1901 TabDragData* data = &(drag_data_[drag_index]);
1890 if (attached_tabstrip_) { 1902 if (attached_tabstrip_) {
1891 int index = 1903 int index =
1892 GetModel(attached_tabstrip_)->GetIndexOfWebContents(data->contents); 1904 GetModel(attached_tabstrip_)->GetIndexOfWebContents(data->contents);
1893 if (attached_tabstrip_ != source_tabstrip_) { 1905 if (attached_tabstrip_ != source_tabstrip_) {
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
2331 gfx::Vector2d TabDragController::GetWindowOffset( 2343 gfx::Vector2d TabDragController::GetWindowOffset(
2332 const gfx::Point& point_in_screen) { 2344 const gfx::Point& point_in_screen) {
2333 TabStrip* owning_tabstrip = (attached_tabstrip_ && detach_into_browser_) ? 2345 TabStrip* owning_tabstrip = (attached_tabstrip_ && detach_into_browser_) ?
2334 attached_tabstrip_ : source_tabstrip_; 2346 attached_tabstrip_ : source_tabstrip_;
2335 views::View* toplevel_view = owning_tabstrip->GetWidget()->GetContentsView(); 2347 views::View* toplevel_view = owning_tabstrip->GetWidget()->GetContentsView();
2336 2348
2337 gfx::Point point = point_in_screen; 2349 gfx::Point point = point_in_screen;
2338 views::View::ConvertPointFromScreen(toplevel_view, &point); 2350 views::View::ConvertPointFromScreen(toplevel_view, &point);
2339 return point.OffsetFromOrigin(); 2351 return point.OffsetFromOrigin();
2340 } 2352 }
OLDNEW
« 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