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