OLD | NEW |
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 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 | 372 |
373 // On windows SaveFocus() may trigger a capture lost, which destroys us. | 373 // On windows SaveFocus() may trigger a capture lost, which destroys us. |
374 { | 374 { |
375 base::WeakPtr<TabDragController> ref(weak_factory_.GetWeakPtr()); | 375 base::WeakPtr<TabDragController> ref(weak_factory_.GetWeakPtr()); |
376 SaveFocus(); | 376 SaveFocus(); |
377 if (!ref) | 377 if (!ref) |
378 return; | 378 return; |
379 } | 379 } |
380 started_drag_ = true; | 380 started_drag_ = true; |
381 Attach(source_tabstrip_, gfx::Point()); | 381 Attach(source_tabstrip_, gfx::Point()); |
| 382 gfx::Point drag_point_in_screen = point_in_screen; |
382 if (static_cast<int>(drag_data_.size()) == | 383 if (static_cast<int>(drag_data_.size()) == |
383 GetModel(source_tabstrip_)->count()) { | 384 GetModel(source_tabstrip_)->count()) { |
384 if (was_source_maximized_ || was_source_fullscreen_) { | 385 if (was_source_maximized_ || was_source_fullscreen_) { |
385 did_restore_window_ = true; | 386 did_restore_window_ = true; |
386 // When all tabs in a maximized browser are dragged the browser gets | 387 // When all tabs in a maximized browser are dragged the browser gets |
387 // restored during the drag and maximized back when the drag ends. | 388 // restored during the drag and maximized back when the drag ends. |
388 views::Widget* widget = GetAttachedBrowserWidget(); | 389 views::Widget* widget = GetAttachedBrowserWidget(); |
389 const int last_tabstrip_width = attached_tabstrip_->GetTabAreaWidth(); | 390 const int last_tabstrip_width = attached_tabstrip_->GetTabAreaWidth(); |
390 std::vector<gfx::Rect> drag_bounds = CalculateBoundsForDraggedTabs(); | 391 std::vector<gfx::Rect> drag_bounds = CalculateBoundsForDraggedTabs(); |
391 OffsetX(GetAttachedDragPoint(point_in_screen).x(), &drag_bounds); | 392 OffsetX(GetAttachedDragPoint(point_in_screen).x(), &drag_bounds); |
392 gfx::Rect new_bounds(CalculateDraggedBrowserBounds(source_tabstrip_, | 393 gfx::Rect new_bounds(CalculateDraggedBrowserBounds(source_tabstrip_, |
393 point_in_screen, | 394 point_in_screen, |
394 &drag_bounds)); | 395 &drag_bounds)); |
395 new_bounds.Offset(-widget->GetRestoredBounds().x() + | 396 new_bounds.Offset(-widget->GetRestoredBounds().x() + |
396 point_in_screen.x() - | 397 point_in_screen.x() - |
397 mouse_offset_.x(), 0); | 398 mouse_offset_.x(), 0); |
398 widget->SetVisibilityChangedAnimationsEnabled(false); | 399 widget->SetVisibilityChangedAnimationsEnabled(false); |
399 widget->Restore(); | 400 widget->Restore(); |
400 widget->SetBounds(new_bounds); | 401 widget->SetBounds(new_bounds); |
401 AdjustBrowserAndTabBoundsForDrag(last_tabstrip_width, | 402 AdjustBrowserAndTabBoundsForDrag(last_tabstrip_width, |
402 point_in_screen, | 403 point_in_screen, |
403 &drag_bounds); | 404 &drag_bounds); |
404 widget->SetVisibilityChangedAnimationsEnabled(true); | 405 widget->SetVisibilityChangedAnimationsEnabled(true); |
405 } else { | 406 } else { |
| 407 #if !defined(OS_LINUX) || defined(OS_CHROMEOS) |
406 // The user has to move the mouse some amount of pixels before the drag | 408 // The user has to move the mouse some amount of pixels before the drag |
407 // starts. Offset the window by this amount so that the relative offset | 409 // starts. Offset the window by this amount so that the relative offset |
408 // of the initial location is consistent. See crbug.com/518740 | 410 // of the initial location is consistent. See crbug.com/518740 |
409 views::Widget* widget = GetAttachedBrowserWidget(); | 411 views::Widget* widget = GetAttachedBrowserWidget(); |
410 gfx::Rect bounds = widget->GetWindowBoundsInScreen(); | 412 gfx::Rect bounds = widget->GetWindowBoundsInScreen(); |
411 bounds.Offset(point_in_screen.x() - start_point_in_screen_.x(), | 413 bounds.Offset(point_in_screen.x() - start_point_in_screen_.x(), |
412 point_in_screen.y() - start_point_in_screen_.y()); | 414 point_in_screen.y() - start_point_in_screen_.y()); |
413 widget->SetBounds(bounds); | 415 widget->SetBounds(bounds); |
| 416 #else |
| 417 // Linux does not need the window offset behavior above because all drag |
| 418 // implementations move windows relative to a passed-in cursor position |
| 419 // instead of the implicit current cursor position like on Windows. |
| 420 drag_point_in_screen = start_point_in_screen_; |
| 421 #endif |
414 } | 422 } |
415 RunMoveLoop(GetWindowOffset(point_in_screen)); | 423 RunMoveLoop(GetWindowOffset(drag_point_in_screen)); |
416 return; | 424 return; |
417 } | 425 } |
418 } | 426 } |
419 | 427 |
420 if (ContinueDragging(point_in_screen) == Liveness::DELETED) | 428 if (ContinueDragging(point_in_screen) == Liveness::DELETED) |
421 return; | 429 return; |
422 } | 430 } |
423 | 431 |
424 void TabDragController::EndDrag(EndDragReason reason) { | 432 void TabDragController::EndDrag(EndDragReason reason) { |
425 TRACE_EVENT0("views", "TabDragController::EndDrag"); | 433 TRACE_EVENT0("views", "TabDragController::EndDrag"); |
(...skipping 1412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1838 // TODO(pkotwicz): Fix this properly (crbug.com/358482) | 1846 // TODO(pkotwicz): Fix this properly (crbug.com/358482) |
1839 for (auto* browser : *BrowserList::GetInstance()) { | 1847 for (auto* browser : *BrowserList::GetInstance()) { |
1840 if (browser->tab_strip_model()->empty()) | 1848 if (browser->tab_strip_model()->empty()) |
1841 exclude.insert(browser->window()->GetNativeWindow()); | 1849 exclude.insert(browser->window()->GetNativeWindow()); |
1842 } | 1850 } |
1843 #endif | 1851 #endif |
1844 base::WeakPtr<TabDragController> ref(weak_factory_.GetWeakPtr()); | 1852 base::WeakPtr<TabDragController> ref(weak_factory_.GetWeakPtr()); |
1845 *window = window_finder_->GetLocalProcessWindowAtPoint(screen_point, exclude); | 1853 *window = window_finder_->GetLocalProcessWindowAtPoint(screen_point, exclude); |
1846 return ref ? Liveness::ALIVE : Liveness::DELETED; | 1854 return ref ? Liveness::ALIVE : Liveness::DELETED; |
1847 } | 1855 } |
OLD | NEW |