From 8f9e9a45e0a78ca7338d71f3fb1d9e5f3c690575 Mon Sep 17 00:00:00 2001 From: "rsesek@chromium.org" Date: Thu, 30 May 2013 21:57:41 +0000 Subject: [Mac][MC] Fix some issues with the swipe gesture. * Do not animate out if the notification has been swiped away. * Lock the direction so that if you start swiping one way, you can swipe quickly back the other to abort the gesture. * Use the device swipe direction, tracking the direction of the fingers, rather than the interpreted (natural/traditional) scroll direction. BUG=238252 Review URL: https://chromiumcodereview.appspot.com/15764008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@203237 0039d316-1c4b-4281-b951-d872f2087c98 --- ui/message_center/cocoa/popup_controller.mm | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'ui') diff --git a/ui/message_center/cocoa/popup_controller.mm b/ui/message_center/cocoa/popup_controller.mm index 694d860..e807ce7 100644 --- a/ui/message_center/cocoa/popup_controller.mm +++ b/ui/message_center/cocoa/popup_controller.mm @@ -61,9 +61,15 @@ enum { if (shouldTrackSwipe) { MCPopupController* controller = base::mac::ObjCCastStrict([self windowController]); + BOOL directionInverted = [event isDirectionInvertedFromDevice]; auto handler = ^(CGFloat gestureAmount, NSEventPhase phase, BOOL isComplete, BOOL* stop) { + // The swipe direction should match the direction the user's fingers + // are moving, not the interpreted scroll direction. + if (directionInverted) + gestureAmount *= -1; + if (phase == NSEventPhaseBegan) { [controller notificationSwipeStarted]; return; @@ -75,7 +81,7 @@ enum { if (ended || isComplete) [controller notificationSwipeEnded:ended complete:isComplete]; }; - [event trackSwipeEventWithOptions:0 + [event trackSwipeEventWithOptions:NSEventSwipeTrackingLockDirection dampenAmountThresholdMin:-1 max:1 usingHandler:handler]; @@ -188,11 +194,19 @@ enum { - (void)closeWithAnimation { if (isClosing_) return; + isClosing_ = YES; + // If the notification was swiped closed, do not animate it as the + // notification has already faded out. + if (swipeGestureEnded_) { + [self close]; + return; + } + NSDictionary* animationDict = @{ - NSViewAnimationTargetKey: [self window], - NSViewAnimationEffectKey: NSViewAnimationFadeOutEffect + NSViewAnimationTargetKey : [self window], + NSViewAnimationEffectKey : NSViewAnimationFadeOutEffect }; boundsAnimation_.reset([[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:animationDict]]); @@ -215,8 +229,8 @@ enum { bounds_ = newBounds; NSDictionary* animationDict = @{ - NSViewAnimationTargetKey: [self window], - NSViewAnimationEndFrameKey: [NSValue valueWithRect:newBounds] + NSViewAnimationTargetKey : [self window], + NSViewAnimationEndFrameKey : [NSValue valueWithRect:newBounds] }; boundsAnimation_.reset([[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:animationDict]]); -- cgit v1.1