Fix simulated touch state on repeated mouse down#161
Open
shrinktofit wants to merge 1 commit into
Open
Conversation
Contributor
Author
|
By the way, as another data point: in a native browser touch sequence, if I start touching on the canvas, move out of the canvas, and then release, the canvas-side flow still receives the corresponding This is why the simulated touch path should preserve the same pairing guarantee as web touch input: when mouse events are not paired, we should explicitly cancel the previous simulated touch before starting a new one. |
Code Size Check Report
Interface Check ReportThis pull request does not change any public interfaces ! |
star-e
approved these changes
Jun 22, 2026
Contributor
|
@cocos-robot run test cases |
star-e
requested review from
bofeng-song and
qiuguohua
and removed request for
bofeng-song
June 22, 2026 08:20
|
@shrinktofit, Please check the result of
Task Details |
|
@shrinktofit, Please check the result of
Task Details |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix simulated touch lifecycle handling when mouse down/up events are not paired. If a new mouse down arrives while the simulated touch is still active, the previous simulated touch is now cancelled before emitting the new touch start.
Problem
Mouse events are not guaranteed to arrive as perfectly paired
mousedown/mouseupsequences. For example, a user can press on the canvas, keep the mouse button pressed while moving outside the canvas, release elsewhere, then move back into the canvas and click again. This is easier to hit when:Before this change, the simulated touch sequence could become
touch-start, touch-start, touch-end. In most touch workflows, a new touch start while the previous simulated touch is still active is unexpected.Fix
When simulating touch from mouse input, the engine uses touch id
0. On a new simulatedTOUCH_START, if touch id0is still alive, we first dispatchTOUCH_CANCELfor the previous touch and release it fromtouchManager. The new mouse down can then create a fresh simulated touch and dispatch the expectedTOUCH_START.This keeps the simulated touch lifecycle well formed:
Reproduction
The following standalone page demonstrates that element-level mouse events can become unpaired. Press inside the canvas, drag to the gray area, release there, then move back into the canvas and click again. The canvas receives the second
mousedownwithout receiving the firstmouseup.Tests