@@ -333,6 +333,42 @@ abstract class _BaseAdapter {
333
333
mixin _WheelEventListenerMixin on _BaseAdapter {
334
334
static double ? _defaultScrollLineHeight;
335
335
336
+ bool _isTrackpadEvent (DomWheelEvent event) {
337
+ // This function relies on deprecated and non-standard implementation
338
+ // details. Useful reference material can be found below.
339
+ //
340
+ // https://source.chromium.org/chromium/chromium/src/+/main:ui/events/event.cc
341
+ // https://source.chromium.org/chromium/chromium/src/+/main:ui/events/cocoa/events_mac.mm
342
+ // https://github.com/WebKit/WebKit/blob/main/Source/WebCore/platform/mac/PlatformEventFactoryMac.mm
343
+ // https://searchfox.org/mozilla-central/source/dom/events/WheelEvent.h
344
+ // https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-mousewheel
345
+ if (browserEngine == BrowserEngine .firefox) {
346
+ // Firefox has restricted the wheelDelta properties, they do not provide
347
+ // enough information to accurately disambiguate trackpad events from mouse
348
+ // wheel events.
349
+ return false ;
350
+ }
351
+ if ((event.deltaX % 120 == 0 ) && (event.deltaY % 120 == 0 )) {
352
+ // While not in any formal web standard, `blink` and `webkit` browsers use
353
+ // a delta of 120 to represent one mouse wheel turn. If both dimensions of
354
+ // the delta are divisible by 120, this event is almost certainly not from
355
+ // a trackpad.
356
+ return false ;
357
+ }
358
+ if (((event.wheelDeltaX ?? (- 3 * event.deltaX)) != - 3 * event.deltaX) ||
359
+ ((event.wheelDeltaY ?? (- 3 * event.deltaY)) != - 3 * event.deltaY)) {
360
+ // On macOS, scrolling using a mouse wheel by default uses an acceleration
361
+ // curve, so delta values ramp up and are not at fixed multiples of 120.
362
+ // But in this case, the wheelDelta properties of the event still keep
363
+ // their original values.
364
+ // For all events without this acceleration curve applied, the wheelDelta
365
+ // values are by convention three times greater than the delta values and with
366
+ // the opposite sign.
367
+ return false ;
368
+ }
369
+ return true ;
370
+ }
371
+
336
372
List <ui.PointerData > _convertWheelEventToPointerData (
337
373
DomWheelEvent event
338
374
) {
@@ -341,20 +377,7 @@ mixin _WheelEventListenerMixin on _BaseAdapter {
341
377
const int domDeltaPage = 0x02 ;
342
378
343
379
ui.PointerDeviceKind kind = ui.PointerDeviceKind .mouse;
344
- if ((browserEngine == BrowserEngine .blink || browserEngine == BrowserEngine .webkit) &&
345
- (event.deltaX % 120 != 0 || event.deltaY % 120 != 0 ) &&
346
- ((event.wheelDeltaX ?? (- 3 * event.deltaX)) == - 3 * event.deltaX) &&
347
- ((event.wheelDeltaY ?? (- 3 * event.deltaY)) == - 3 * event.deltaY)) {
348
- // While not standardized, `blink` and `webkit` browsers use a delta of 120 to
349
- // represent one mouse wheel turn. If either dimension of the delta
350
- // is not divisible by 120, this event is not a normal mouse wheel event.
351
- // On macOS, mouse wheel events by default have an acceleration curve applied,
352
- // so their delta values ramp up and are not at fixed multiples of 120.
353
- // But in this case, the wheelDelta properties of the event still keep
354
- // their original values.
355
- // For all events without this acceleration curve applied, the wheelDelta
356
- // values are by convention three times greater than the delta values and with
357
- // the opposite sign.
380
+ if (_isTrackpadEvent (event)) {
358
381
kind = ui.PointerDeviceKind .trackpad;
359
382
}
360
383
0 commit comments