diff options
author | pinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-29 20:30:54 +0000 |
---|---|---|
committer | pinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-29 20:30:54 +0000 |
commit | 02f58f54e138f44d26743fa1f8bef78fc705ae80 (patch) | |
tree | 792a99808f6fa13439d141094189887e31cc2a23 /chrome/browser/cocoa/browser_window_controller.mm | |
parent | 135c20361491522381a596cf036d17eedc501a46 (diff) | |
download | chromium_src-02f58f54e138f44d26743fa1f8bef78fc705ae80.zip chromium_src-02f58f54e138f44d26743fa1f8bef78fc705ae80.tar.gz chromium_src-02f58f54e138f44d26743fa1f8bef78fc705ae80.tar.bz2 |
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
Diffstat (limited to 'chrome/browser/cocoa/browser_window_controller.mm')
-rw-r--r-- | chrome/browser/cocoa/browser_window_controller.mm | 48 |
1 files changed, 42 insertions, 6 deletions
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 { |