From 0e52c9ca9e098265d6e71c07198a391948e8e75d Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Fri, 12 May 2017 15:39:01 +0300 Subject: [PATCH] Bug 1052253 - Part 1: Fix gestures when using macOS 10.11 or later SDK. r=mstange `beginGestureWithEvent` and `endGestureWithEvent` are not called for applications that link against the macOS 10.11 or later SDK when we're running on macOS 10.11 or later. For compatibility with all supported macOS versions, we have to call {begin,end}GestureWithEvent ourselves based on the event phase when we're using the 10.11+ SDK. See: https://developer.apple.com/reference/appkit/nsresponder/1526368-begingesturewithevent --- widget/cocoa/nsChildView.mm | 71 +++++++++++++++++++++++++++++-------- 1 file changed, 57 insertions(+), 14 deletions(-) diff --git a/widget/cocoa/nsChildView.mm b/widget/cocoa/nsChildView.mm index ec668d8c66d6..614b72783c55 100644 --- a/widget/cocoa/nsChildView.mm +++ b/widget/cocoa/nsChildView.mm @@ -208,6 +208,8 @@ static bool sIsTabletPointerActivated = false; - (BOOL)inactiveWindowAcceptsMouseEvent:(NSEvent*)aEvent; - (void)updateWindowDraggableState; +- (bool)beginOrEndGestureForEventPhase:(NSEvent*)aEvent; + - (bool)shouldConsiderStartingSwipeFromEvent:(NSEvent*)aEvent; @end @@ -4179,8 +4181,10 @@ NSEvent* gLastDragMouseDownEvent = nil; { NS_OBJC_BEGIN_TRY_ABORT_BLOCK; - if (!anEvent || !mGeckoChild) + if (!anEvent || !mGeckoChild || + [self beginOrEndGestureForEventPhase:anEvent]) { return; + } nsAutoRetainCocoaObject kungFuDeathGrip(self); @@ -4209,22 +4213,14 @@ NSEvent* gLastDragMouseDownEvent = nil; NS_OBJC_END_TRY_ABORT_BLOCK; } -- (void)beginGestureWithEvent:(NSEvent *)anEvent -{ - if (!anEvent) - return; - - mGestureState = eGestureState_StartGesture; - mCumulativeMagnification = 0; - mCumulativeRotation = 0.0; -} - - (void)magnifyWithEvent:(NSEvent *)anEvent { NS_OBJC_BEGIN_TRY_ABORT_BLOCK; - if (!anEvent || !mGeckoChild) + if (!anEvent || !mGeckoChild || + [self beginOrEndGestureForEventPhase:anEvent]) { return; + } nsAutoRetainCocoaObject kungFuDeathGrip(self); @@ -4265,7 +4261,8 @@ NSEvent* gLastDragMouseDownEvent = nil; { NS_OBJC_BEGIN_TRY_ABORT_BLOCK; - if (!anEvent || !mGeckoChild) { + if (!anEvent || !mGeckoChild || + [self beginOrEndGestureForEventPhase:anEvent]) { return; } @@ -4289,8 +4286,10 @@ NSEvent* gLastDragMouseDownEvent = nil; { NS_OBJC_BEGIN_TRY_ABORT_BLOCK; - if (!anEvent || !mGeckoChild) + if (!anEvent || !mGeckoChild || + [self beginOrEndGestureForEventPhase:anEvent]) { return; + } nsAutoRetainCocoaObject kungFuDeathGrip(self); @@ -4332,6 +4331,50 @@ NSEvent* gLastDragMouseDownEvent = nil; NS_OBJC_END_TRY_ABORT_BLOCK; } +// `beginGestureWithEvent` and `endGestureWithEvent` are not called for +// applications that link against the macOS 10.11 or later SDK when we're +// running on macOS 10.11 or later. For compatibility with all supported macOS +// versions, we have to call {begin,end}GestureWithEvent ourselves based on +// the event phase when we're handling gestures. +- (bool)beginOrEndGestureForEventPhase:(NSEvent*)aEvent +{ + if (!aEvent) { + return false; + } + + bool usingElCapitanOrLaterSDK = true; +#if !defined(MAC_OS_X_VERSION_10_11) || \ + MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_11 + usingElCapitanOrLaterSDK = false; +#endif + + if (nsCocoaFeatures::OnElCapitanOrLater() && usingElCapitanOrLaterSDK) { + if (aEvent.phase == NSEventPhaseBegan) { + [self beginGestureWithEvent:aEvent]; + return true; + } + + if (aEvent.phase == NSEventPhaseEnded || + aEvent.phase == NSEventPhaseCancelled) { + [self endGestureWithEvent:aEvent]; + return true; + } + } + + return false; +} + +- (void)beginGestureWithEvent:(NSEvent*)aEvent +{ + if (!aEvent) { + return; + } + + mGestureState = eGestureState_StartGesture; + mCumulativeMagnification = 0; + mCumulativeRotation = 0.0; +} + - (void)endGestureWithEvent:(NSEvent *)anEvent { NS_OBJC_BEGIN_TRY_ABORT_BLOCK;