| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/cocoa/tab_view.h" | 5 #include "chrome/browser/cocoa/tab_view.h" |
| 6 #include "chrome/browser/cocoa/tab_window_controller.h" | 6 #include "chrome/browser/cocoa/tab_window_controller.h" |
| 7 | 7 |
| 8 @implementation TabView | 8 @implementation TabView |
| 9 | 9 |
| 10 - (id)initWithFrame:(NSRect)frame { | 10 - (id)initWithFrame:(NSRect)frame { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 TabWindowController* sourceController = [sourceWindow windowController]; | 63 TabWindowController* sourceController = [sourceWindow windowController]; |
| 64 | 64 |
| 65 // We don't want to "tear off" a tab if there's only one in the window. Treat | 65 // We don't want to "tear off" a tab if there's only one in the window. Treat |
| 66 // it like we're dragging around a tab we've already detached. Note that | 66 // it like we're dragging around a tab we've already detached. Note that |
| 67 // unit tests might have |-numberOfTabs| reporting zero since the model | 67 // unit tests might have |-numberOfTabs| reporting zero since the model |
| 68 // won't be fully hooked up. We need to be prepared for that and not send | 68 // won't be fully hooked up. We need to be prepared for that and not send |
| 69 // them into the "magnetic" codepath. | 69 // them into the "magnetic" codepath. |
| 70 BOOL isLastRemainingTab = [sourceController numberOfTabs] <= 1; | 70 BOOL isLastRemainingTab = [sourceController numberOfTabs] <= 1; |
| 71 | 71 |
| 72 BOOL dragging = YES; | 72 BOOL dragging = YES; |
| 73 BOOL moved = NO; | 73 BOOL moveBetweenWindows = NO; |
| 74 | 74 |
| 75 NSPoint lastPoint = | 75 NSPoint lastPoint = |
| 76 [[theEvent window] convertBaseToScreen:[theEvent locationInWindow]]; | 76 [[theEvent window] convertBaseToScreen:[theEvent locationInWindow]]; |
| 77 | 77 |
| 78 // First, go through the magnetic drag cycle. We break out of this if | 78 // First, go through the magnetic drag cycle. We break out of this if |
| 79 // "stretchiness" ever exceeds the a set amount. | 79 // "stretchiness" ever exceeds the a set amount. |
| 80 NSRect frame = [self frame]; | 80 NSRect frame = [self frame]; |
| 81 if (!isLastRemainingTab) { | 81 if (!isLastRemainingTab) { |
| 82 while (dragging) { | 82 while (dragging) { |
| 83 theEvent = | 83 theEvent = |
| (...skipping 12 matching lines...) Expand all Loading... |
| 96 CGFloat tearForce = fabs(thisPoint.y - lastPoint.y); | 96 CGFloat tearForce = fabs(thisPoint.y - lastPoint.y); |
| 97 if (tearForce > kTearDistance) break; | 97 if (tearForce > kTearDistance) break; |
| 98 if ([theEvent type] == NSLeftMouseUp) { | 98 if ([theEvent type] == NSLeftMouseUp) { |
| 99 // Mouse up, break out of the drag event tracking loop | 99 // Mouse up, break out of the drag event tracking loop |
| 100 dragging = NO; | 100 dragging = NO; |
| 101 break; | 101 break; |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 } | 104 } |
| 105 | 105 |
| 106 [sourceController removePlaceholder]; | 106 if (dragging) |
| 107 [sourceController removePlaceholder]; |
| 107 | 108 |
| 108 TabWindowController* draggedController = nil; | 109 TabWindowController* draggedController = nil; |
| 109 TabWindowController* targetController = nil; | 110 TabWindowController* targetController = nil; |
| 110 | 111 |
| 111 NSWindow* dragWindow = nil; | 112 NSWindow* dragWindow = nil; |
| 112 NSWindow* dragOverlay = nil; | 113 NSWindow* dragOverlay = nil; |
| 113 | 114 |
| 114 // Do not start dragging until the user has "torn" the tab off by | 115 // Do not start dragging until the user has "torn" the tab off by |
| 115 // moving more than 3 pixels. | 116 // moving more than 3 pixels. |
| 116 BOOL torn = NO; | 117 BOOL torn = NO; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 // If we're now targeting a new window, re-layout the tabs in the old | 172 // If we're now targeting a new window, re-layout the tabs in the old |
| 172 // target and reset how long we've been hovering over this new one. | 173 // target and reset how long we've been hovering over this new one. |
| 173 if (targetController != newTarget) { | 174 if (targetController != newTarget) { |
| 174 targetDwellDate = [NSDate date]; | 175 targetDwellDate = [NSDate date]; |
| 175 [targetController removePlaceholder]; | 176 [targetController removePlaceholder]; |
| 176 targetController = newTarget; | 177 targetController = newTarget; |
| 177 } | 178 } |
| 178 | 179 |
| 179 NSEventType type = [theEvent type]; | 180 NSEventType type = [theEvent type]; |
| 180 if (type == NSLeftMouseDragged) { | 181 if (type == NSLeftMouseDragged) { |
| 181 moved = YES; | 182 moveBetweenWindows = YES; |
| 182 if (!draggedController) { | 183 if (!draggedController) { |
| 183 if (isLastRemainingTab) { | 184 if (isLastRemainingTab) { |
| 184 draggedController = sourceController; | 185 draggedController = sourceController; |
| 185 dragWindow = [draggedController window]; | 186 dragWindow = [draggedController window]; |
| 186 } else { | 187 } else { |
| 187 // Detach from the current window and put it in a new window. | 188 // Detach from the current window and put it in a new window. |
| 188 draggedController = [sourceController detachTabToNewWindow:self]; | 189 draggedController = [sourceController detachTabToNewWindow:self]; |
| 189 dragWindow = [draggedController window]; | 190 dragWindow = [draggedController window]; |
| 190 [dragWindow setAlphaValue:0.0]; | 191 [dragWindow setAlphaValue:0.0]; |
| 191 } | 192 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 setAlphaValue:targetController ? 0.85 : 1.0]; | 251 setAlphaValue:targetController ? 0.85 : 1.0]; |
| 251 } else if (type == NSLeftMouseUp) { | 252 } else if (type == NSLeftMouseUp) { |
| 252 // Mouse up, break out of the drag event tracking loop | 253 // Mouse up, break out of the drag event tracking loop |
| 253 dragging = NO; | 254 dragging = NO; |
| 254 } | 255 } |
| 255 lastPoint = thisPoint; | 256 lastPoint = thisPoint; |
| 256 } // while tracking mouse | 257 } // while tracking mouse |
| 257 | 258 |
| 258 // The drag/click is done. If the user dragged the mouse, finalize the drag | 259 // The drag/click is done. If the user dragged the mouse, finalize the drag |
| 259 // and clean up. | 260 // and clean up. |
| 260 if (moved) { | 261 if (moveBetweenWindows) { |
| 261 TabWindowController *dropController = targetController; | 262 // Move between windows. If |targetController| is nil, we're not dropping |
| 262 #if 1 | 263 // into any existing window. |
| 263 dropController = nil; // Don't allow drops on other windows for now | 264 TabWindowController* dropController = targetController; |
| 264 #endif | |
| 265 if (dropController) { | 265 if (dropController) { |
| 266 // TODO(alcor/pinkerton): hookup drops on existing windows | 266 // The ordering here is important. We need to be able to get from the |
| 267 NSRect adjustedFrame = [self bounds]; | 267 // TabView in the |draggedController| to whatever is needed by the tab |
| 268 NSRect dropTabFrame = [[dropController tabStripView] frame]; | 268 // model. To do so, it still has to be in the model, so we have to call |
| 269 adjustedFrame.origin = [self convertPointToBase:NSZeroPoint]; | 269 // "drop" before we call "detach". |
| 270 adjustedFrame.origin = | 270 NSView* draggedTabView = [draggedController selectedTabView]; |
| 271 [sourceWindow convertBaseToScreen:adjustedFrame.origin]; | 271 [draggedController removeOverlay]; |
| 272 adjustedFrame.origin.x = adjustedFrame.origin.x - dropTabFrame.origin.x; | 272 [dropController dropTabView:draggedTabView |
| 273 //adjustedFrame.origin.y = adjustedFrame.origin.y - dropTabFrame.origin.y; | 273 fromController:draggedController]; |
| 274 //adjustedFrame.size.height += adjustedFrame.origin.y; | 274 [draggedController detachTabView:draggedTabView]; |
| 275 adjustedFrame.origin.y = 0; | |
| 276 // TODO(alcor): get add tab stuff working | |
| 277 // [dropController addTab:tab_]; | |
| 278 [self setFrame:adjustedFrame]; | |
| 279 [dropController layoutTabs]; | |
| 280 [draggedController close]; | |
| 281 [dropController showWindow:nil]; | 275 [dropController showWindow:nil]; |
| 282 } else { | 276 } else { |
| 283 [targetController removePlaceholder]; | 277 [targetController removePlaceholder]; |
| 284 [[dragWindow animator] setAlphaValue:1.0]; | 278 [[dragWindow animator] setAlphaValue:1.0]; |
| 285 [dragOverlay setHasShadow:NO]; | 279 [dragOverlay setHasShadow:NO]; |
| 286 [dragWindow setHasShadow:YES]; | 280 [dragWindow setHasShadow:YES]; |
| 287 [draggedController removeOverlay]; | 281 [draggedController removeOverlay]; |
| 288 [dragWindow makeKeyAndOrderFront:nil]; | 282 [dragWindow makeKeyAndOrderFront:nil]; |
| 289 | 283 |
| 290 [[draggedController window] setLevel:NSNormalWindowLevel]; | 284 [[draggedController window] setLevel:NSNormalWindowLevel]; |
| 291 [draggedController layoutTabs]; | 285 [draggedController layoutTabs]; |
| 292 } | 286 } |
| 293 [sourceController layoutTabs]; | 287 [sourceController layoutTabs]; |
| 288 } else { |
| 289 // Move or click within a window. We need to differentiate between a |
| 290 // click on the tab and a drag by checking against the initial x position. |
| 291 NSPoint currentPoint = [NSEvent mouseLocation]; |
| 292 BOOL wasDrag = fabs(currentPoint.x - lastPoint.x) > kDragStartDistance; |
| 293 if (wasDrag) { |
| 294 // Move tab to new location. |
| 295 TabWindowController* dropController = sourceController; |
| 296 [dropController dropTabView:[dropController selectedTabView] |
| 297 fromController:nil]; |
| 298 } |
| 294 } | 299 } |
| 300 |
| 301 [sourceController removePlaceholder]; |
| 295 } | 302 } |
| 296 | 303 |
| 297 @end | 304 @end |
| OLD | NEW |