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 #import "chrome/browser/ui/cocoa/tabs/tab_strip_drag_controller.h" | 5 #import "chrome/browser/ui/cocoa/tabs/tab_strip_drag_controller.h" |
6 | 6 |
7 #import "base/mac/mac_util.h" | 7 #import "base/mac/mac_util.h" |
8 #include "base/mac/scoped_cftyperef.h" | 8 #include "base/mac/scoped_cftyperef.h" |
9 #import "base/mac/sdk_forward_declarations.h" | 9 #import "base/mac/sdk_forward_declarations.h" |
10 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" | 10 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" |
11 #import "chrome/browser/ui/cocoa/tabs/tab_controller_target.h" | 11 #import "chrome/browser/ui/cocoa/tabs/tab_controller_target.h" |
12 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" | 12 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" |
13 #import "chrome/browser/ui/cocoa/tabs/tab_window_controller.h" | 13 #import "chrome/browser/ui/cocoa/tabs/tab_window_controller.h" |
| 14 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" |
14 | 15 |
15 const CGFloat kTearDistance = 36.0; | 16 const CGFloat kTearDistance = 36.0; |
16 const NSTimeInterval kTearDuration = 0.333; | 17 const NSTimeInterval kTearDuration = 0.333; |
17 | 18 |
18 @interface TabStripDragController (Private) | 19 @interface TabStripDragController (Private) |
19 - (void)resetDragControllers; | 20 - (void)resetDragControllers; |
20 - (NSArray*)dropTargetsForController:(TabWindowController*)dragController; | 21 - (NSArray*)dropTargetsForController:(TabWindowController*)dragController; |
21 - (void)setWindowBackgroundVisibility:(BOOL)shouldBeVisible; | 22 - (void)setWindowBackgroundVisibility:(BOOL)shouldBeVisible; |
22 - (void)endDrag:(NSEvent*)event; | 23 - (void)endDrag:(NSEvent*)event; |
23 - (void)continueDrag:(NSEvent*)event; | 24 - (void)continueDrag:(NSEvent*)event; |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 // Create or identify the dragged controller. | 226 // Create or identify the dragged controller. |
226 if (!draggedController_) { | 227 if (!draggedController_) { |
227 // Get rid of any placeholder remaining in the original source window. | 228 // Get rid of any placeholder remaining in the original source window. |
228 [sourceController_ removePlaceholder]; | 229 [sourceController_ removePlaceholder]; |
229 | 230 |
230 // Detach from the current window and put it in a new window. If there are | 231 // Detach from the current window and put it in a new window. If there are |
231 // no more tabs remaining after detaching, the source window is about to | 232 // no more tabs remaining after detaching, the source window is about to |
232 // go away (it's been autoreleased) so we need to ensure we don't reference | 233 // go away (it's been autoreleased) so we need to ensure we don't reference |
233 // it any more. In that case the new controller becomes our source | 234 // it any more. In that case the new controller becomes our source |
234 // controller. | 235 // controller. |
| 236 NSArray* tabs = [draggedTab_ selected] ? [tabStrip_ selectedViews] |
| 237 : @[ [draggedTab_ tabView] ]; |
235 draggedController_ = | 238 draggedController_ = |
236 [sourceController_ detachTabToNewWindow:[draggedTab_ tabView]]; | 239 [sourceController_ detachTabsToNewWindow:tabs |
| 240 draggedTab:[draggedTab_ tabView]]; |
| 241 |
237 dragWindow_ = [draggedController_ window]; | 242 dragWindow_ = [draggedController_ window]; |
238 [dragWindow_ setAlphaValue:0.0]; | 243 [dragWindow_ setAlphaValue:0.0]; |
239 if (![sourceController_ hasLiveTabs]) { | 244 if (![sourceController_ hasLiveTabs]) { |
240 sourceController_ = draggedController_; | 245 sourceController_ = draggedController_; |
241 sourceWindow_ = dragWindow_; | 246 sourceWindow_ = dragWindow_; |
242 } | 247 } |
243 | 248 |
244 // Disable window animation before calling |orderFront:| when detaching | 249 // Disable window animation before calling |orderFront:| when detaching |
245 // to a new window. | 250 // to a new window. |
246 NSWindowAnimationBehavior savedAnimationBehavior = | 251 NSWindowAnimationBehavior savedAnimationBehavior = |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 | 328 |
324 // If we're not hovering over any window, make the window fully | 329 // If we're not hovering over any window, make the window fully |
325 // opaque. Otherwise, find where the tab might be dropped and insert | 330 // opaque. Otherwise, find where the tab might be dropped and insert |
326 // a placeholder so it appears like it's part of that window. | 331 // a placeholder so it appears like it's part of that window. |
327 if (targetController_) { | 332 if (targetController_) { |
328 if (![[targetController_ window] isKeyWindow]) | 333 if (![[targetController_ window] isKeyWindow]) |
329 [[targetController_ window] orderFront:nil]; | 334 [[targetController_ window] orderFront:nil]; |
330 | 335 |
331 // Compute where placeholder should go and insert it into the | 336 // Compute where placeholder should go and insert it into the |
332 // destination tab strip. | 337 // destination tab strip. |
333 TabView* draggedTabView = (TabView*)[draggedController_ activeTabView]; | 338 // The placeholder frame is the rect that contains all dragged tabs. |
334 NSRect tabFrame = [draggedTabView frame]; | 339 NSRect tabFrame = NSZeroRect; |
| 340 for (NSView* tabView in [draggedController_ tabViews]) { |
| 341 tabFrame = NSUnionRect(tabFrame, [tabView frame]); |
| 342 } |
335 tabFrame.origin = [dragWindow_ convertBaseToScreen:tabFrame.origin]; | 343 tabFrame.origin = [dragWindow_ convertBaseToScreen:tabFrame.origin]; |
336 tabFrame.origin = [[targetController_ window] | 344 tabFrame.origin = [[targetController_ window] |
337 convertScreenToBase:tabFrame.origin]; | 345 convertScreenToBase:tabFrame.origin]; |
338 tabFrame = [[targetController_ tabStripView] | 346 tabFrame = [[targetController_ tabStripView] |
339 convertRect:tabFrame fromView:nil]; | 347 convertRect:tabFrame fromView:nil]; |
340 [targetController_ insertPlaceholderForTab:[draggedTab_ tabView] | 348 [targetController_ insertPlaceholderForTab:[draggedTab_ tabView] |
341 frame:tabFrame]; | 349 frame:tabFrame]; |
342 [targetController_ layoutTabs]; | 350 [targetController_ layoutTabs]; |
343 } else { | 351 } else { |
344 [dragWindow_ makeKeyAndOrderFront:nil]; | 352 [dragWindow_ makeKeyAndOrderFront:nil]; |
(...skipping 27 matching lines...) Expand all Loading... |
372 // dragging. It will show when the next call to -layoutTabs (which happens | 380 // dragging. It will show when the next call to -layoutTabs (which happens |
373 // indirectly by several of the calls below, such as removing the | 381 // indirectly by several of the calls below, such as removing the |
374 // placeholder). | 382 // placeholder). |
375 [draggedController_ showNewTabButton:YES]; | 383 [draggedController_ showNewTabButton:YES]; |
376 | 384 |
377 if (draggingWithinTabStrip_) { | 385 if (draggingWithinTabStrip_) { |
378 if (tabWasDragged_) { | 386 if (tabWasDragged_) { |
379 // Move tab to new location. | 387 // Move tab to new location. |
380 DCHECK([sourceController_ numberOfTabs]); | 388 DCHECK([sourceController_ numberOfTabs]); |
381 TabWindowController* dropController = sourceController_; | 389 TabWindowController* dropController = sourceController_; |
382 [dropController moveTabView:[dropController activeTabView] | 390 [dropController moveTabViews:@[ [dropController activeTabView] ] |
383 fromController:nil]; | 391 fromController:nil]; |
384 } | 392 } |
385 } else if (targetController_) { | 393 } else if (targetController_) { |
386 // Move between windows. If |targetController_| is nil, we're not dropping | 394 // Move between windows. If |targetController_| is nil, we're not dropping |
387 // into any existing window. | 395 // into any existing window. |
388 NSView* draggedTabView = [draggedController_ activeTabView]; | 396 [targetController_ moveTabViews:[draggedController_ tabViews] |
389 [targetController_ moveTabView:draggedTabView | 397 fromController:draggedController_]; |
390 fromController:draggedController_]; | |
391 // Force redraw to avoid flashes of old content before returning to event | 398 // Force redraw to avoid flashes of old content before returning to event |
392 // loop. | 399 // loop. |
393 [[targetController_ window] display]; | 400 [[targetController_ window] display]; |
394 [targetController_ showWindow:nil]; | 401 [targetController_ showWindow:nil]; |
395 [draggedController_ removeOverlay]; | 402 [draggedController_ removeOverlay]; |
396 } else { | 403 } else { |
397 // Only move the window around on screen. Make sure it's set back to | 404 // Only move the window around on screen. Make sure it's set back to |
398 // normal state (fully opaque, has shadow, has key, etc). | 405 // normal state (fully opaque, has shadow, has key, etc). |
399 [draggedController_ removeOverlay]; | 406 [draggedController_ removeOverlay]; |
400 // Don't want to re-show the window if it was closed during the drag. | 407 // Don't want to re-show the window if it was closed during the drag. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 [[targetController_ window] makeMainWindow]; | 476 [[targetController_ window] makeMainWindow]; |
470 } else { | 477 } else { |
471 [dragWindow_ setAlphaValue:0.5]; | 478 [dragWindow_ setAlphaValue:0.5]; |
472 [[draggedController_ overlayWindow] setHasShadow:NO]; | 479 [[draggedController_ overlayWindow] setHasShadow:NO]; |
473 [[draggedController_ window] makeMainWindow]; | 480 [[draggedController_ window] makeMainWindow]; |
474 } | 481 } |
475 chromeIsVisible_ = shouldBeVisible; | 482 chromeIsVisible_ = shouldBeVisible; |
476 } | 483 } |
477 | 484 |
478 @end | 485 @end |
OLD | NEW |