Closed Bug 2085126 Opened 1 month ago Closed 24 days ago

Support swipe-to-nav on touchscreen without the main thread (Windows)

Categories

(Core :: Panning and Zooming, enhancement, P2)

enhancement

Tracking

()

RESOLVED FIXED
161 Branch
Tracking Status
firefox161 --- fixed

People

(Reporter: canalun, Assigned: canalun)

References

(Blocks 1 open bug)

Details

Attachments

(6 external files)

To fully support Bug 1443710, first implement swipe-to-nav without the main thread.
Note that we have to use the main thread of UI process to check the status of navigation history.
Here, "without the main thread" means that we exclude dispatch-to-content and unconfirmed touch-action. In short, this bug supports swipe-to-nav on touchscreen only on pages without either non-passive listeners, irregular areas, inactive scrollable frames, or unconfirmed touch action.

Blocks: 1443710
See Also: → 2085128
Priority: -- → P2
  1. Scope

This patch implements the basic single-finger swipe navigation flow on Windows.
The following items are addressed in subsequent patches.

  • considering related CSS props (i.e. touch-action and overscroll-behavior)
  • excluding two-finger gesture
  • handling diagonal swipe
  • considering widget.disable-swipe-tracker and pip
  • handling dispatch-to-content (e.g. preventDefault)
  • supporting linux

Note that this patch adopts a new pref,
"widget.swipe.touchscreen.enabled", which is enabled by default on Nightly.

  1. Summary

Reuse the existing SwipeTracker to recognize touchscreen swipes and drive
the browser's swipe navigation UI.

APZ determines which horizontal directions are available for swipe
navigation by checking whether any scroll target in the overscroll
handoff chain can scroll in those directions. It returns this information
to the widget at the start of the touch block.

The widget tracks each touch input through four phases.

Ending or canceling the touch block resets the widget's touch swipe state.
Cancellation also removes SwipeTracker, because only resetting the touch
state would keep the shared tracker consuming subsequent touchpad inputs.

  1. Difference between swipe-to-nav by pan gesture

APZ and UI/Content process continues to receive events even during
swipe-to-nav. That is different from swipe-to-nav by pan gesture.

APZ receives every touch event before the widget processes it as a swipe,
so it can maintain the touch block's lifecycle. Once the browser accepts
the swipe, SetBrowserGestureResponse tells APZ to drop the block's events
instead of scrolling the page.

While the widget is Pending, mMayTriggerSwipe tells APZ to queue the first
non-suppressed touchmove until SetBrowserGestureResponse arrives. This
prevents APZ from scrolling before the widget makes its swipe decision.
Consumed drops the queued events; NotConsumed releases them for normal
touch handling. Later moves no longer request a browser response.

Touchstart must remain unblocked so APZ can begin tap and long-press
recognition. Moves within slop must also remain unblocked, because the
widget does not make a swipe decision or send a response for those events.

UI/Content process receives every touch event, because they have to maintain
touch event lifecycle. Because touchmove event should be kept emitted during
swipe-to-nav and touchend event should be emitted at the end of swipe-to-nav,
UI/Content process has to receive every touch event even after swipe-to-nav
started.

  1. Test

Mochitest cases cover navigation, scrolling, slop, direction changes,
rejection, cancellation, and recovery in subsequent gestures. Also, there are
cases for touch/pointer event firing.

Gtests verify that the first swipe-candidate move does not scroll before
the browser response, that Consumed keeps the page stationary, and that
NotConsumed releases the queued move and allows subsequent scrolling.

Assignee: nobody → i.am.kanaru.sato
Status: NEW → ASSIGNED

Record the input source in SwipeTracker and consume events from the other
source while a swipe is active.

Add tests verifying that a touchscreen swipe can complete navigation or
be canceled after intervening touchpad input.

Touchscreen swipe navigation supports single-finger gestures. But multiple
fingers may be present in the initial MULTITOUCH_START, or another finger
may be added before movement (MULTITOUCH_START -> MULTITOUCH_START) or
during an active swipe (MULTITOUCH_START -> MULTITOUCH_MOVE -> MULTITOUCH_START).
Also multiple fingers can be removed subsequently (MULTITOUCH_END -> MULTITOUCH_END).
This patch rejects swipe navigation once more than one finger is on the
screen, and resets the touch swipe state when the last finger is lifted.

The widget counts the fingers with a TouchCounter before passing each
touch input to APZ. APZ may consume some events of a gesture with
nsEventStatus_eConsumeNoDefault (e.g. a touchstart during a fast fling),
and such events never reach the code after ReceiveInputEvent(). If the
widget counted the fingers there, a missed touchstart or touchend would
leave the count and the phase inconsistent for the rest of the gesture
and the subsequent ones. Rejecting a multi-finger gesture and resetting
the state on the last touchend therefore happen regardless of whether
APZ consumes the event.

Note rejecting before passing the input to APZ also clears mMayTriggerSwipe,
so APZ never waits for a browser gesture response for a multi-finger gesture.

Alternatives considered:

A. Using APZ's TouchCounter in APZCTreeManager.
It is not a count of the fingers on the screen. It counts the input after
APZ has filtered out the touches APZ decides to ignore (ref:
APZCTreeManager::ProcessTouchInput)

B. Tracking only the first finger and ignoring the others, instead of rejecting
a multi-finger gesture.
APZ starts a new touch block for each touchstart, so it's required to send
a browser gesture response for every new block, and decide which block to
track when a finger is added before the swipe decision. Deciding which
finger to track would still require knowing how many fingers are on the screen.

Only report swipeable directions when touch-action does not prevent the
touch block from panning horizontally. Also, while checking the overscroll
handoff chain, reject swipe navigation if the target or an ancestor
disallows it through overscroll-behavior.

Note that touch-action confirmed on the main thread is out-of-scope of
this patch. That is addressed once after mechanics for dispatch-to-content
is established.

Add browser tests covering touch-action: pan-y and horizontal
overscroll-behavior values auto, chain, contain, and none, including
nested scrollers and restrictions on ancestors.

mMayTriggerSwipe now includes if the window is PiP in order to
prevent APZ from doing any swipe-related calculation for a PiP window.

Use SwipeTracker::CanTriggerSwipe() to apply the degree threshold
and widget.disable-swipe-tracker pref, like swipe-to-nav by pan gesture.
While the threshold for pan swipe is '8', it was too tight for touch swipe.
So this patch adopts a new one for touch swipe, that is '3.7'.

I am going to review the rest of the patches tomorrow.

Pushed by i.am.kanaru.sato@gmail.com: https://github.com/mozilla-firefox/firefox/commit/a7ce9a58b3d3 https://hg.mozilla.org/integration/autoland/rev/eea5a3340120 swipe-to-nav on touchscreen: Implement happy-path on Windows. r=hiro https://github.com/mozilla-firefox/firefox/commit/3a4686cfb973 https://hg.mozilla.org/integration/autoland/rev/11e385cb5285 swipe-to-nav on touchscreen: Prevent touchpad input from interfering with touchscreen swipes. r=hiro,mac-reviewers,bradwerth https://github.com/mozilla-firefox/firefox/commit/a05ec9f9be7a https://hg.mozilla.org/integration/autoland/rev/64937b3aab8d swipe-to-nav on touchscreen: Reject multi-finger touch gesture. r=hiro https://github.com/mozilla-firefox/firefox/commit/cd3e562c53f7 https://hg.mozilla.org/integration/autoland/rev/515f4f1abe6b swipe-to-nav on touchscreen: Respect touch-action & overscroll-behavior. r=hiro https://github.com/mozilla-firefox/firefox/commit/9de4456f92de https://hg.mozilla.org/integration/autoland/rev/af6101b53548 swipe-to-nav on touchscreen: Exclude PiP windows. r=hiro,kpatenio https://github.com/mozilla-firefox/firefox/commit/b03d376f19b2 https://hg.mozilla.org/integration/autoland/rev/3c5ae84f006e swipe-to-nav on touchscreen: Respect swipe degree threshold and pref. r=hiro
Regressions: 2088306
Regressions: 2088553
Regressions: 2089067
QA Whiteboard: [qa-triage-done-c162/b161]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: