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/callback.h" | 10 #include "base/callback.h" |
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
477 | 477 |
478 if (!started_drag_) { | 478 if (!started_drag_) { |
479 if (!CanStartDrag(real_point_in_screen)) | 479 if (!CanStartDrag(real_point_in_screen)) |
480 return; // User hasn't dragged far enough yet. | 480 return; // User hasn't dragged far enough yet. |
481 | 481 |
482 started_drag_ = true; | 482 started_drag_ = true; |
483 SaveFocus(); | 483 SaveFocus(); |
484 Attach(source_tabstrip_, gfx::Point()); | 484 Attach(source_tabstrip_, gfx::Point()); |
485 if (detach_into_browser_ && static_cast<int>(drag_data_.size()) == | 485 if (detach_into_browser_ && static_cast<int>(drag_data_.size()) == |
486 GetModel(source_tabstrip_)->count()) { | 486 GetModel(source_tabstrip_)->count()) { |
487 RunMoveLoop(); // Runs a nested loop, returning when done. | 487 // TODO(erg): The following calculation is off; it only affects the |
488 // linux_aura port though. | |
489 RunMoveLoop(mouse_offset_); // Runs a nested loop, returning when done. | |
sky
2012/08/14 22:49:23
I'm a bit confused. What location are you trying t
Elliot Glaysher
2012/08/14 22:55:00
The offset from the top left corner of the window
| |
488 return; | 490 return; |
489 } | 491 } |
490 } | 492 } |
491 | 493 |
492 ContinueDragging(real_point_in_screen); | 494 ContinueDragging(real_point_in_screen); |
493 } | 495 } |
494 | 496 |
495 void TabDragController::EndDrag(bool canceled) { | 497 void TabDragController::EndDrag(bool canceled) { |
496 EndDragImpl(canceled && source_tabstrip_ ? CANCELED : NORMAL); | 498 EndDragImpl(canceled && source_tabstrip_ ? CANCELED : NORMAL); |
497 } | 499 } |
(...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1259 attached_tabstrip_ = NULL; | 1261 attached_tabstrip_ = NULL; |
1260 } | 1262 } |
1261 | 1263 |
1262 void TabDragController::DetachIntoNewBrowserAndRunMoveLoop( | 1264 void TabDragController::DetachIntoNewBrowserAndRunMoveLoop( |
1263 const gfx::Point& point_in_screen) { | 1265 const gfx::Point& point_in_screen) { |
1264 if (GetModel(attached_tabstrip_)->count() == | 1266 if (GetModel(attached_tabstrip_)->count() == |
1265 static_cast<int>(drag_data_.size())) { | 1267 static_cast<int>(drag_data_.size())) { |
1266 // All the tabs in a browser are being dragged but all the tabs weren't | 1268 // All the tabs in a browser are being dragged but all the tabs weren't |
1267 // initially being dragged. For this to happen the user would have to | 1269 // initially being dragged. For this to happen the user would have to |
1268 // start dragging a set of tabs, the other tabs close, then detach. | 1270 // start dragging a set of tabs, the other tabs close, then detach. |
1269 RunMoveLoop(); | 1271 |
1272 // TODO(erg): This offset isn't perfect on linux_aura. | |
1273 RunMoveLoop(mouse_offset_); | |
1270 return; | 1274 return; |
1271 } | 1275 } |
1272 | 1276 |
1273 // Create a new browser to house the dragged tabs and have the OS run a move | 1277 // Create a new browser to house the dragged tabs and have the OS run a move |
1274 // loop. | 1278 // loop. |
1275 | 1279 |
1276 gfx::Point attached_point = GetAttachedDragPoint(point_in_screen); | 1280 gfx::Point attached_point = GetAttachedDragPoint(point_in_screen); |
1277 | 1281 |
1278 // Calculate the bounds for the tabs from the attached_tab_strip. We do this | 1282 // Calculate the bounds for the tabs from the attached_tab_strip. We do this |
1279 // so that the tabs don't change size when detached. | 1283 // so that the tabs don't change size when detached. |
1280 std::vector<gfx::Rect> drag_bounds = | 1284 std::vector<gfx::Rect> drag_bounds = |
1281 CalculateBoundsForDraggedTabs(attached_point.x()); | 1285 CalculateBoundsForDraggedTabs(attached_point.x()); |
1282 | 1286 |
1287 gfx::Point drag_offset; | |
1283 Browser* browser = CreateBrowserForDrag( | 1288 Browser* browser = CreateBrowserForDrag( |
1284 attached_tabstrip_, point_in_screen, &drag_bounds); | 1289 attached_tabstrip_, point_in_screen, &drag_offset, &drag_bounds); |
1285 Detach(DONT_RELEASE_CAPTURE); | 1290 Detach(DONT_RELEASE_CAPTURE); |
1286 BrowserView* dragged_browser_view = | 1291 BrowserView* dragged_browser_view = |
1287 BrowserView::GetBrowserViewForBrowser(browser); | 1292 BrowserView::GetBrowserViewForBrowser(browser); |
1288 dragged_browser_view->GetWidget()->SetVisibilityChangedAnimationsEnabled( | 1293 dragged_browser_view->GetWidget()->SetVisibilityChangedAnimationsEnabled( |
1289 false); | 1294 false); |
1290 Attach(dragged_browser_view->tabstrip(), gfx::Point()); | 1295 Attach(dragged_browser_view->tabstrip(), gfx::Point()); |
1291 // TODO: come up with a cleaner way to do this. | 1296 // TODO: come up with a cleaner way to do this. |
1292 attached_tabstrip_->SetTabBoundsForDrag(drag_bounds); | 1297 attached_tabstrip_->SetTabBoundsForDrag(drag_bounds); |
1293 | 1298 |
1294 browser->window()->Show(); | 1299 browser->window()->Show(); |
1295 browser->window()->Activate(); | 1300 browser->window()->Activate(); |
1296 dragged_browser_view->GetWidget()->SetVisibilityChangedAnimationsEnabled( | 1301 dragged_browser_view->GetWidget()->SetVisibilityChangedAnimationsEnabled( |
1297 true); | 1302 true); |
1298 RunMoveLoop(); | 1303 RunMoveLoop(drag_offset); |
1299 } | 1304 } |
1300 | 1305 |
1301 void TabDragController::RunMoveLoop() { | 1306 void TabDragController::RunMoveLoop(const gfx::Point& drag_offset) { |
1302 // If the user drags the whole window we'll assume they are going to attach to | 1307 // If the user drags the whole window we'll assume they are going to attach to |
1303 // another window and therefor want to reorder. | 1308 // another window and therefor want to reorder. |
1304 move_behavior_ = REORDER; | 1309 move_behavior_ = REORDER; |
1305 | 1310 |
1306 move_loop_widget_ = GetAttachedBrowserWidget(); | 1311 move_loop_widget_ = GetAttachedBrowserWidget(); |
1307 DCHECK(move_loop_widget_); | 1312 DCHECK(move_loop_widget_); |
1308 move_loop_widget_->AddObserver(this); | 1313 move_loop_widget_->AddObserver(this); |
1309 is_dragging_window_ = true; | 1314 is_dragging_window_ = true; |
1310 bool destroyed = false; | 1315 bool destroyed = false; |
1311 destroyed_ = &destroyed; | 1316 destroyed_ = &destroyed; |
1312 #if !defined(USE_ASH) | 1317 #if !defined(USE_ASH) |
1313 // Running the move loop releases mouse capture on Windows, which triggers | 1318 // Running the move loop releases mouse capture on Windows, which triggers |
1314 // destroying the drag loop. Release mouse capture ourself before this while | 1319 // destroying the drag loop. Release mouse capture ourself before this while |
1315 // the DragController isn't owned by the TabStrip. | 1320 // the DragController isn't owned by the TabStrip. |
1316 attached_tabstrip_->ReleaseDragController(); | 1321 attached_tabstrip_->ReleaseDragController(); |
1317 attached_tabstrip_->GetWidget()->ReleaseCapture(); | 1322 attached_tabstrip_->GetWidget()->ReleaseCapture(); |
1318 attached_tabstrip_->OwnDragController(this); | 1323 attached_tabstrip_->OwnDragController(this); |
1319 #endif | 1324 #endif |
1320 views::Widget::MoveLoopResult result = move_loop_widget_->RunMoveLoop(); | 1325 views::Widget::MoveLoopResult result = |
1326 move_loop_widget_->RunMoveLoop(drag_offset); | |
1321 content::NotificationService::current()->Notify( | 1327 content::NotificationService::current()->Notify( |
1322 chrome::NOTIFICATION_TAB_DRAG_LOOP_DONE, | 1328 chrome::NOTIFICATION_TAB_DRAG_LOOP_DONE, |
1323 content::NotificationService::AllBrowserContextsAndSources(), | 1329 content::NotificationService::AllBrowserContextsAndSources(), |
1324 content::NotificationService::NoDetails()); | 1330 content::NotificationService::NoDetails()); |
1325 | 1331 |
1326 if (destroyed) | 1332 if (destroyed) |
1327 return; | 1333 return; |
1328 destroyed_ = NULL; | 1334 destroyed_ = NULL; |
1329 // Under chromeos we immediately set the |move_loop_widget_| to NULL. | 1335 // Under chromeos we immediately set the |move_loop_widget_| to NULL. |
1330 if (move_loop_widget_) { | 1336 if (move_loop_widget_) { |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1908 drag_data_[i].source_model_index) { | 1914 drag_data_[i].source_model_index) { |
1909 return false; | 1915 return false; |
1910 } | 1916 } |
1911 } | 1917 } |
1912 return true; | 1918 return true; |
1913 } | 1919 } |
1914 | 1920 |
1915 Browser* TabDragController::CreateBrowserForDrag( | 1921 Browser* TabDragController::CreateBrowserForDrag( |
1916 TabStrip* source, | 1922 TabStrip* source, |
1917 const gfx::Point& point_in_screen, | 1923 const gfx::Point& point_in_screen, |
1924 gfx::Point* drag_offset, | |
1918 std::vector<gfx::Rect>* drag_bounds) { | 1925 std::vector<gfx::Rect>* drag_bounds) { |
1919 Browser* browser = new Browser( | 1926 Browser* browser = new Browser( |
1920 Browser::CreateParams(drag_data_[0].contents->profile())); | 1927 Browser::CreateParams(drag_data_[0].contents->profile())); |
1921 gfx::Point center(0, source->height() / 2); | 1928 gfx::Point center(0, source->height() / 2); |
1922 views::View::ConvertPointToWidget(source, ¢er); | 1929 views::View::ConvertPointToWidget(source, ¢er); |
1923 gfx::Rect new_bounds(source->GetWidget()->GetWindowBoundsInScreen()); | 1930 gfx::Rect new_bounds(source->GetWidget()->GetWindowBoundsInScreen()); |
1924 new_bounds.set_y(point_in_screen.y() - center.y()); | 1931 new_bounds.set_y(point_in_screen.y() - center.y()); |
1925 switch (GetDetachPosition(point_in_screen)) { | 1932 switch (GetDetachPosition(point_in_screen)) { |
1926 case DETACH_BEFORE: | 1933 case DETACH_BEFORE: |
1927 new_bounds.set_x(point_in_screen.x() - center.x()); | 1934 new_bounds.set_x(point_in_screen.x() - center.x()); |
1928 new_bounds.Offset(-mouse_offset_.x(), 0); | 1935 new_bounds.Offset(-mouse_offset_.x(), 0); |
1929 break; | 1936 break; |
1930 | 1937 |
1931 case DETACH_AFTER: { | 1938 case DETACH_AFTER: { |
1932 gfx::Point right_edge(source->width(), 0); | 1939 gfx::Point right_edge(source->width(), 0); |
1933 views::View::ConvertPointToWidget(source, &right_edge); | 1940 views::View::ConvertPointToWidget(source, &right_edge); |
1934 new_bounds.set_x(point_in_screen.x() - right_edge.x()); | 1941 new_bounds.set_x(point_in_screen.x() - right_edge.x()); |
1935 new_bounds.Offset(drag_bounds->back().right() - mouse_offset_.x(), 0); | 1942 new_bounds.Offset(drag_bounds->back().right() - mouse_offset_.x(), 0); |
1936 int delta = (*drag_bounds)[0].x(); | 1943 int delta = (*drag_bounds)[0].x(); |
1937 for (size_t i = 0; i < drag_bounds->size(); ++i) | 1944 for (size_t i = 0; i < drag_bounds->size(); ++i) |
1938 (*drag_bounds)[i].Offset(-delta, 0); | 1945 (*drag_bounds)[i].Offset(-delta, 0); |
1939 break; | 1946 break; |
1940 } | 1947 } |
1941 | 1948 |
1942 default: | 1949 default: |
1943 break; // Nothing to do for DETACH_ABOVE_OR_BELOW. | 1950 break; // Nothing to do for DETACH_ABOVE_OR_BELOW. |
1944 } | 1951 } |
1945 | 1952 |
1953 *drag_offset = point_in_screen.Subtract(new_bounds.origin()); | |
1954 | |
1946 SetTrackedByWorkspace(browser->window()->GetNativeWindow(), false); | 1955 SetTrackedByWorkspace(browser->window()->GetNativeWindow(), false); |
1947 browser->window()->SetBounds(new_bounds); | 1956 browser->window()->SetBounds(new_bounds); |
1948 return browser; | 1957 return browser; |
1949 } | 1958 } |
1950 | 1959 |
1951 gfx::Point TabDragController::GetCursorScreenPoint() { | 1960 gfx::Point TabDragController::GetCursorScreenPoint() { |
1952 #if defined(USE_ASH) | 1961 #if defined(USE_ASH) |
1953 views::Widget* widget = GetAttachedBrowserWidget(); | 1962 views::Widget* widget = GetAttachedBrowserWidget(); |
1954 DCHECK(widget); | 1963 DCHECK(widget); |
1955 if (aura::Env::GetInstance()->is_touch_down()) { | 1964 if (aura::Env::GetInstance()->is_touch_down()) { |
1956 aura::Window* widget_window = widget->GetNativeWindow(); | 1965 aura::Window* widget_window = widget->GetNativeWindow(); |
1957 DCHECK(widget_window->GetRootWindow()); | 1966 DCHECK(widget_window->GetRootWindow()); |
1958 gfx::Point touch_point; | 1967 gfx::Point touch_point; |
1959 bool got_touch_point = widget_window->GetRootWindow()-> | 1968 bool got_touch_point = widget_window->GetRootWindow()-> |
1960 gesture_recognizer()->GetLastTouchPointForTarget(widget_window, | 1969 gesture_recognizer()->GetLastTouchPointForTarget(widget_window, |
1961 &touch_point); | 1970 &touch_point); |
1962 DCHECK(got_touch_point); | 1971 DCHECK(got_touch_point); |
1963 return touch_point; | 1972 return touch_point; |
1964 } | 1973 } |
1965 #endif | 1974 #endif |
1966 return gfx::Screen::GetCursorScreenPoint(); | 1975 return gfx::Screen::GetCursorScreenPoint(); |
1967 } | 1976 } |
OLD | NEW |