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

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

Issue 1259913003: MacViews: Implement Tab Dragging (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@20150529-ViewsBrowser-DisableCertificateDialog
Patch Set: update comments, still a TODO Created 5 years, 4 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 | « no previous file | chrome/browser/ui/views/tabs/window_finder_mac.mm » ('j') | 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 e604c7c47692ca25ace806a1355c3f0626e444db..b963ac3bec4393a7683b4b4b5181e93191faadcf 100644
--- a/chrome/browser/ui/views/tabs/tab_drag_controller.cc
+++ b/chrome/browser/ui/views/tabs/tab_drag_controller.cc
@@ -83,6 +83,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)
+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);
@@ -279,7 +288,12 @@ void TabDragController::Init(
(host_desktop_type_ != chrome::HOST_DESKTOP_TYPE_ASH);
#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;
@@ -351,10 +365,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());
@@ -362,6 +380,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()) ==
@@ -529,13 +548,17 @@ 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_);
@@ -613,6 +636,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_)
@@ -828,6 +859,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_);
@@ -895,6 +927,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.
@@ -934,6 +968,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)
@@ -957,7 +995,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);
}
@@ -1755,6 +1794,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;
« no previous file with comments | « no previous file | chrome/browser/ui/views/tabs/window_finder_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698