| 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 29 matching lines...) Expand all Loading... |
| 40 #include "ui/base/resource/resource_bundle.h" | 40 #include "ui/base/resource/resource_bundle.h" |
| 41 #include "ui/gfx/canvas.h" | 41 #include "ui/gfx/canvas.h" |
| 42 #include "ui/gfx/image/image_skia.h" | 42 #include "ui/gfx/image/image_skia.h" |
| 43 #include "ui/gfx/screen.h" | 43 #include "ui/gfx/screen.h" |
| 44 #include "ui/views/widget/root_view.h" | 44 #include "ui/views/widget/root_view.h" |
| 45 #include "ui/views/widget/widget.h" | 45 #include "ui/views/widget/widget.h" |
| 46 | 46 |
| 47 #if defined(USE_ASH) | 47 #if defined(USE_ASH) |
| 48 #include "ash/shell.h" | 48 #include "ash/shell.h" |
| 49 #include "ash/wm/property_util.h" | 49 #include "ash/wm/property_util.h" |
| 50 #include "ash/wm/window_util.h" | |
| 51 #include "ui/aura/env.h" | 50 #include "ui/aura/env.h" |
| 52 #include "ui/aura/root_window.h" | 51 #include "ui/aura/root_window.h" |
| 53 #include "ui/base/gestures/gesture_recognizer.h" | 52 #include "ui/base/gestures/gesture_recognizer.h" |
| 54 #endif | 53 #endif |
| 55 | 54 |
| 56 using content::OpenURLParams; | 55 using content::OpenURLParams; |
| 57 using content::UserMetricsAction; | 56 using content::UserMetricsAction; |
| 58 using content::WebContents; | 57 using content::WebContents; |
| 59 | 58 |
| 60 static const int kHorizontalMoveThreshold = 16; // Pixels. | 59 static const int kHorizontalMoveThreshold = 16; // Pixels. |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 | 184 |
| 186 DISALLOW_COPY_AND_ASSIGN(DockView); | 185 DISALLOW_COPY_AND_ASSIGN(DockView); |
| 187 }; | 186 }; |
| 188 | 187 |
| 189 void SetTrackedByWorkspace(gfx::NativeWindow window, bool value) { | 188 void SetTrackedByWorkspace(gfx::NativeWindow window, bool value) { |
| 190 #if defined(USE_ASH) | 189 #if defined(USE_ASH) |
| 191 ash::SetTrackedByWorkspace(window, value); | 190 ash::SetTrackedByWorkspace(window, value); |
| 192 #endif | 191 #endif |
| 193 } | 192 } |
| 194 | 193 |
| 195 void SetWindowPositionManaged(gfx::NativeWindow window, bool value) { | |
| 196 #if defined(USE_ASH) | |
| 197 ash::wm::SetWindowPositionManaged(window, value); | |
| 198 #endif | |
| 199 } | |
| 200 | |
| 201 bool ShouldDetachIntoNewBrowser() { | 194 bool ShouldDetachIntoNewBrowser() { |
| 202 #if defined(USE_AURA) | 195 #if defined(USE_AURA) |
| 203 return true; | 196 return true; |
| 204 #else | 197 #else |
| 205 return CommandLine::ForCurrentProcess()->HasSwitch( | 198 return CommandLine::ForCurrentProcess()->HasSwitch( |
| 206 switches::kTabBrowserDragging); | 199 switches::kTabBrowserDragging); |
| 207 #endif | 200 #endif |
| 208 } | 201 } |
| 209 | 202 |
| 210 // Returns true if |bounds| contains the y-coordinate |y|. The y-coordinate | 203 // Returns true if |bounds| contains the y-coordinate |y|. The y-coordinate |
| 211 // of |bounds| is adjusted by |vertical_adjustment|. | 204 // of |bounds| is adjusted by |vertical_adjustment|. |
| 212 bool DoesRectContainVerticalPointExpanded( | 205 bool DoesRectContainVerticalPointExpanded( |
| 213 const gfx::Rect& bounds, | 206 const gfx::Rect& bounds, |
| 214 int vertical_adjustment, | 207 int vertical_adjustment, |
| 215 int y) { | 208 int y) { |
| 216 int upper_threshold = bounds.bottom() + vertical_adjustment; | 209 int upper_threshold = bounds.bottom() + vertical_adjustment; |
| 217 int lower_threshold = bounds.y() - vertical_adjustment; | 210 int lower_threshold = bounds.y() - vertical_adjustment; |
| 218 return y >= lower_threshold && y <= upper_threshold; | 211 return y >= lower_threshold && y <= upper_threshold; |
| 219 } | 212 } |
| 220 | 213 |
| 221 // WidgetObserver implementation that resets the window position managed | |
| 222 // property on Show. | |
| 223 // We're forced to do this here since BrowserFrameAura resets the 'window | |
| 224 // position managed' property during a show and we need the property set to | |
| 225 // false before WorkspaceLayoutManager2 sees the visibility change. | |
| 226 class WindowPositionManagedUpdater : public views::WidgetObserver { | |
| 227 public: | |
| 228 virtual void OnWidgetVisibilityChanged(views::Widget* widget, | |
| 229 bool visible) OVERRIDE { | |
| 230 SetWindowPositionManaged(widget->GetNativeView(), false); | |
| 231 } | |
| 232 }; | |
| 233 | |
| 234 } // namespace | 214 } // namespace |
| 235 | 215 |
| 236 /////////////////////////////////////////////////////////////////////////////// | 216 /////////////////////////////////////////////////////////////////////////////// |
| 237 // DockDisplayer | 217 // DockDisplayer |
| 238 | 218 |
| 239 // DockDisplayer is responsible for giving the user a visual indication of a | 219 // DockDisplayer is responsible for giving the user a visual indication of a |
| 240 // possible dock position (as represented by DockInfo). DockDisplayer shows | 220 // possible dock position (as represented by DockInfo). DockDisplayer shows |
| 241 // a window with a DockView in it. Two animations are used that correspond to | 221 // a window with a DockView in it. Two animations are used that correspond to |
| 242 // the state of DockInfo::in_enable_area. | 222 // the state of DockInfo::in_enable_area. |
| 243 class TabDragController::DockDisplayer : public ui::AnimationDelegate { | 223 class TabDragController::DockDisplayer : public ui::AnimationDelegate { |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 TabDragController::~TabDragController() { | 366 TabDragController::~TabDragController() { |
| 387 if (instance_ == this) | 367 if (instance_ == this) |
| 388 instance_ = NULL; | 368 instance_ = NULL; |
| 389 | 369 |
| 390 if (destroyed_) | 370 if (destroyed_) |
| 391 *destroyed_ = true; | 371 *destroyed_ = true; |
| 392 | 372 |
| 393 if (move_loop_widget_) { | 373 if (move_loop_widget_) { |
| 394 move_loop_widget_->RemoveObserver(this); | 374 move_loop_widget_->RemoveObserver(this); |
| 395 SetTrackedByWorkspace(move_loop_widget_->GetNativeView(), true); | 375 SetTrackedByWorkspace(move_loop_widget_->GetNativeView(), true); |
| 396 SetWindowPositionManaged(move_loop_widget_->GetNativeView(), true); | |
| 397 } | 376 } |
| 398 | 377 |
| 399 if (source_tabstrip_ && detach_into_browser_) | 378 if (source_tabstrip_ && detach_into_browser_) |
| 400 GetModel(source_tabstrip_)->RemoveObserver(this); | 379 GetModel(source_tabstrip_)->RemoveObserver(this); |
| 401 | 380 |
| 402 MessageLoopForUI::current()->RemoveObserver(this); | 381 MessageLoopForUI::current()->RemoveObserver(this); |
| 403 | 382 |
| 404 // Need to delete the view here manually _before_ we reset the dragged | 383 // Need to delete the view here manually _before_ we reset the dragged |
| 405 // contents to NULL, otherwise if the view is animating to its destination | 384 // contents to NULL, otherwise if the view is animating to its destination |
| 406 // bounds, it won't be able to clean up properly since its cleanup routine | 385 // bounds, it won't be able to clean up properly since its cleanup routine |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 target_tabstrip->OwnDragController(this); | 822 target_tabstrip->OwnDragController(this); |
| 844 // Disable animations so that we don't see a close animation on aero. | 823 // Disable animations so that we don't see a close animation on aero. |
| 845 browser_widget->SetVisibilityChangedAnimationsEnabled(false); | 824 browser_widget->SetVisibilityChangedAnimationsEnabled(false); |
| 846 // For aura we can't release capture, otherwise it'll cancel a gesture. | 825 // For aura we can't release capture, otherwise it'll cancel a gesture. |
| 847 // Instead we have to directly change capture. | 826 // Instead we have to directly change capture. |
| 848 #if !defined(USE_ASH) | 827 #if !defined(USE_ASH) |
| 849 browser_widget->ReleaseCapture(); | 828 browser_widget->ReleaseCapture(); |
| 850 #else | 829 #else |
| 851 target_tabstrip->GetWidget()->SetCapture(attached_tabstrip_); | 830 target_tabstrip->GetWidget()->SetCapture(attached_tabstrip_); |
| 852 #endif | 831 #endif |
| 853 // The window is going away. Since the drag is still on going we don't want | |
| 854 // that to effect the position of any windows. | |
| 855 SetWindowPositionManaged(browser_widget->GetNativeView(), false); | |
| 856 | |
| 857 // EndMoveLoop is going to snap the window back to its original location. | 832 // EndMoveLoop is going to snap the window back to its original location. |
| 858 // Hide it so users don't see this. | 833 // Hide it so users don't see this. |
| 859 browser_widget->Hide(); | 834 browser_widget->Hide(); |
| 860 browser_widget->EndMoveLoop(); | 835 browser_widget->EndMoveLoop(); |
| 861 | 836 |
| 862 // Ideally we would always swap the tabs now, but on windows it seems that | 837 // Ideally we would always swap the tabs now, but on windows it seems that |
| 863 // running the move loop implicitly activates the window when done, leading | 838 // running the move loop implicitly activates the window when done, leading |
| 864 // to all sorts of flicker. So, on windows, instead we process the move | 839 // to all sorts of flicker. So, on windows, instead we process the move |
| 865 // after the loop completes. But on chromeos, we can do tab swapping now to | 840 // after the loop completes. But on chromeos, we can do tab swapping now to |
| 866 // avoid the tab flashing issue(crbug.com/116329). | 841 // avoid the tab flashing issue(crbug.com/116329). |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1317 attached_tabstrip_, point_in_screen, &drag_offset, &drag_bounds); | 1292 attached_tabstrip_, point_in_screen, &drag_offset, &drag_bounds); |
| 1318 Detach(DONT_RELEASE_CAPTURE); | 1293 Detach(DONT_RELEASE_CAPTURE); |
| 1319 BrowserView* dragged_browser_view = | 1294 BrowserView* dragged_browser_view = |
| 1320 BrowserView::GetBrowserViewForBrowser(browser); | 1295 BrowserView::GetBrowserViewForBrowser(browser); |
| 1321 dragged_browser_view->GetWidget()->SetVisibilityChangedAnimationsEnabled( | 1296 dragged_browser_view->GetWidget()->SetVisibilityChangedAnimationsEnabled( |
| 1322 false); | 1297 false); |
| 1323 Attach(dragged_browser_view->tabstrip(), gfx::Point()); | 1298 Attach(dragged_browser_view->tabstrip(), gfx::Point()); |
| 1324 // TODO: come up with a cleaner way to do this. | 1299 // TODO: come up with a cleaner way to do this. |
| 1325 attached_tabstrip_->SetTabBoundsForDrag(drag_bounds); | 1300 attached_tabstrip_->SetTabBoundsForDrag(drag_bounds); |
| 1326 | 1301 |
| 1327 WindowPositionManagedUpdater updater; | |
| 1328 dragged_browser_view->GetWidget()->AddObserver(&updater); | |
| 1329 browser->window()->Show(); | 1302 browser->window()->Show(); |
| 1330 dragged_browser_view->GetWidget()->RemoveObserver(&updater); | |
| 1331 | |
| 1332 browser->window()->Activate(); | 1303 browser->window()->Activate(); |
| 1333 dragged_browser_view->GetWidget()->SetVisibilityChangedAnimationsEnabled( | 1304 dragged_browser_view->GetWidget()->SetVisibilityChangedAnimationsEnabled( |
| 1334 true); | 1305 true); |
| 1335 RunMoveLoop(drag_offset); | 1306 RunMoveLoop(drag_offset); |
| 1336 } | 1307 } |
| 1337 | 1308 |
| 1338 void TabDragController::RunMoveLoop(const gfx::Point& drag_offset) { | 1309 void TabDragController::RunMoveLoop(const gfx::Point& drag_offset) { |
| 1339 // If the user drags the whole window we'll assume they are going to attach to | 1310 // If the user drags the whole window we'll assume they are going to attach to |
| 1340 // another window and therefor want to reorder. | 1311 // another window and therefor want to reorder. |
| 1341 move_behavior_ = REORDER; | 1312 move_behavior_ = REORDER; |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1578 | 1549 |
| 1579 bring_to_front_timer_.Stop(); | 1550 bring_to_front_timer_.Stop(); |
| 1580 move_stacked_timer_.Stop(); | 1551 move_stacked_timer_.Stop(); |
| 1581 | 1552 |
| 1582 if (is_dragging_window_) { | 1553 if (is_dragging_window_) { |
| 1583 // SetTrackedByWorkspace() may call us back (by way of the window bounds | 1554 // SetTrackedByWorkspace() may call us back (by way of the window bounds |
| 1584 // changing). Set |waiting_for_run_loop_to_exit_| here so that if that | 1555 // changing). Set |waiting_for_run_loop_to_exit_| here so that if that |
| 1585 // happens we ignore it. | 1556 // happens we ignore it. |
| 1586 waiting_for_run_loop_to_exit_ = true; | 1557 waiting_for_run_loop_to_exit_ = true; |
| 1587 | 1558 |
| 1588 if (type == NORMAL || (type == TAB_DESTROYED && drag_data_.size() > 1)) { | 1559 if (type == NORMAL || (type == TAB_DESTROYED && drag_data_.size() > 1)) |
| 1589 SetTrackedByWorkspace(GetAttachedBrowserWidget()->GetNativeView(), true); | 1560 SetTrackedByWorkspace(GetAttachedBrowserWidget()->GetNativeView(), true); |
| 1590 SetWindowPositionManaged(GetAttachedBrowserWidget()->GetNativeView(), | |
| 1591 true); | |
| 1592 } | |
| 1593 | 1561 |
| 1594 // End the nested drag loop. | 1562 // End the nested drag loop. |
| 1595 GetAttachedBrowserWidget()->EndMoveLoop(); | 1563 GetAttachedBrowserWidget()->EndMoveLoop(); |
| 1596 } | 1564 } |
| 1597 | 1565 |
| 1598 // Hide the current dock controllers. | 1566 // Hide the current dock controllers. |
| 1599 for (size_t i = 0; i < dock_controllers_.size(); ++i) { | 1567 for (size_t i = 0; i < dock_controllers_.size(); ++i) { |
| 1600 // Be sure and clear the controller first, that way if Hide ends up | 1568 // Be sure and clear the controller first, that way if Hide ends up |
| 1601 // deleting the controller it won't call us back. | 1569 // deleting the controller it won't call us back. |
| 1602 dock_controllers_[i]->clear_controller(); | 1570 dock_controllers_[i]->clear_controller(); |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1995 default: | 1963 default: |
| 1996 break; // Nothing to do for DETACH_ABOVE_OR_BELOW. | 1964 break; // Nothing to do for DETACH_ABOVE_OR_BELOW. |
| 1997 } | 1965 } |
| 1998 | 1966 |
| 1999 *drag_offset = point_in_screen.Subtract(new_bounds.origin()); | 1967 *drag_offset = point_in_screen.Subtract(new_bounds.origin()); |
| 2000 | 1968 |
| 2001 Browser::CreateParams create_params(drag_data_[0].contents->profile()); | 1969 Browser::CreateParams create_params(drag_data_[0].contents->profile()); |
| 2002 create_params.initial_bounds = new_bounds; | 1970 create_params.initial_bounds = new_bounds; |
| 2003 Browser* browser = new Browser(create_params); | 1971 Browser* browser = new Browser(create_params); |
| 2004 SetTrackedByWorkspace(browser->window()->GetNativeWindow(), false); | 1972 SetTrackedByWorkspace(browser->window()->GetNativeWindow(), false); |
| 2005 SetWindowPositionManaged(browser->window()->GetNativeWindow(), false); | |
| 2006 // If the window is created maximized then the bounds we supplied are ignored. | 1973 // If the window is created maximized then the bounds we supplied are ignored. |
| 2007 // We need to reset them again so they are honored. | 1974 // We need to reset them again so they are honored. |
| 2008 browser->window()->SetBounds(new_bounds); | 1975 browser->window()->SetBounds(new_bounds); |
| 2009 return browser; | 1976 return browser; |
| 2010 } | 1977 } |
| 2011 | 1978 |
| 2012 gfx::Point TabDragController::GetCursorScreenPoint() { | 1979 gfx::Point TabDragController::GetCursorScreenPoint() { |
| 2013 #if defined(USE_ASH) | 1980 #if defined(USE_ASH) |
| 2014 views::Widget* widget = GetAttachedBrowserWidget(); | 1981 views::Widget* widget = GetAttachedBrowserWidget(); |
| 2015 DCHECK(widget); | 1982 DCHECK(widget); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2030 gfx::Point TabDragController::GetWindowOffset( | 1997 gfx::Point TabDragController::GetWindowOffset( |
| 2031 const gfx::Point& point_in_screen) { | 1998 const gfx::Point& point_in_screen) { |
| 2032 TabStrip* owning_tabstrip = (attached_tabstrip_ && detach_into_browser_) ? | 1999 TabStrip* owning_tabstrip = (attached_tabstrip_ && detach_into_browser_) ? |
| 2033 attached_tabstrip_ : source_tabstrip_; | 2000 attached_tabstrip_ : source_tabstrip_; |
| 2034 views::View* toplevel_view = owning_tabstrip->GetWidget()->GetContentsView(); | 2001 views::View* toplevel_view = owning_tabstrip->GetWidget()->GetContentsView(); |
| 2035 | 2002 |
| 2036 gfx::Point offset = point_in_screen; | 2003 gfx::Point offset = point_in_screen; |
| 2037 views::View::ConvertPointFromScreen(toplevel_view, &offset); | 2004 views::View::ConvertPointFromScreen(toplevel_view, &offset); |
| 2038 return offset; | 2005 return offset; |
| 2039 } | 2006 } |
| OLD | NEW |