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

Side by Side Diff: chrome/browser/ui/views/tabs/tab_drag_controller.cc

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

Powered by Google App Engine
This is Rietveld 408576698