| 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 #include <Carbon/Carbon.h> | 7 #include <Carbon/Carbon.h> |
| 8 | 8 |
| 9 #include "base/mac/scoped_cftyperef.h" | 9 #include "base/mac/scoped_cftyperef.h" |
| 10 #import "base/mac/sdk_forward_declarations.h" | 10 #import "base/mac/sdk_forward_declarations.h" |
| 11 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" | 11 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" |
| 12 #import "chrome/browser/ui/cocoa/tabs/tab_controller_target.h" | 12 #import "chrome/browser/ui/cocoa/tabs/tab_controller_target.h" |
| 13 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" | 13 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" |
| 14 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" | 14 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" |
| 15 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" | 15 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" |
| 16 #import "chrome/browser/ui/cocoa/tabs/tab_window_controller.h" | 16 #import "chrome/browser/ui/cocoa/tabs/tab_window_controller.h" |
| 17 #include "ui/base/cocoa/cocoa_base_utils.h" | 17 #include "ui/base/cocoa/cocoa_base_utils.h" |
| 18 #include "ui/gfx/mac/scoped_cocoa_disable_screen_updates.h" | 18 #include "ui/gfx/mac/scoped_cocoa_disable_screen_updates.h" |
| 19 | 19 |
| 20 const CGFloat kHorizontalTearDistance = 10.0; // Using the same value as Views. | |
| 21 const CGFloat kTearDistance = 36.0; | 20 const CGFloat kTearDistance = 36.0; |
| 22 const NSTimeInterval kTearDuration = 0.333; | 21 const NSTimeInterval kTearDuration = 0.333; |
| 23 | 22 |
| 24 // Returns whether |screenPoint| is inside the bounds of |view|. | 23 // Returns whether |screenPoint| is inside the bounds of |view|. |
| 25 static BOOL PointIsInsideView(NSPoint screenPoint, NSView* view) { | 24 static BOOL PointIsInsideView(NSPoint screenPoint, NSView* view) { |
| 26 if ([view window] == nil) | 25 if ([view window] == nil) |
| 27 return NO; | 26 return NO; |
| 28 NSPoint windowPoint = | 27 NSPoint windowPoint = |
| 29 ui::ConvertPointFromScreenToWindow([view window], screenPoint); | 28 ui::ConvertPointFromScreenToWindow([view window], screenPoint); |
| 30 NSPoint viewPoint = [view convertPoint:windowPoint fromView:nil]; | 29 NSPoint viewPoint = [view convertPoint:windowPoint fromView:nil]; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 return; | 164 return; |
| 166 } | 165 } |
| 167 | 166 |
| 168 // First, go through the magnetic drag cycle. We break out of this if | 167 // First, go through the magnetic drag cycle. We break out of this if |
| 169 // "stretchiness" ever exceeds a set amount. | 168 // "stretchiness" ever exceeds a set amount. |
| 170 tabWasDragged_ = YES; | 169 tabWasDragged_ = YES; |
| 171 | 170 |
| 172 if (draggingWithinTabStrip_) { | 171 if (draggingWithinTabStrip_) { |
| 173 NSPoint thisPoint = [NSEvent mouseLocation]; | 172 NSPoint thisPoint = [NSEvent mouseLocation]; |
| 174 CGFloat offset = thisPoint.x - dragOrigin_.x; | 173 CGFloat offset = thisPoint.x - dragOrigin_.x; |
| 175 // Only begin dragging the tab horizontally if it's torn out of its dead | 174 [sourceController_ insertPlaceholderForTab:[draggedTab_ tabView] |
| 176 // zone. | 175 frame:NSOffsetRect(sourceTabFrame_, |
| 177 if (!outOfTabHorizontalDeadZone_ && | 176 offset, 0)]; |
| 178 fabs(offset) > kHorizontalTearDistance) { | |
| 179 outOfTabHorizontalDeadZone_ = YES; | |
| 180 } | |
| 181 if (outOfTabHorizontalDeadZone_) { | |
| 182 [sourceController_ insertPlaceholderForTab:[draggedTab_ tabView] | |
| 183 frame:NSOffsetRect(sourceTabFrame_, | |
| 184 offset, 0)]; | |
| 185 } | |
| 186 // Check that we haven't pulled the tab too far to start a drag. This | 177 // Check that we haven't pulled the tab too far to start a drag. This |
| 187 // can include either pulling it too far down, or off the side of the tab | 178 // can include either pulling it too far down, or off the side of the tab |
| 188 // strip that would cause it to no longer be fully visible. | 179 // strip that would cause it to no longer be fully visible. |
| 189 BOOL stillVisible = | 180 BOOL stillVisible = |
| 190 [sourceController_ isTabFullyVisible:[draggedTab_ tabView]]; | 181 [sourceController_ isTabFullyVisible:[draggedTab_ tabView]]; |
| 191 CGFloat tearForce = fabs(thisPoint.y - dragOrigin_.y); | 182 CGFloat tearForce = fabs(thisPoint.y - dragOrigin_.y); |
| 192 if ([sourceController_ tabTearingAllowed] && | 183 if ([sourceController_ tabTearingAllowed] && |
| 193 (tearForce > kTearDistance || !stillVisible)) { | 184 (tearForce > kTearDistance || !stillVisible)) { |
| 194 draggingWithinTabStrip_ = NO; | 185 draggingWithinTabStrip_ = NO; |
| 195 // When you finally leave the strip, we treat that as the origin. | 186 // When you finally leave the strip, we treat that as the origin. |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 // we want to hide the window background so the tab stands out for | 396 // we want to hide the window background so the tab stands out for |
| 406 // positioning. If not, we want to show it so it looks like a new window will | 397 // positioning. If not, we want to show it so it looks like a new window will |
| 407 // be realized. | 398 // be realized. |
| 408 BOOL chromeShouldBeVisible = targetController_ == nil; | 399 BOOL chromeShouldBeVisible = targetController_ == nil; |
| 409 [self setWindowBackgroundVisibility:chromeShouldBeVisible]; | 400 [self setWindowBackgroundVisibility:chromeShouldBeVisible]; |
| 410 } | 401 } |
| 411 | 402 |
| 412 - (void)endDrag:(NSEvent*)event { | 403 - (void)endDrag:(NSEvent*)event { |
| 413 // Cancel any delayed -continueDrag: requests that may still be pending. | 404 // Cancel any delayed -continueDrag: requests that may still be pending. |
| 414 [NSObject cancelPreviousPerformRequestsWithTarget:self]; | 405 [NSObject cancelPreviousPerformRequestsWithTarget:self]; |
| 415 outOfTabHorizontalDeadZone_ = NO; | |
| 416 | 406 |
| 417 // Special-case this to keep the logic below simpler. | 407 // Special-case this to keep the logic below simpler. |
| 418 if (moveWindowOnDrag_) { | 408 if (moveWindowOnDrag_) { |
| 419 [self resetDragControllers]; | 409 [self resetDragControllers]; |
| 420 return; | 410 return; |
| 421 } | 411 } |
| 422 | 412 |
| 423 // TODO(pinkerton): http://crbug.com/25682 demonstrates a way to get here by | 413 // TODO(pinkerton): http://crbug.com/25682 demonstrates a way to get here by |
| 424 // some weird circumstance that doesn't first go through mouseDown:. We | 414 // some weird circumstance that doesn't first go through mouseDown:. We |
| 425 // really shouldn't go any farther. | 415 // really shouldn't go any farther. |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 [[targetController_ window] makeMainWindow]; | 555 [[targetController_ window] makeMainWindow]; |
| 566 } else { | 556 } else { |
| 567 [dragWindow_ setAlphaValue:0.5]; | 557 [dragWindow_ setAlphaValue:0.5]; |
| 568 [[draggedController_ overlayWindow] setHasShadow:NO]; | 558 [[draggedController_ overlayWindow] setHasShadow:NO]; |
| 569 [[draggedController_ window] makeMainWindow]; | 559 [[draggedController_ window] makeMainWindow]; |
| 570 } | 560 } |
| 571 chromeIsVisible_ = shouldBeVisible; | 561 chromeIsVisible_ = shouldBeVisible; |
| 572 } | 562 } |
| 573 | 563 |
| 574 @end | 564 @end |
| OLD | NEW |