Bug 1794070 - Check mOverscrollBehaviorAllowsSwipe whether we do the short circuit for swipe. r=botond

Though this isn't a real bug at all since later we check the flag in
nsBaseWidget::MayStartSwipeForAPZ [1], this change includes a browser
mochitest to make sure `overscroll-behavior: contain` prevents swipe
navigations.


[1] https://searchfox.org/mozilla-central/rev/c5c002f81f08a73e04868e0c2bf0eb113f200b03/widget/nsBaseWidget.cpp#2294

Differential Revision: https://phabricator.services.mozilla.com/D160434
This commit is contained in:
Hiroyuki Ikezoe 2022-11-21 03:10:06 +00:00
parent df505b470b
commit 3fb8018d34
5 changed files with 109 additions and 4 deletions

View File

@ -1642,6 +1642,9 @@ APZEventResult APZCTreeManager::ReceiveInputEvent(
return state.Finish(*this, std::move(aCallback));
}
panInput.mOverscrollBehaviorAllowsSwipe =
state.mHit.mTargetApzc->OverscrollBehaviorAllowsSwipe();
state.mResult = mInputQueue->ReceiveInputEvent(
state.mHit.mTargetApzc,
TargetConfirmationFlags{state.mHit.mHitResult}, panInput);
@ -1649,9 +1652,6 @@ APZEventResult APZCTreeManager::ReceiveInputEvent(
// Update the out-parameters so they are what the caller expects.
panInput.mPanStartPoint = *untransformedStartPoint;
panInput.mPanDisplacement = *untransformedDisplacement;
panInput.mOverscrollBehaviorAllowsSwipe =
state.mHit.mTargetApzc->OverscrollBehaviorAllowsSwipe();
}
break;
}

View File

@ -453,7 +453,7 @@ APZEventResult InputQueue::ReceivePanGestureInput(
CancelAnimationsForNewBlock(block);
MaybeRequestContentResponse(aTarget, block);
if (aFlags.mTargetConfirmed &&
if (aFlags.mTargetConfirmed && event.mOverscrollBehaviorAllowsSwipe &&
event
.mRequiresContentResponseIfCannotScrollHorizontallyInStartDirection &&
!CanScrollTargetHorizontally(event, block)) {

View File

@ -12,5 +12,6 @@ skip-if =
os == "win" && bits == 32 && !debug # Bug 1759422
verify # Bug 1800022
support-files =
helper_swipe_gesture.html
!/gfx/layers/apz/test/mochitest/apz_test_native_event_utils.js
!/gfx/layers/apz/test/mochitest/apz_test_utils.js

View File

@ -805,6 +805,90 @@ add_task(async () => {
await SpecialPowers.popPrefEnv();
});
add_task(async () => {
await SpecialPowers.pushPrefEnv({
set: [
["browser.gesture.swipe.left", "Browser:BackOrBackDuplicate"],
["browser.gesture.swipe.right", "Browser:ForwardOrForwardDuplicate"],
["widget.disable-swipe-tracker", false],
["widget.swipe.velocity-twitch-tolerance", 0.0000001],
["widget.swipe.success-velocity-contribution", 0.5],
["apz.overscroll.enabled", true],
["apz.test.logging_enabled", true],
],
});
const tab = await BrowserTestUtils.openNewForegroundTab(
gBrowser,
"about:about",
true /* waitForLoad */
);
const URL_ROOT = getRootDirectory(gTestPath).replace(
"chrome://mochitests/content/",
"http://mochi.test:8888/"
);
BrowserTestUtils.loadURI(
tab.linkedBrowser,
URL_ROOT + "helper_swipe_gesture.html"
);
await BrowserTestUtils.browserLoaded(
tab.linkedBrowser,
false /* includeSubFrames */,
URL_ROOT + "helper_swipe_gesture.html"
);
// Make sure we can go back to the previous page.
ok(gBrowser.webNavigation.canGoBack);
await SpecialPowers.spawn(tab.linkedBrowser, [], async () => {
// Set `overscroll-behavior-x: contain` and flush it.
content.document.documentElement.style.overscrollBehaviorX = "contain";
content.document.documentElement.getBoundingClientRect();
await content.wrappedJSObject.promiseApzFlushedRepaints();
});
// Start a pan gesture but keep touching.
await panLeftToRightBegin(tab.linkedBrowser, 100, 100, 2);
// Flush APZ pending requests to make sure the pan gesture has been processed.
await SpecialPowers.spawn(tab.linkedBrowser, [], async () => {
await content.wrappedJSObject.promiseApzFlushedRepaints();
});
const isOverscrolled = await SpecialPowers.spawn(
tab.linkedBrowser,
[],
() => {
const scrollId = SpecialPowers.DOMWindowUtils.getViewId(
content.document.scrollingElement
);
const data = SpecialPowers.DOMWindowUtils.getCompositorAPZTestData();
return data.additionalData.some(entry => {
return (
entry.key == scrollId &&
entry.value.split(",").includes("overscrolled")
);
});
}
);
ok(isOverscrolled, "The root scroller should have overscrolled");
// Finish the pan gesture.
await panLeftToRightUpdate(tab.linkedBrowser, 100, 100, 2);
await panLeftToRightEnd(tab.linkedBrowser, 100, 100, 2);
// And wait a while to give a chance to navigate.
await waitForWhile();
// Make sure any navigation didn't happen.
is(tab.linkedBrowser.currentURI.spec, URL_ROOT + "helper_swipe_gesture.html");
BrowserTestUtils.removeTab(tab);
await SpecialPowers.popPrefEnv();
});
// NOTE: This test listens wheel events so that it causes an overscroll issue
// (bug 1800022). To avoid the bug, we need to run this test case at the end
// of this file.

View File

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<script src="/tests/SimpleTest/paint_listener.js"></script>
<script src="/browser/gfx/layers/apz/test/mochitest/apz_test_utils.js"></script>
<script src="/browser/gfx/layers/apz/test/mochitest/apz_test_native_event_utils.js"></script>
<style>
html {
overflow-x: scroll;
}
body {
margin: 0;
}
div {
height: 100vh;
width: 110vw;
background-color: blue;
}
</style>
<div></div>
</html>