Bug 1663731 - For two-touch gestures, don't send the pointercancel too early. r=botond

The existing code would send the pointercancel to web content as soon as the
second touchstart event was triggered for a pinch gesture. Instead, we want
to wait and see if the subsequent touchmove is cancelled before doing that.

Differential Revision: https://phabricator.services.mozilla.com/D92130
This commit is contained in:
Kartikaya Gupta 2020-10-03 13:15:44 +00:00
Родитель c4408a4561
Коммит a84069819c
3 изменённых файлов: 86 добавлений и 4 удалений

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

@ -0,0 +1,80 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width; initial-scale=1.0">
<title>Test for Bug 1663731</title>
<script type="application/javascript" src="apz_test_native_event_utils.js"></script>
<script type="application/javascript" src="apz_test_utils.js"></script>
<script src="/tests/SimpleTest/paint_listener.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<script type="application/javascript">
function* test(testDriver) {
var body = document.body;
var cancelledTouchMove = false;
// Event listeners just for logging/debugging purposes
body.addEventListener("pointerdown", function(e) {
dump(`Got pointerdown, pointer id ${e.pointerId}\n`);
});
body.addEventListener("touchstart", function(e) {
dump(`Got touchstart with ${e.touches.length} touches\n`);
}, {passive: true});
// Event listeners relevant to the test. We want to make sure that even
// though APZ can zoom the page, it does NOT dispatch pointercancel events in
// the scenario where the page calls preventDefault() on the first touchmove
// with two touch points. In other words, if the page chooses to disable
// browser pinch-zooming by preventDefault()'ing the first touchmove for
// the second touch point, then the browser should not dispatch pointercancel
// at all, but keep sending the pointerevents to the content. This is
// similar to what the browser does when zooming is disallowed by
// touch-action:none, for example.
body.addEventListener("pointercancel", function(e) {
dump(`Got pointercancel, pointer id ${e.pointerId}\n`);
ok(false, "Should not get any pointercancel events");
});
body.addEventListener("touchmove", function(e) {
dump(`Got touchmove with ${e.touches.length} touches\n`);
if (e.touches.length > 1) {
dump(`Preventing...\n`);
e.preventDefault();
cancelledTouchMove = true;
}
}, {passive: false});
// This listener is just to catch the end of the touch sequence so we can
// end the test at the right time.
body.addEventListener("touchend", function(e) {
dump(`Got touchend with ${e.touches.length} touches\n`);
if (e.touches.length == 0) {
setTimeout(testDriver, 0);
}
});
yield* pinchZoomOutTouchSequenceAtCenter();
dump("All touch events synthesized, waiting for final pointerup...\n");
yield true;
ok(cancelledTouchMove, "Checking that we definitely cancelled the touchmove");
}
waitUntilApzStable()
.then(runContinuation(test))
.then(subtestDone);
</script>
<style>
body {
height: 5000px;
}
</style>
</head>
<body>
A two-finger pinch action here should send pointer events to content and not do browser zooming.
</body>
</html>

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

@ -24,6 +24,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1285070
{"file": "helper_bug1502010_unconsumed_pan.html", "prefs": [enablePE]},
{"file": "helper_bug1544966_zoom_on_touch_action_none.html", "prefs": [enablePE, ...touch_action_prefs]},
{"file": "helper_bug1648491_no_pointercancel_with_dtc.html", "prefs": [enablePE, ...touch_action_prefs]},
{"file": "helper_bug1663731_no_pointercancel_on_second_touchstart.html", "prefs": [enablePE, ...touch_action_prefs]},
];
if (isApzEnabled()) {

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

@ -321,15 +321,16 @@ void APZEventState::ProcessTouchEvent(
bool isTouchPrevented = aContentResponse == nsEventStatus_eConsumeNoDefault;
bool sentContentResponse = false;
APZES_LOG("Handling event type %d\n", aEvent.mMessage);
APZES_LOG("Handling event type %d isPrevented=%d\n", aEvent.mMessage,
isTouchPrevented);
switch (aEvent.mMessage) {
case eTouchStart: {
mTouchEndCancelled = false;
mTouchRollup = do_GetWeakReference(widget::nsAutoRollup::GetLastRollup());
sentContentResponse = SendPendingTouchPreventedResponse(false);
// sentContentResponse can be true here if we get two TOUCH_STARTs in a
// row and just responded to the first one.
SendPendingTouchPreventedResponse(false);
// The above call may have sent a message to APZ if we get two
// TOUCH_STARTs in a row and just responded to the first one.
// We're about to send a response back to APZ, but we should only do it
// for events that went through APZ (which should be all of them).