| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/views/tabs/tab_overview_drag_controller.h" | 5 #include "chrome/browser/views/tabs/tab_overview_drag_controller.h" |
| 6 | 6 |
| 7 #include "chrome/browser/browser.h" | 7 #include "chrome/browser/browser.h" |
| 8 #include "chrome/browser/browser_window.h" | 8 #include "chrome/browser/browser_window.h" |
| 9 #include "chrome/browser/dock_info.h" | 9 #include "chrome/browser/dock_info.h" |
| 10 #include "chrome/browser/gtk/browser_window_gtk.h" | 10 #include "chrome/browser/gtk/browser_window_gtk.h" |
| 11 #include "chrome/browser/metrics/user_metrics.h" |
| 11 #include "chrome/browser/tab_contents/tab_contents.h" | 12 #include "chrome/browser/tab_contents/tab_contents.h" |
| 12 #include "chrome/browser/tabs/tab_strip_model.h" | 13 #include "chrome/browser/tabs/tab_strip_model.h" |
| 13 #include "chrome/browser/tab_contents/tab_contents.h" | 14 #include "chrome/browser/tab_contents/tab_contents.h" |
| 14 #include "chrome/browser/views/tabs/tab_overview_cell.h" | 15 #include "chrome/browser/views/tabs/tab_overview_cell.h" |
| 15 #include "chrome/browser/views/tabs/tab_overview_controller.h" | 16 #include "chrome/browser/views/tabs/tab_overview_controller.h" |
| 16 #include "chrome/browser/views/tabs/tab_overview_grid.h" | 17 #include "chrome/browser/views/tabs/tab_overview_grid.h" |
| 17 #include "chrome/browser/views/tabs/tab_overview_types.h" | 18 #include "chrome/browser/views/tabs/tab_overview_types.h" |
| 18 #include "chrome/common/notification_service.h" | 19 #include "chrome/common/notification_service.h" |
| 19 #include "views/fill_layout.h" | 20 #include "views/fill_layout.h" |
| 20 #include "views/view.h" | 21 #include "views/view.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 if (original_index_ == -1) | 87 if (original_index_ == -1) |
| 87 return; | 88 return; |
| 88 | 89 |
| 89 if (!dragging_ && | 90 if (!dragging_ && |
| 90 views::View::ExceededDragThreshold(location.x() - origin_.x(), | 91 views::View::ExceededDragThreshold(location.x() - origin_.x(), |
| 91 location.y() - origin_.y())) { | 92 location.y() - origin_.y())) { |
| 92 // Start dragging. | 93 // Start dragging. |
| 93 dragging_ = true; | 94 dragging_ = true; |
| 94 controller_->DragStarted(); | 95 controller_->DragStarted(); |
| 95 grid()->set_floating_index(current_index_); | 96 grid()->set_floating_index(current_index_); |
| 97 UserMetrics::RecordAction(L"TabOverview_DragCell", |
| 98 original_model_->profile()); |
| 96 } | 99 } |
| 97 if (dragging_) | 100 if (dragging_) |
| 98 DragCell(location); | 101 DragCell(location); |
| 99 } | 102 } |
| 100 | 103 |
| 101 void TabOverviewDragController::CommitDrag(const gfx::Point& location) { | 104 void TabOverviewDragController::CommitDrag(const gfx::Point& location) { |
| 102 if (original_index_ == -1) | 105 if (original_index_ == -1) |
| 103 return; | 106 return; |
| 104 | 107 |
| 105 Drag(location); | 108 Drag(location); |
| 106 if (detached_tab_) { | 109 if (detached_tab_) { |
| 107 if (mouse_over_mini_window_) { | 110 if (mouse_over_mini_window_) { |
| 108 // Dragged over a mini window, add as the last tab to the browser. | 111 // Dragged over a mini window, add as the last tab to the browser. |
| 109 Attach(model()->count()); | 112 Attach(model()->count()); |
| 113 UserMetrics::RecordAction(L"TabOverview_DropOnMiniWindow", |
| 114 original_model_->profile()); |
| 110 } else { | 115 } else { |
| 111 DropTab(location); | 116 DropTab(location); |
| 112 } | 117 } |
| 113 } else if (!dragging_ ) { | 118 } else if (!dragging_ ) { |
| 114 // We haven't started dragging. Tell the controller to focus the browser. | 119 // We haven't started dragging. Tell the controller to focus the browser. |
| 115 controller_->FocusBrowser(); | 120 controller_->FocusBrowser(); |
| 116 } else { | 121 } else { |
| 117 // The tab is already in position, nothing to do but animate the change. | 122 // The tab is already in position, nothing to do but animate the change. |
| 118 grid()->set_floating_index(-1); | 123 grid()->set_floating_index(-1); |
| 119 grid()->AnimateToTargetBounds(); | 124 grid()->AnimateToTargetBounds(); |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 detached_window_->Close(); | 332 detached_window_->Close(); |
| 328 detached_window_ = NULL; | 333 detached_window_ = NULL; |
| 329 } | 334 } |
| 330 | 335 |
| 331 void TabOverviewDragController::Detach(const gfx::Point& location) { | 336 void TabOverviewDragController::Detach(const gfx::Point& location) { |
| 332 if (detached_tab_) { | 337 if (detached_tab_) { |
| 333 // Already detached. | 338 // Already detached. |
| 334 return; | 339 return; |
| 335 } | 340 } |
| 336 | 341 |
| 342 UserMetrics::RecordAction(L"TabOverview_DetachCell", |
| 343 original_model_->profile()); |
| 344 |
| 337 detached_window_ = CreateDetachedWindow( | 345 detached_window_ = CreateDetachedWindow( |
| 338 location, model()->GetTabContentsAt(current_index_)); | 346 location, model()->GetTabContentsAt(current_index_)); |
| 339 detached_window_->Show(); | 347 detached_window_->Show(); |
| 340 | 348 |
| 341 grid()->set_floating_index(-1); | 349 grid()->set_floating_index(-1); |
| 342 SetDetachedContents(model()->GetTabContentsAt(current_index_)); | 350 SetDetachedContents(model()->GetTabContentsAt(current_index_)); |
| 343 if (model()->count() == 1) { | 351 if (model()->count() == 1) { |
| 344 // The model is going to be empty. Tell the host to move us offscreen. | 352 // The model is going to be empty. Tell the host to move us offscreen. |
| 345 // NOTE: it would be nice to hide and destroy the window here but this | 353 // NOTE: it would be nice to hide and destroy the window here but this |
| 346 // causes two problems: we'll stop getting events, and we don't want | 354 // causes two problems: we'll stop getting events, and we don't want |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 Source<TabContents>(tab)); | 448 Source<TabContents>(tab)); |
| 441 | 449 |
| 442 // We need to be the delegate so we receive messages about stuff, | 450 // We need to be the delegate so we receive messages about stuff, |
| 443 // otherwise our dragged contents may be replaced and subsequently | 451 // otherwise our dragged contents may be replaced and subsequently |
| 444 // collected/destroyed while the drag is in process, leading to | 452 // collected/destroyed while the drag is in process, leading to |
| 445 // nasty crashes. | 453 // nasty crashes. |
| 446 original_delegate_ = tab->delegate(); | 454 original_delegate_ = tab->delegate(); |
| 447 tab->set_delegate(this); | 455 tab->set_delegate(this); |
| 448 } | 456 } |
| 449 } | 457 } |
| OLD | NEW |