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 eb5dd067822b015bd313fcb34c30eb42867f885c..8f3e9e81fb972a203289122d20975d75a6483c4d 100644 |
--- a/chrome/browser/ui/views/tabs/tab_drag_controller.cc |
+++ b/chrome/browser/ui/views/tabs/tab_drag_controller.cc |
@@ -85,6 +85,15 @@ const int kStackedDistance = 36; |
// maximized size. |
const int kMaximizedWindowInset = 10; // DIPs. |
+// Whether a new browser window created during a drag is destroyed immediately |
+// once it is associated with a new tab strip. If false, windows created during |
+// the drag are destroyed only when the drag ends. |
+#if 0 && defined(OS_MACOSX) |
tapted
2016/03/01 08:11:58
So, this doesn't work yet. It's fine for a follow-
themblsha
2016/03/09 17:40:22
Done.
|
+const bool windows_destroy_during_drag = false; |
+#else |
+const bool windows_destroy_during_drag = true; |
+#endif |
+ |
#if defined(USE_ASH) |
void SetWindowPositionManaged(gfx::NativeWindow window, bool value) { |
ash::wm::GetWindowState(window)->set_window_position_managed(value); |
@@ -272,7 +281,12 @@ void TabDragController::Init( |
can_release_capture_ = false; |
#endif |
start_point_in_screen_ = gfx::Point(source_tab_offset, mouse_offset.y()); |
+ DLOG(INFO) << "TabDragController::Init/mouse offset -> point_in_window=" |
+ << mouse_offset.ToString() << " -> " |
+ << start_point_in_screen_.ToString(); |
views::View::ConvertPointToScreen(source_tab, &start_point_in_screen_); |
+ DLOG(INFO) << " --> in screen=" << start_point_in_screen_.ToString(); |
+ |
event_source_ = event_source; |
mouse_offset_ = mouse_offset; |
move_behavior_ = move_behavior; |
@@ -344,10 +358,14 @@ void TabDragController::Drag(const gfx::Point& point_in_screen) { |
if (waiting_for_run_loop_to_exit_) |
return; |
+ DLOG(INFO) << "Started_drag = " << started_drag_; |
+ |
if (!started_drag_) { |
if (!CanStartDrag(point_in_screen)) |
return; // User hasn't dragged far enough yet. |
+ DLOG(INFO) << "STARTING!"; |
+ |
// On windows SaveFocus() may trigger a capture lost, which destroys us. |
{ |
base::WeakPtr<TabDragController> ref(weak_factory_.GetWeakPtr()); |
@@ -355,6 +373,7 @@ void TabDragController::Drag(const gfx::Point& point_in_screen) { |
if (!ref) |
return; |
} |
+ DLOG(INFO) << "Starting drag"; |
started_drag_ = true; |
Attach(source_tabstrip_, gfx::Point()); |
if (static_cast<int>(drag_data_.size()) == |
@@ -523,13 +542,19 @@ bool TabDragController::CanStartDrag(const gfx::Point& point_in_screen) const { |
static const int kMinimumDragDistance = 10; |
int x_offset = abs(point_in_screen.x() - start_point_in_screen_.x()); |
int y_offset = abs(point_in_screen.y() - start_point_in_screen_.y()); |
- return sqrt(pow(static_cast<float>(x_offset), 2) + |
+ bool result = sqrt(pow(static_cast<float>(x_offset), 2) + |
pow(static_cast<float>(y_offset), 2)) > kMinimumDragDistance; |
+ DLOG(INFO) << start_point_in_screen_.ToString() << " , " |
+ << point_in_screen.ToString(); |
+ DLOG(INFO) << "can start = " << result; |
+ return result; |
} |
void TabDragController::ContinueDragging(const gfx::Point& point_in_screen) { |
TRACE_EVENT1("views", "TabDragController::ContinueDragging", |
"point_in_screen", point_in_screen.ToString()); |
+ DLOG(INFO) << "ContinueDragging... point_in_screen=" |
+ << point_in_screen.ToString(); |
DCHECK(attached_tabstrip_); |
@@ -607,6 +632,14 @@ TabDragController::DragBrowserToNewTabStrip( |
// going to trigger capture lost, which cancels drag. |
attached_tabstrip_->ReleaseDragController(); |
target_tabstrip->OwnDragController(this); |
+ if (!windows_destroy_during_drag) { |
+ Detach(DONT_RELEASE_CAPTURE); |
+ Attach(target_tabstrip, point_in_screen); |
+ // Move the tabs into position. |
+ // MoveAttached(point_in_screen); // assumes !is_dragging_window_ |
+ return DRAG_BROWSER_RESULT_CONTINUE; |
+ } |
+ |
// Disable animations so that we don't see a close animation on aero. |
browser_widget->SetVisibilityChangedAnimationsEnabled(false); |
if (can_release_capture_) |
@@ -822,6 +855,7 @@ TabStrip* TabDragController::GetTargetTabStripForPoint( |
"point_in_screen", point_in_screen.ToString()); |
if (move_only() && attached_tabstrip_) { |
+ DLOG(INFO) << "MoveOnly"; |
// move_only() is intended for touch, in which case we only want to detach |
// if the touch point moves significantly in the vertical distance. |
gfx::Rect tabstrip_bounds = GetViewScreenBounds(attached_tabstrip_); |
@@ -889,6 +923,8 @@ void TabDragController::Attach(TabStrip* attached_tabstrip, |
std::vector<Tab*> tabs = |
GetTabsMatchingDraggedContents(attached_tabstrip_); |
+ bool acquire_capture = true; |
+ |
if (tabs.empty()) { |
// Transitioning from detached to attached to a new tabstrip. Add tabs to |
// the new model. |
@@ -928,6 +964,10 @@ void TabDragController::Attach(TabStrip* attached_tabstrip, |
} |
tabs = GetTabsMatchingDraggedContents(attached_tabstrip_); |
+ |
+ // If the windows are kept, there's no need to re-acquire capture. Instead, |
+ // the TabDragController remains in a MoveLoop. |
+ acquire_capture = windows_destroy_during_drag; |
} |
DCHECK_EQ(tabs.size(), drag_data_.size()); |
for (size_t i = 0; i < drag_data_.size(); ++i) |
@@ -951,7 +991,8 @@ void TabDragController::Attach(TabStrip* attached_tabstrip, |
// Transfer ownership of us to the new tabstrip as well as making sure the |
// window has capture. This is important so that if activation changes the |
// drag isn't prematurely canceled. |
- attached_tabstrip_->GetWidget()->SetCapture(attached_tabstrip_); |
+ if (acquire_capture) |
+ attached_tabstrip_->GetWidget()->SetCapture(attached_tabstrip_); |
attached_tabstrip_->OwnDragController(this); |
} |
@@ -1744,6 +1785,7 @@ Browser* TabDragController::CreateBrowserForDrag( |
SetWindowPositionManaged(browser->window()->GetNativeWindow(), false); |
// If the window is created maximized then the bounds we supplied are ignored. |
// We need to reset them again so they are honored. |
+ DLOG(INFO) << "SetBounds -> " << new_bounds.ToString(); |
browser->window()->SetBounds(new_bounds); |
return browser; |