Bug 1636473 - Use the APZ machinery to dispatch magnifygesture events. r=dao,tnikkel

Unify two separate codepaths that do conceptually identical things. That is,
instead of having the widget code directly dispatch wheel and pinch gesture
events to Gecko, allow APZ to do it as part of it's handling of pinch inputs
when zooming is disabled.

The main difference is that the WidgetSimpleGestureEvent delta values come out
different, because they are based on the macOS event's magnification value,
rather than the (now deprecated) deltaZ value. This is actually better since it
makes the values consistent across platforms and allows removal of some ifdefs.

Differential Revision: https://phabricator.services.mozilla.com/D74640
This commit is contained in:
Kartikaya Gupta 2020-05-12 00:46:34 +00:00
Родитель 7fba1d1b69
Коммит 7a22496951
5 изменённых файлов: 10 добавлений и 75 удалений

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

@ -595,13 +595,8 @@ pref("browser.gesture.swipe.left", "Browser:BackOrBackDuplicate");
pref("browser.gesture.swipe.right", "Browser:ForwardOrForwardDuplicate");
pref("browser.gesture.swipe.up", "cmd_scrollTop");
pref("browser.gesture.swipe.down", "cmd_scrollBottom");
#ifdef XP_MACOSX
pref("browser.gesture.pinch.latched", true);
pref("browser.gesture.pinch.threshold", 150);
#else
pref("browser.gesture.pinch.latched", false);
pref("browser.gesture.pinch.threshold", 25);
#endif
pref("browser.gesture.pinch.latched", false);
pref("browser.gesture.pinch.threshold", 25);
#if defined(XP_WIN) || defined(MOZ_WIDGET_GTK)
// Enabled for touch input display zoom.
pref("browser.gesture.pinch.out", "cmd_fullZoomEnlarge");

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

@ -100,9 +100,7 @@ var gGestureSupport = {
break;
case "MozMagnifyGestureStart":
aEvent.preventDefault();
let pinchPref =
AppConstants.platform == "win" ? def(25, 0) : def(150, 1);
this._setupGesture(aEvent, "pinch", pinchPref, "out", "in");
this._setupGesture(aEvent, "pinch", def(25, 0), "out", "in");
break;
case "MozRotateGestureStart":
aEvent.preventDefault();

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

@ -889,6 +889,11 @@ void APZCCallbackHelper::NotifyPinchGesture(
}
WidgetSimpleGestureEvent event(true, msg, aWidget);
// XXX mDelta for the eMagnifyGesture event is supposed to be the
// cumulative magnification over the entire gesture (per docs in
// SimpleGestureEvent.webidl) but currently APZ just sends us a zero
// aSpanChange for that event, so the mDelta is wrong. Nothing relies
// on that currently, but we might want to fix it at some point.
event.mDelta = aSpanChange;
event.mModifiers = aModifiers;
DispatchWidgetEvent(event);

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

@ -154,10 +154,6 @@ class WidgetRenderingContext;
// beginGestureWithEvent and endGestureWithEvent sequence. We
// discard the spurious gesture event so as not to confuse Gecko.
//
// mCumulativeMagnification keeps track of the total amount of
// magnification peformed during a magnify gesture so that we can
// send that value with the final MozMagnifyGesture event.
//
// mCumulativeRotation keeps track of the total amount of rotation
// performed during a rotate gesture so we can send that value with
// the final MozRotateGesture event.
@ -167,7 +163,6 @@ class WidgetRenderingContext;
eGestureState_MagnifyGesture,
eGestureState_RotateGesture
} mGestureState;
float mCumulativeMagnification;
float mCumulativeRotation;
#ifdef __LP64__

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

@ -2375,7 +2375,6 @@ NSEvent* gLastDragMouseDownEvent = nil; // [strong]
mDragService = nullptr;
mGestureState = eGestureState_None;
mCumulativeMagnification = 0.0;
mCumulativeRotation = 0.0;
mIsUpdatingLayer = NO;
@ -2849,52 +2848,7 @@ NSEvent* gLastDragMouseDownEvent = nil; // [strong]
100.0 * (1.0 - [anEvent magnification]),
nsCocoaUtils::ModifiersForEvent(anEvent)};
// FIXME: bug 1525793 -- this may need to handle zooming or not on a per-document basis.
if (StaticPrefs::apz_allow_zooming()) {
mGeckoChild->DispatchAPZInputEvent(event);
} else {
if (!anEvent || [self beginOrEndGestureForEventPhase:anEvent]) {
return;
}
nsAutoRetainCocoaObject kungFuDeathGrip(self);
float deltaZ = [anEvent deltaZ];
EventMessage msg;
switch (mGestureState) {
case eGestureState_StartGesture:
msg = eMagnifyGestureStart;
mGestureState = eGestureState_MagnifyGesture;
break;
case eGestureState_MagnifyGesture:
msg = eMagnifyGestureUpdate;
break;
case eGestureState_None:
case eGestureState_RotateGesture:
default:
return;
}
// See PinchGestureInput::ToWidgetWheelEvent for a lengthy explanation of the values we put into
// the WidgetWheelEvent that used to be here.
WidgetWheelEvent geckoWheelEvent(event.ToWidgetWheelEvent(mGeckoChild));
mGeckoChild->DispatchWindowEvent(geckoWheelEvent);
// If the fake wheel event wasn't stopped, then send a normal magnify event.
if (!geckoWheelEvent.mFlags.mDefaultPrevented) {
WidgetSimpleGestureEvent geckoEvent(true, msg, mGeckoChild);
geckoEvent.mDelta = deltaZ;
[self convertCocoaMouseEvent:anEvent toGeckoEvent:&geckoEvent];
mGeckoChild->DispatchWindowEvent(geckoEvent);
// Keep track of the cumulative magnification for the final "magnify" event.
mCumulativeMagnification += deltaZ;
}
}
mGeckoChild->DispatchAPZInputEvent(event);
NS_OBJC_END_TRY_ABORT_BLOCK;
}
@ -3006,7 +2960,6 @@ NSEvent* gLastDragMouseDownEvent = nil; // [strong]
}
mGestureState = eGestureState_StartGesture;
mCumulativeMagnification = 0;
mCumulativeRotation = 0.0;
}
@ -3016,7 +2969,6 @@ NSEvent* gLastDragMouseDownEvent = nil; // [strong]
if (!anEvent || !mGeckoChild) {
// Clear the gestures state if we cannot send an event.
mGestureState = eGestureState_None;
mCumulativeMagnification = 0.0;
mCumulativeRotation = 0.0;
return;
}
@ -3024,16 +2976,6 @@ NSEvent* gLastDragMouseDownEvent = nil; // [strong]
nsAutoRetainCocoaObject kungFuDeathGrip(self);
switch (mGestureState) {
case eGestureState_MagnifyGesture: {
// Setup the "magnify" event.
WidgetSimpleGestureEvent geckoEvent(true, eMagnifyGesture, mGeckoChild);
geckoEvent.mDelta = mCumulativeMagnification;
[self convertCocoaMouseEvent:anEvent toGeckoEvent:&geckoEvent];
// Send the event.
mGeckoChild->DispatchWindowEvent(geckoEvent);
} break;
case eGestureState_RotateGesture: {
// Setup the "rotate" event.
WidgetSimpleGestureEvent geckoEvent(true, eRotateGesture, mGeckoChild);
@ -3049,6 +2991,7 @@ NSEvent* gLastDragMouseDownEvent = nil; // [strong]
mGeckoChild->DispatchWindowEvent(geckoEvent);
} break;
case eGestureState_MagnifyGesture: // APZ handles sending the widget events
case eGestureState_None:
case eGestureState_StartGesture:
default:
@ -3057,7 +3000,6 @@ NSEvent* gLastDragMouseDownEvent = nil; // [strong]
// Clear the gestures state.
mGestureState = eGestureState_None;
mCumulativeMagnification = 0.0;
mCumulativeRotation = 0.0;
NS_OBJC_END_TRY_ABORT_BLOCK;