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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 105 |
106 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 106 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
107 | 107 |
108 gfx::ImageSkia* high_icon = rb.GetImageSkiaNamed(IDR_DOCK_HIGH); | 108 gfx::ImageSkia* high_icon = rb.GetImageSkiaNamed(IDR_DOCK_HIGH); |
109 gfx::ImageSkia* wide_icon = rb.GetImageSkiaNamed(IDR_DOCK_WIDE); | 109 gfx::ImageSkia* wide_icon = rb.GetImageSkiaNamed(IDR_DOCK_WIDE); |
110 | 110 |
111 canvas->Save(); | 111 canvas->Save(); |
112 bool rtl_ui = base::i18n::IsRTL(); | 112 bool rtl_ui = base::i18n::IsRTL(); |
113 if (rtl_ui) { | 113 if (rtl_ui) { |
114 // Flip canvas to draw the mirrored tab images for RTL UI. | 114 // Flip canvas to draw the mirrored tab images for RTL UI. |
115 canvas->Translate(gfx::Point(width(), 0)); | 115 canvas->Translate(gfx::Vector2d(width(), 0)); |
116 canvas->Scale(-1, 1); | 116 canvas->Scale(-1, 1); |
117 } | 117 } |
118 int x_of_active_tab = width() / 2 + kTabSpacing / 2; | 118 int x_of_active_tab = width() / 2 + kTabSpacing / 2; |
119 int x_of_inactive_tab = width() / 2 - high_icon->width() - kTabSpacing / 2; | 119 int x_of_inactive_tab = width() / 2 - high_icon->width() - kTabSpacing / 2; |
120 switch (type_) { | 120 switch (type_) { |
121 case DockInfo::LEFT_OF_WINDOW: | 121 case DockInfo::LEFT_OF_WINDOW: |
122 case DockInfo::LEFT_HALF: | 122 case DockInfo::LEFT_HALF: |
123 if (!rtl_ui) | 123 if (!rtl_ui) |
124 std::swap(x_of_active_tab, x_of_inactive_tab); | 124 std::swap(x_of_active_tab, x_of_inactive_tab); |
125 canvas->DrawImageInt(*high_icon, x_of_active_tab, | 125 canvas->DrawImageInt(*high_icon, x_of_active_tab, |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 | 497 |
498 if (!started_drag_) { | 498 if (!started_drag_) { |
499 if (!CanStartDrag(real_point_in_screen)) | 499 if (!CanStartDrag(real_point_in_screen)) |
500 return; // User hasn't dragged far enough yet. | 500 return; // User hasn't dragged far enough yet. |
501 | 501 |
502 started_drag_ = true; | 502 started_drag_ = true; |
503 SaveFocus(); | 503 SaveFocus(); |
504 Attach(source_tabstrip_, gfx::Point()); | 504 Attach(source_tabstrip_, gfx::Point()); |
505 if (detach_into_browser_ && static_cast<int>(drag_data_.size()) == | 505 if (detach_into_browser_ && static_cast<int>(drag_data_.size()) == |
506 GetModel(source_tabstrip_)->count()) { | 506 GetModel(source_tabstrip_)->count()) { |
507 gfx::Point dragged_view_point = GetWindowOffset(point_in_screen); | 507 RunMoveLoop(GetWindowOffset(point_in_screen)); |
508 RunMoveLoop(dragged_view_point); | |
509 return; | 508 return; |
510 } | 509 } |
511 } | 510 } |
512 | 511 |
513 ContinueDragging(real_point_in_screen); | 512 ContinueDragging(real_point_in_screen); |
514 } | 513 } |
515 | 514 |
516 void TabDragController::EndDrag(EndDragReason reason) { | 515 void TabDragController::EndDrag(EndDragReason reason) { |
517 // If we're dragging a window ignore capture lost since it'll ultimately | 516 // If we're dragging a window ignore capture lost since it'll ultimately |
518 // trigger the move loop to end and we'll revert the drag when RunMoveLoop() | 517 // trigger the move loop to end and we'll revert the drag when RunMoveLoop() |
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1298 attached_tabstrip_ = NULL; | 1297 attached_tabstrip_ = NULL; |
1299 } | 1298 } |
1300 | 1299 |
1301 void TabDragController::DetachIntoNewBrowserAndRunMoveLoop( | 1300 void TabDragController::DetachIntoNewBrowserAndRunMoveLoop( |
1302 const gfx::Point& point_in_screen) { | 1301 const gfx::Point& point_in_screen) { |
1303 if (GetModel(attached_tabstrip_)->count() == | 1302 if (GetModel(attached_tabstrip_)->count() == |
1304 static_cast<int>(drag_data_.size())) { | 1303 static_cast<int>(drag_data_.size())) { |
1305 // All the tabs in a browser are being dragged but all the tabs weren't | 1304 // All the tabs in a browser are being dragged but all the tabs weren't |
1306 // initially being dragged. For this to happen the user would have to | 1305 // initially being dragged. For this to happen the user would have to |
1307 // start dragging a set of tabs, the other tabs close, then detach. | 1306 // start dragging a set of tabs, the other tabs close, then detach. |
1308 gfx::Point dragged_view_point = GetWindowOffset(point_in_screen); | 1307 RunMoveLoop(GetWindowOffset(point_in_screen)); |
1309 RunMoveLoop(dragged_view_point); | |
1310 return; | 1308 return; |
1311 } | 1309 } |
1312 | 1310 |
1313 // Create a new browser to house the dragged tabs and have the OS run a move | 1311 // Create a new browser to house the dragged tabs and have the OS run a move |
1314 // loop. | 1312 // loop. |
1315 | 1313 |
1316 gfx::Point attached_point = GetAttachedDragPoint(point_in_screen); | 1314 gfx::Point attached_point = GetAttachedDragPoint(point_in_screen); |
1317 | 1315 |
1318 // Calculate the bounds for the tabs from the attached_tab_strip. We do this | 1316 // Calculate the bounds for the tabs from the attached_tab_strip. We do this |
1319 // so that the tabs don't change size when detached. | 1317 // so that the tabs don't change size when detached. |
1320 std::vector<gfx::Rect> drag_bounds = | 1318 std::vector<gfx::Rect> drag_bounds = |
1321 CalculateBoundsForDraggedTabs(attached_point.x()); | 1319 CalculateBoundsForDraggedTabs(attached_point.x()); |
1322 | 1320 |
1323 gfx::Point drag_offset; | 1321 gfx::Vector2d drag_offset; |
1324 Browser* browser = CreateBrowserForDrag( | 1322 Browser* browser = CreateBrowserForDrag( |
1325 attached_tabstrip_, point_in_screen, &drag_offset, &drag_bounds); | 1323 attached_tabstrip_, point_in_screen, &drag_offset, &drag_bounds); |
1326 Detach(DONT_RELEASE_CAPTURE); | 1324 Detach(DONT_RELEASE_CAPTURE); |
1327 BrowserView* dragged_browser_view = | 1325 BrowserView* dragged_browser_view = |
1328 BrowserView::GetBrowserViewForBrowser(browser); | 1326 BrowserView::GetBrowserViewForBrowser(browser); |
1329 dragged_browser_view->GetWidget()->SetVisibilityChangedAnimationsEnabled( | 1327 dragged_browser_view->GetWidget()->SetVisibilityChangedAnimationsEnabled( |
1330 false); | 1328 false); |
1331 Attach(dragged_browser_view->tabstrip(), gfx::Point()); | 1329 Attach(dragged_browser_view->tabstrip(), gfx::Point()); |
1332 // TODO: come up with a cleaner way to do this. | 1330 // TODO: come up with a cleaner way to do this. |
1333 attached_tabstrip_->SetTabBoundsForDrag(drag_bounds); | 1331 attached_tabstrip_->SetTabBoundsForDrag(drag_bounds); |
1334 | 1332 |
1335 WindowPositionManagedUpdater updater; | 1333 WindowPositionManagedUpdater updater; |
1336 dragged_browser_view->GetWidget()->AddObserver(&updater); | 1334 dragged_browser_view->GetWidget()->AddObserver(&updater); |
1337 browser->window()->Show(); | 1335 browser->window()->Show(); |
1338 dragged_browser_view->GetWidget()->RemoveObserver(&updater); | 1336 dragged_browser_view->GetWidget()->RemoveObserver(&updater); |
1339 | 1337 |
1340 browser->window()->Activate(); | 1338 browser->window()->Activate(); |
1341 dragged_browser_view->GetWidget()->SetVisibilityChangedAnimationsEnabled( | 1339 dragged_browser_view->GetWidget()->SetVisibilityChangedAnimationsEnabled( |
1342 true); | 1340 true); |
1343 RunMoveLoop(drag_offset); | 1341 RunMoveLoop(drag_offset); |
1344 } | 1342 } |
1345 | 1343 |
1346 void TabDragController::RunMoveLoop(const gfx::Point& drag_offset) { | 1344 void TabDragController::RunMoveLoop(const gfx::Vector2d& drag_offset) { |
1347 // If the user drags the whole window we'll assume they are going to attach to | 1345 // If the user drags the whole window we'll assume they are going to attach to |
1348 // another window and therefor want to reorder. | 1346 // another window and therefor want to reorder. |
1349 move_behavior_ = REORDER; | 1347 move_behavior_ = REORDER; |
1350 | 1348 |
1351 move_loop_widget_ = GetAttachedBrowserWidget(); | 1349 move_loop_widget_ = GetAttachedBrowserWidget(); |
1352 DCHECK(move_loop_widget_); | 1350 DCHECK(move_loop_widget_); |
1353 move_loop_widget_->AddObserver(this); | 1351 move_loop_widget_->AddObserver(this); |
1354 is_dragging_window_ = true; | 1352 is_dragging_window_ = true; |
1355 bool destroyed = false; | 1353 bool destroyed = false; |
1356 destroyed_ = &destroyed; | 1354 destroyed_ = &destroyed; |
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1972 drag_data_[i].source_model_index) { | 1970 drag_data_[i].source_model_index) { |
1973 return false; | 1971 return false; |
1974 } | 1972 } |
1975 } | 1973 } |
1976 return true; | 1974 return true; |
1977 } | 1975 } |
1978 | 1976 |
1979 Browser* TabDragController::CreateBrowserForDrag( | 1977 Browser* TabDragController::CreateBrowserForDrag( |
1980 TabStrip* source, | 1978 TabStrip* source, |
1981 const gfx::Point& point_in_screen, | 1979 const gfx::Point& point_in_screen, |
1982 gfx::Point* drag_offset, | 1980 gfx::Vector2d* drag_offset, |
1983 std::vector<gfx::Rect>* drag_bounds) { | 1981 std::vector<gfx::Rect>* drag_bounds) { |
1984 gfx::Point center(0, source->height() / 2); | 1982 gfx::Point center(0, source->height() / 2); |
1985 views::View::ConvertPointToWidget(source, ¢er); | 1983 views::View::ConvertPointToWidget(source, ¢er); |
1986 gfx::Rect new_bounds(source->GetWidget()->GetWindowBoundsInScreen()); | 1984 gfx::Rect new_bounds(source->GetWidget()->GetWindowBoundsInScreen()); |
1987 new_bounds.set_y(point_in_screen.y() - center.y()); | 1985 new_bounds.set_y(point_in_screen.y() - center.y()); |
1988 switch (GetDetachPosition(point_in_screen)) { | 1986 switch (GetDetachPosition(point_in_screen)) { |
1989 case DETACH_BEFORE: | 1987 case DETACH_BEFORE: |
1990 new_bounds.set_x(point_in_screen.x() - center.x()); | 1988 new_bounds.set_x(point_in_screen.x() - center.x()); |
1991 new_bounds.Offset(-mouse_offset_.x(), 0); | 1989 new_bounds.Offset(-mouse_offset_.x(), 0); |
1992 break; | 1990 break; |
1993 | 1991 |
1994 case DETACH_AFTER: { | 1992 case DETACH_AFTER: { |
1995 gfx::Point right_edge(source->width(), 0); | 1993 gfx::Point right_edge(source->width(), 0); |
1996 views::View::ConvertPointToWidget(source, &right_edge); | 1994 views::View::ConvertPointToWidget(source, &right_edge); |
1997 new_bounds.set_x(point_in_screen.x() - right_edge.x()); | 1995 new_bounds.set_x(point_in_screen.x() - right_edge.x()); |
1998 new_bounds.Offset(drag_bounds->back().right() - mouse_offset_.x(), 0); | 1996 new_bounds.Offset(drag_bounds->back().right() - mouse_offset_.x(), 0); |
1999 int delta = (*drag_bounds)[0].x(); | 1997 int delta = (*drag_bounds)[0].x(); |
2000 for (size_t i = 0; i < drag_bounds->size(); ++i) | 1998 for (size_t i = 0; i < drag_bounds->size(); ++i) |
2001 (*drag_bounds)[i].Offset(-delta, 0); | 1999 (*drag_bounds)[i].Offset(-delta, 0); |
2002 break; | 2000 break; |
2003 } | 2001 } |
2004 | 2002 |
2005 default: | 2003 default: |
2006 break; // Nothing to do for DETACH_ABOVE_OR_BELOW. | 2004 break; // Nothing to do for DETACH_ABOVE_OR_BELOW. |
2007 } | 2005 } |
2008 | 2006 |
2009 *drag_offset = point_in_screen.Subtract(new_bounds.origin()); | 2007 *drag_offset = point_in_screen - new_bounds.origin(); |
2010 | 2008 |
2011 Browser::CreateParams create_params( | 2009 Browser::CreateParams create_params( |
2012 Browser::TYPE_TABBED, | 2010 Browser::TYPE_TABBED, |
2013 drag_data_[0].contents->profile(), | 2011 drag_data_[0].contents->profile(), |
2014 host_desktop_type_); | 2012 host_desktop_type_); |
2015 create_params.initial_bounds = new_bounds; | 2013 create_params.initial_bounds = new_bounds; |
2016 Browser* browser = new Browser(create_params); | 2014 Browser* browser = new Browser(create_params); |
2017 SetTrackedByWorkspace(browser->window()->GetNativeWindow(), false); | 2015 SetTrackedByWorkspace(browser->window()->GetNativeWindow(), false); |
2018 SetWindowPositionManaged(browser->window()->GetNativeWindow(), false); | 2016 SetWindowPositionManaged(browser->window()->GetNativeWindow(), false); |
2019 // If the window is created maximized then the bounds we supplied are ignored. | 2017 // If the window is created maximized then the bounds we supplied are ignored. |
(...skipping 13 matching lines...) Expand all Loading... |
2033 bool got_touch_point = widget_window->GetRootWindow()-> | 2031 bool got_touch_point = widget_window->GetRootWindow()-> |
2034 gesture_recognizer()->GetLastTouchPointForTarget(widget_window, | 2032 gesture_recognizer()->GetLastTouchPointForTarget(widget_window, |
2035 &touch_point); | 2033 &touch_point); |
2036 DCHECK(got_touch_point); | 2034 DCHECK(got_touch_point); |
2037 return touch_point; | 2035 return touch_point; |
2038 } | 2036 } |
2039 #endif | 2037 #endif |
2040 return screen_->GetCursorScreenPoint(); | 2038 return screen_->GetCursorScreenPoint(); |
2041 } | 2039 } |
2042 | 2040 |
2043 gfx::Point TabDragController::GetWindowOffset( | 2041 gfx::Vector2d TabDragController::GetWindowOffset( |
2044 const gfx::Point& point_in_screen) { | 2042 const gfx::Point& point_in_screen) { |
2045 TabStrip* owning_tabstrip = (attached_tabstrip_ && detach_into_browser_) ? | 2043 TabStrip* owning_tabstrip = (attached_tabstrip_ && detach_into_browser_) ? |
2046 attached_tabstrip_ : source_tabstrip_; | 2044 attached_tabstrip_ : source_tabstrip_; |
2047 views::View* toplevel_view = owning_tabstrip->GetWidget()->GetContentsView(); | 2045 views::View* toplevel_view = owning_tabstrip->GetWidget()->GetContentsView(); |
2048 | 2046 |
2049 gfx::Point offset = point_in_screen; | 2047 gfx::Point point = point_in_screen; |
2050 views::View::ConvertPointFromScreen(toplevel_view, &offset); | 2048 views::View::ConvertPointFromScreen(toplevel_view, &point); |
2051 return offset; | 2049 return point.OffsetFromOrigin(); |
2052 } | 2050 } |
OLD | NEW |