Bug 1794070 - Refer mRequiresContentResponseIfCannotScrollHorizontallyInStartDirection flag instead of calling SwipeTrackker::CanTriggerSwipe(). r=botond

And rename mRequiresContentResponseIfCannotScrollHorizontallyInStartDirection to
mMayTriggerSwipe.

So basically once after the flag is set, we should use it.

Differential Revision: https://phabricator.services.mozilla.com/D160436
This commit is contained in:
Hiroyuki Ikezoe 2022-11-21 03:10:07 +00:00
parent ae5bdfff82
commit 5b39846aeb
10 changed files with 28 additions and 61 deletions

View File

@ -454,9 +454,7 @@ APZEventResult InputQueue::ReceivePanGestureInput(
MaybeRequestContentResponse(aTarget, block); MaybeRequestContentResponse(aTarget, block);
if (aFlags.mTargetConfirmed && event.mOverscrollBehaviorAllowsSwipe && if (aFlags.mTargetConfirmed && event.mOverscrollBehaviorAllowsSwipe &&
event event.MayTriggerSwipe() && !CanScrollTargetHorizontally(event, block)) {
.RequiresContentResponseIfCannotScrollHorizontallyInStartDirection() &&
!CanScrollTargetHorizontally(event, block)) {
// This event may trigger a swipe gesture, depending on what our caller // This event may trigger a swipe gesture, depending on what our caller
// wants to do it. We need to suspend handling of this block until we get // wants to do it. We need to suspend handling of this block until we get
// a content response which will tell us whether to proceed or abort the // a content response which will tell us whether to proceed or abort the

View File

@ -426,8 +426,7 @@ PanGestureInput::PanGestureInput()
mOverscrollBehaviorAllowsSwipe(false), mOverscrollBehaviorAllowsSwipe(false),
mSimulateMomentum(false), mSimulateMomentum(false),
mIsNoLineOrPageDelta(true), mIsNoLineOrPageDelta(true),
mRequiresContentResponseIfCannotScrollHorizontallyInStartDirection( mMayTriggerSwipe(false) {}
false) {}
PanGestureInput::PanGestureInput(PanGestureType aType, uint32_t aTime, PanGestureInput::PanGestureInput(PanGestureType aType, uint32_t aTime,
TimeStamp aTimeStamp, TimeStamp aTimeStamp,
@ -446,8 +445,7 @@ PanGestureInput::PanGestureInput(PanGestureType aType, uint32_t aTime,
mOverscrollBehaviorAllowsSwipe(false), mOverscrollBehaviorAllowsSwipe(false),
mSimulateMomentum(false), mSimulateMomentum(false),
mIsNoLineOrPageDelta(true) { mIsNoLineOrPageDelta(true) {
mRequiresContentResponseIfCannotScrollHorizontallyInStartDirection = mMayTriggerSwipe = SwipeTracker::CanTriggerSwipe(*this);
SwipeTracker::CanTriggerSwipe(*this);
} }
PanGestureInput::PanGestureInput(PanGestureType aType, uint32_t aTime, PanGestureInput::PanGestureInput(PanGestureType aType, uint32_t aTime,
@ -458,8 +456,7 @@ PanGestureInput::PanGestureInput(PanGestureType aType, uint32_t aTime,
IsEligibleForSwipe aIsEligibleForSwipe) IsEligibleForSwipe aIsEligibleForSwipe)
: PanGestureInput(aType, aTime, aTimeStamp, aPanStartPoint, : PanGestureInput(aType, aTime, aTimeStamp, aPanStartPoint,
aPanDisplacement, aModifiers) { aPanDisplacement, aModifiers) {
mRequiresContentResponseIfCannotScrollHorizontallyInStartDirection &= mMayTriggerSwipe &= bool(aIsEligibleForSwipe);
bool(aIsEligibleForSwipe);
} }
void PanGestureInput::SetLineOrPageDeltas(int32_t aLineOrPageDeltaX, void PanGestureInput::SetLineOrPageDeltas(int32_t aLineOrPageDeltaX,

View File

@ -426,10 +426,8 @@ class PanGestureInput : public InputData {
void SetIsNoLineOrPageDelta(bool aIsNoLineOrPageDelta) { void SetIsNoLineOrPageDelta(bool aIsNoLineOrPageDelta) {
mIsNoLineOrPageDelta = aIsNoLineOrPageDelta; mIsNoLineOrPageDelta = aIsNoLineOrPageDelta;
} }
bool RequiresContentResponseIfCannotScrollHorizontallyInStartDirection() bool MayTriggerSwipe() const { return mMayTriggerSwipe; }
const { bool RequiresContentResponseIfCannotScrollHorizontallyInStartDirection();
return mRequiresContentResponseIfCannotScrollHorizontallyInStartDirection;
}
static gfx::IntPoint GetIntegerDeltaForEvent(bool aIsStart, float x, float y); static gfx::IntPoint GetIntegerDeltaForEvent(bool aIsStart, float x, float y);
@ -483,12 +481,8 @@ class PanGestureInput : public InputData {
// hold until a content response has arrived, even if the block has a // hold until a content response has arrived, even if the block has a
// confirmed target. // confirmed target.
// This is used by events that can result in a swipe instead of a scroll. // This is used by events that can result in a swipe instead of a scroll.
bool mRequiresContentResponseIfCannotScrollHorizontallyInStartDirection : 1; bool mMayTriggerSwipe : 1;
void SetRequiresContentResponseIfCannotScrollHorizontallyInStartDirection( void SetMayTriggerSwipe(bool aValue) { mMayTriggerSwipe = aValue; }
bool aRequires) {
mRequiresContentResponseIfCannotScrollHorizontallyInStartDirection =
aRequires;
}
}; };
/** /**

View File

@ -480,7 +480,7 @@ class nsChildView final : public nsBaseWidget {
virtual LayoutDeviceIntPoint GetClientOffset() override; virtual LayoutDeviceIntPoint GetClientOffset() override;
void DispatchAPZWheelInputEvent(mozilla::InputData& aEvent, bool aCanTriggerSwipe); void DispatchAPZWheelInputEvent(mozilla::InputData& aEvent);
nsEventStatus DispatchAPZInputEvent(mozilla::InputData& aEvent); nsEventStatus DispatchAPZInputEvent(mozilla::InputData& aEvent);
void DispatchDoubleTapGesture(mozilla::TimeStamp aEventTimeStamp, void DispatchDoubleTapGesture(mozilla::TimeStamp aEventTimeStamp,

View File

@ -1879,7 +1879,7 @@ nsEventStatus nsChildView::DispatchAPZInputEvent(InputData& aEvent) {
return result.GetStatus(); return result.GetStatus();
} }
void nsChildView::DispatchAPZWheelInputEvent(InputData& aEvent, bool aCanTriggerSwipe) { void nsChildView::DispatchAPZWheelInputEvent(InputData& aEvent) {
if (mSwipeTracker && aEvent.mInputType == PANGESTURE_INPUT) { if (mSwipeTracker && aEvent.mInputType == PANGESTURE_INPUT) {
// Give the swipe tracker a first pass at the event. If a new pan gesture // Give the swipe tracker a first pass at the event. If a new pan gesture
// has been started since the beginning of the swipe, the swipe tracker // has been started since the beginning of the swipe, the swipe tracker
@ -1902,8 +1902,7 @@ void nsChildView::DispatchAPZWheelInputEvent(InputData& aEvent, bool aCanTrigger
return; return;
} }
event = MayStartSwipeForAPZ(aEvent.AsPanGestureInput(), result, event = MayStartSwipeForAPZ(aEvent.AsPanGestureInput(), result);
CanTriggerSwipe{aCanTriggerSwipe});
break; break;
} }
case SCROLLWHEEL_INPUT: { case SCROLLWHEEL_INPUT: {
@ -1932,7 +1931,7 @@ void nsChildView::DispatchAPZWheelInputEvent(InputData& aEvent, bool aCanTrigger
nsEventStatus status; nsEventStatus status;
switch (aEvent.mInputType) { switch (aEvent.mInputType) {
case PANGESTURE_INPUT: { case PANGESTURE_INPUT: {
if (MayStartSwipeForNonAPZ(aEvent.AsPanGestureInput(), CanTriggerSwipe{aCanTriggerSwipe})) { if (MayStartSwipeForNonAPZ(aEvent.AsPanGestureInput())) {
return; return;
} }
event = aEvent.AsPanGestureInput().ToWidgetEvent(this); event = aEvent.AsPanGestureInput().ToWidgetEvent(this);
@ -3171,10 +3170,7 @@ static gfx::IntPoint GetIntegerDeltaForEvent(NSEvent* aEvent) {
nsCocoaUtils::CreatePanGestureEvent(theEvent, eventIntervalTime, eventTimeStamp, position, nsCocoaUtils::CreatePanGestureEvent(theEvent, eventIntervalTime, eventTimeStamp, position,
preciseDelta, lineOrPageDelta, modifiers); preciseDelta, lineOrPageDelta, modifiers);
// NOTE: This `canTriggerSwipe` will be dropped in a subsequent change. geckoChildDeathGrip->DispatchAPZWheelInputEvent(panEvent);
bool canTriggerSwipe = nsCocoaUtils::ShouldConsiderStartingSwipeFromEvent(theEvent) &&
SwipeTracker::CanTriggerSwipe(panEvent);
geckoChildDeathGrip->DispatchAPZWheelInputEvent(panEvent, canTriggerSwipe);
} else if (usePreciseDeltas) { } else if (usePreciseDeltas) {
// This is on 10.6 or old touchpads that don't have any phase information. // This is on 10.6 or old touchpads that don't have any phase information.
ScrollWheelInput wheelEvent( ScrollWheelInput wheelEvent(
@ -3193,7 +3189,7 @@ static gfx::IntPoint GetIntegerDeltaForEvent(NSEvent* aEvent) {
wheelEvent.mLineOrPageDeltaX = lineOrPageDelta.x; wheelEvent.mLineOrPageDeltaX = lineOrPageDelta.x;
wheelEvent.mLineOrPageDeltaY = lineOrPageDelta.y; wheelEvent.mLineOrPageDeltaY = lineOrPageDelta.y;
wheelEvent.mIsMomentum = nsCocoaUtils::IsMomentumScrollEvent(theEvent); wheelEvent.mIsMomentum = nsCocoaUtils::IsMomentumScrollEvent(theEvent);
geckoChildDeathGrip->DispatchAPZWheelInputEvent(wheelEvent, false); geckoChildDeathGrip->DispatchAPZWheelInputEvent(wheelEvent);
} else { } else {
ScrollWheelInput::ScrollMode scrollMode = ScrollWheelInput::SCROLLMODE_INSTANT; ScrollWheelInput::ScrollMode scrollMode = ScrollWheelInput::SCROLLMODE_INSTANT;
if (StaticPrefs::general_smoothScroll() && StaticPrefs::general_smoothScroll_mouseWheel()) { if (StaticPrefs::general_smoothScroll() && StaticPrefs::general_smoothScroll_mouseWheel()) {
@ -3214,7 +3210,7 @@ static gfx::IntPoint GetIntegerDeltaForEvent(NSEvent* aEvent) {
WheelDeltaAdjustmentStrategy::eNone); WheelDeltaAdjustmentStrategy::eNone);
wheelEvent.mLineOrPageDeltaX = lineOrPageDelta.x; wheelEvent.mLineOrPageDeltaX = lineOrPageDelta.x;
wheelEvent.mLineOrPageDeltaY = lineOrPageDelta.y; wheelEvent.mLineOrPageDeltaY = lineOrPageDelta.y;
geckoChildDeathGrip->DispatchAPZWheelInputEvent(wheelEvent, false); geckoChildDeathGrip->DispatchAPZWheelInputEvent(wheelEvent);
} }
NS_OBJC_END_TRY_IGNORE_BLOCK; NS_OBJC_END_TRY_IGNORE_BLOCK;

View File

@ -5094,14 +5094,12 @@ void nsWindow::DispatchPanGesture(PanGestureInput& aPanInput) {
} }
WidgetWheelEvent event = aPanInput.ToWidgetEvent(this); WidgetWheelEvent event = aPanInput.ToWidgetEvent(this);
bool canTriggerSwipe = SwipeTracker::CanTriggerSwipe(aPanInput);
if (!mAPZC) { if (!mAPZC) {
if (MayStartSwipeForNonAPZ(aPanInput, CanTriggerSwipe{canTriggerSwipe})) { if (MayStartSwipeForNonAPZ(aPanInput)) {
return; return;
} }
} else { } else {
event = MayStartSwipeForAPZ(aPanInput, result, event = MayStartSwipeForAPZ(aPanInput, result);
CanTriggerSwipe{canTriggerSwipe});
} }
ProcessUntransformedAPZEvent(&event, result); ProcessUntransformedAPZEvent(&event, result);

View File

@ -2293,11 +2293,9 @@ nsBaseWidget::SwipeInfo nsBaseWidget::SendMayStartSwipe(
} }
WidgetWheelEvent nsBaseWidget::MayStartSwipeForAPZ( WidgetWheelEvent nsBaseWidget::MayStartSwipeForAPZ(
const PanGestureInput& aPanInput, const APZEventResult& aApzResult, const PanGestureInput& aPanInput, const APZEventResult& aApzResult) {
CanTriggerSwipe aCanTriggerSwipe) {
WidgetWheelEvent event = aPanInput.ToWidgetEvent(this); WidgetWheelEvent event = aPanInput.ToWidgetEvent(this);
if (aCanTriggerSwipe == CanTriggerSwipe::Yes && if (aPanInput.MayTriggerSwipe() && aPanInput.mOverscrollBehaviorAllowsSwipe) {
aPanInput.mOverscrollBehaviorAllowsSwipe) {
SwipeInfo swipeInfo = SendMayStartSwipe(aPanInput); SwipeInfo swipeInfo = SendMayStartSwipe(aPanInput);
event.mCanTriggerSwipe = swipeInfo.wantsSwipe; event.mCanTriggerSwipe = swipeInfo.wantsSwipe;
if (swipeInfo.wantsSwipe) { if (swipeInfo.wantsSwipe) {
@ -2329,8 +2327,7 @@ WidgetWheelEvent nsBaseWidget::MayStartSwipeForAPZ(
return event; return event;
} }
bool nsBaseWidget::MayStartSwipeForNonAPZ(const PanGestureInput& aPanInput, bool nsBaseWidget::MayStartSwipeForNonAPZ(const PanGestureInput& aPanInput) {
CanTriggerSwipe aCanTriggerSwipe) {
if (aPanInput.mType == PanGestureInput::PANGESTURE_MAYSTART || if (aPanInput.mType == PanGestureInput::PANGESTURE_MAYSTART ||
aPanInput.mType == PanGestureInput::PANGESTURE_START) { aPanInput.mType == PanGestureInput::PANGESTURE_START) {
mCurrentPanGestureBelongsToSwipe = false; mCurrentPanGestureBelongsToSwipe = false;
@ -2346,7 +2343,7 @@ bool nsBaseWidget::MayStartSwipeForNonAPZ(const PanGestureInput& aPanInput,
return true; return true;
} }
if (aCanTriggerSwipe == CanTriggerSwipe::No) { if (!aPanInput.MayTriggerSwipe()) {
return false; return false;
} }

View File

@ -337,21 +337,15 @@ class nsBaseWidget : public nsIWidget, public nsSupportsWeakReference {
uint32_t allowedDirections; uint32_t allowedDirections;
}; };
SwipeInfo SendMayStartSwipe(const mozilla::PanGestureInput& aSwipeStartEvent); SwipeInfo SendMayStartSwipe(const mozilla::PanGestureInput& aSwipeStartEvent);
enum class CanTriggerSwipe : bool {
No = false,
Yes = true,
};
// Returns a WidgetWheelEvent which needs to be handled by APZ regardless of // Returns a WidgetWheelEvent which needs to be handled by APZ regardless of
// whether |aPanInput| event was used for SwipeTracker or not. // whether |aPanInput| event was used for SwipeTracker or not.
mozilla::WidgetWheelEvent MayStartSwipeForAPZ( mozilla::WidgetWheelEvent MayStartSwipeForAPZ(
const mozilla::PanGestureInput& aPanInput, const mozilla::PanGestureInput& aPanInput,
const mozilla::layers::APZEventResult& aApzResult, const mozilla::layers::APZEventResult& aApzResult);
CanTriggerSwipe aCanTriggerSwipe);
// Returns true if |aPanInput| event was used for SwipeTracker, false // Returns true if |aPanInput| event was used for SwipeTracker, false
// otherwise. // otherwise.
bool MayStartSwipeForNonAPZ(const mozilla::PanGestureInput& aPanInput, bool MayStartSwipeForNonAPZ(const mozilla::PanGestureInput& aPanInput);
CanTriggerSwipe aCanTriggerSwipe);
void NotifyWindowDestroyed(); void NotifyWindowDestroyed();
void NotifySizeMoveDone(); void NotifySizeMoveDone();

View File

@ -1176,10 +1176,7 @@ struct ParamTraits<mozilla::PanGestureInput>
WriteParam(aWriter, aParam.mUserDeltaMultiplierY); WriteParam(aWriter, aParam.mUserDeltaMultiplierY);
WriteParam(aWriter, aParam.mDeltaType); WriteParam(aWriter, aParam.mDeltaType);
WriteParam(aWriter, aParam.mHandledByAPZ); WriteParam(aWriter, aParam.mHandledByAPZ);
WriteParam( WriteParam(aWriter, aParam.mMayTriggerSwipe);
aWriter,
aParam
.mRequiresContentResponseIfCannotScrollHorizontallyInStartDirection);
WriteParam(aWriter, aParam.mOverscrollBehaviorAllowsSwipe); WriteParam(aWriter, aParam.mOverscrollBehaviorAllowsSwipe);
WriteParam(aWriter, aParam.mSimulateMomentum); WriteParam(aWriter, aParam.mSimulateMomentum);
WriteParam(aWriter, aParam.mIsNoLineOrPageDelta); WriteParam(aWriter, aParam.mIsNoLineOrPageDelta);
@ -1198,10 +1195,8 @@ struct ParamTraits<mozilla::PanGestureInput>
ReadParam(aReader, &aResult->mUserDeltaMultiplierY) && ReadParam(aReader, &aResult->mUserDeltaMultiplierY) &&
ReadParam(aReader, &aResult->mDeltaType) && ReadParam(aReader, &aResult->mDeltaType) &&
ReadBoolForBitfield(aReader, aResult, &paramType::SetHandledByAPZ) && ReadBoolForBitfield(aReader, aResult, &paramType::SetHandledByAPZ) &&
ReadBoolForBitfield( ReadBoolForBitfield(aReader, aResult,
aReader, aResult, &paramType::SetMayTriggerSwipe) &&
&paramType::
SetRequiresContentResponseIfCannotScrollHorizontallyInStartDirection) &&
ReadBoolForBitfield(aReader, aResult, ReadBoolForBitfield(aReader, aResult,
&paramType::SetOverscrollBehaviorAllowsSwipe) && &paramType::SetOverscrollBehaviorAllowsSwipe) &&
ReadBoolForBitfield(aReader, aResult, ReadBoolForBitfield(aReader, aResult,

View File

@ -867,14 +867,12 @@ void nsWindow::SendAnAPZEvent(InputData& aEvent) {
if (aEvent.mInputType == PANGESTURE_INPUT) { if (aEvent.mInputType == PANGESTURE_INPUT) {
PanGestureInput& panInput = aEvent.AsPanGestureInput(); PanGestureInput& panInput = aEvent.AsPanGestureInput();
WidgetWheelEvent event = panInput.ToWidgetEvent(this); WidgetWheelEvent event = panInput.ToWidgetEvent(this);
bool canTriggerSwipe = SwipeTracker::CanTriggerSwipe(panInput);
if (!mAPZC) { if (!mAPZC) {
if (MayStartSwipeForNonAPZ(panInput, CanTriggerSwipe{canTriggerSwipe})) { if (MayStartSwipeForNonAPZ(panInput)) {
return; return;
} }
} else { } else {
event = MayStartSwipeForAPZ(panInput, result, event = MayStartSwipeForAPZ(panInput, result);
CanTriggerSwipe{canTriggerSwipe});
} }
ProcessUntransformedAPZEvent(&event, result); ProcessUntransformedAPZEvent(&event, result);