From 02f58f54e138f44d26743fa1f8bef78fc705ae80 Mon Sep 17 00:00:00 2001 From: "pinkerton@chromium.org" Date: Wed, 29 Apr 2009 20:30:54 +0000 Subject: Implement dropping of tabs into an existing tab strip from another window. Implement dragging and dropping of tabs within a window. Review URL: http://codereview.chromium.org/102010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14879 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/cocoa/browser_window_controller.mm | 48 ++++++++++++++++++++--- 1 file changed, 42 insertions(+), 6 deletions(-) (limited to 'chrome/browser/cocoa/browser_window_controller.mm') diff --git a/chrome/browser/cocoa/browser_window_controller.mm b/chrome/browser/cocoa/browser_window_controller.mm index efc08fc..5c35e2c 100644 --- a/chrome/browser/cocoa/browser_window_controller.mm +++ b/chrome/browser/cocoa/browser_window_controller.mm @@ -277,16 +277,52 @@ willPositionSheet:(NSWindow *)sheet return [tabStripController_ selectedTabGrowBoxRect]; } -- (void)dropTabView:(NSView *)view atIndex:(NSUInteger)index { - [tabStripController_ dropTabView:view atIndex:index]; +// Drop a given tab view at the location of the current placeholder. If there +// is no placeholder, it will go at the end. |dragController| is the window +// controller of a tab being dropped from a different window. It will be nil +// if the drag is within the window. The implementation will call +// |-removePlaceholder| since the drag is now complete. This also calls +// |-layoutTabs| internally so clients do not need to call it again. When +// dragging tabs between windows, this should be called *before* +// |-detachTabView| on the source window since it needs to still be in the +// source window's tab model for this method to find the information it needs +// to complete the drop. +- (void)dropTabView:(NSView*)view + fromController:(TabWindowController*)dragController { + if (dragController) { + // Moving between windows. Figure out the TabContents to drop into our tab + // model from the source window's model. + BOOL isBrowser = + [dragController isKindOfClass:[BrowserWindowController class]]; + DCHECK(isBrowser); + if (!isBrowser) return; + BrowserWindowController* dragBWC = (BrowserWindowController*)dragController; + int index = [dragBWC->tabStripController_ indexForTabView:view]; + TabContents* contents = + dragBWC->browser_->tabstrip_model()->GetTabContentsAt(index); + + // Deposit it into our model at the appropriate location (it already knows + // where it should go from tracking the drag). + [tabStripController_ dropTabContents:contents]; + } else { + // Moving within a window. + int index = [tabStripController_ indexForTabView:view]; + [tabStripController_ moveTabFromIndex:index]; + } + + // Remove the placeholder since the drag is now complete. + [self removePlaceholder]; } -- (NSView *)selectedTabView { - return [tabStripController_ selectedTabView]; +// Tells the tab strip to forget about this tab in preparation for it being +// put into a different tab strip, such as during a drop on another window. +- (void)detachTabView:(NSView*)view { + int index = [tabStripController_ indexForTabView:view]; + browser_->tabstrip_model()->DetachTabContentsAt(index); } -- (TabStripController *)tabStripController { - return tabStripController_; +- (NSView *)selectedTabView { + return [tabStripController_ selectedTabView]; } - (void)setIsLoading:(BOOL)isLoading { -- cgit v1.1