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
This commit is contained in:
Birunthan Mohanathas 2017-05-12 15:39:01 +03:00
Родитель 1b1642f523
Коммит 0e52c9ca9e
1 изменённых файлов: 57 добавлений и 14 удалений

Просмотреть файл

@ -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;