The touchcancel event occurs when the touch event gets interrupted.
Semantically, it is used to detect when a touchpoint is no longer active.
A touchpoint can be disrupted in a number of different ways, for example:
- If the user's finger is removed from the touch screen on a multitouch active state.
- If the user switches to a different app (abruptly) or if the device loses power.
- If the user's finger moves outside the browser window or the element that they are interacting with, effectively to prevent the user from accidentally interacting with elements outside the intended target.
In all these cases, the touchpoint gets “disrupted” and the touchcancel
event should be fired to handle the forthcoming expected behavior.
Behavior in Browsers:
There is a w3c specification on web APIs for touch events, but is completely implementation dependent.
Example implementation being, touchCancel
is a child object/class of touchEvent
, which is a child object/class of UIEvent
and that is handled by WindowsEventDispatcher
. Example handling of canceling touch by a gfx callback helper.
Apple, similarly, has touchCancel
type property that defines as "A system event canceling the current touches for the control.", and is a child/inherits from UIControl Event structure. But it also has broader type implementation, e.g., For an event where a finger is dragged inside the bounds of the control (touchDragInside). All such types listed here.
Chromium also used touchEvents
, e.g., touchCancel
, for touch scrolling and gesture handling, but no longer [1] [2] do so in favor of a gesture recognizer [3] in the [code].
I found explicit developer documentation that specify when to trigger touchCancel
related events in Apple. They have predefined types and specs on when to use them. MDN has documentation of their type UI event, but not explicit spec on exactly when to use them. I couldn't find Chromium doc/spec of touchEvents
, you are welcome to explore the code.
Edit: correctly specified an example + added section.