Hi,
Thank you Emilio for your great work!
I'd like to explain the background. First, `WheelEvent` was designed
for making it possible web browsers to expose raw wheel event
information with 3 kinds of delta value modes which listeners can
distinguish with `WheelEvent#deltaMode`. And then, I implemented it
as-is before Chrome/Safari. So, the spec (and I) assumed that the
"wheel" event listeners should be like this:
```
addEventListener("wheel", event => {
let amount = 0;
switch (event.deltaMode) {
case event.DOM_DELTA_PIXEL:
default:
amount = event.deltaY;
break;
case event.DOM_DELTA_LINE:
amount = event.deltaY * computeLineHeight(even.target);
break;
case event.DOM_DELTE_PAGE:
amount = event.deltaY * computePageHeight(event.target);
break;
}
scroll(amount);
event.preventDefault();
});
```
But finally, Chrome implemented "wheel" event only with
`DOM_DELTA_PIXEL` and `DOM_DELTA_PAGE`.
Unfortunately, some web app developers didn't realize that there is
`WheelEvent#deltaMode`. Then, they implemented their own listeners like
these:
Example 1:
```
addEventListener("wheel", event => {
let amount = event.deltaY;
if (isFirefox) {
amount *= 16;
}
scroll(amount);
event.preventDefault();
});
```
Example 2:
```
addEventListener("wheel", event => {
let amount = event.deltaY;
if (isFirefox && navigator.platform.includes("Mac")) {
amount *= 16;
}
scroll(amount);
event.preventDefault();
});
```
Example 3:
```
addEventListener("wheel", event => {
const amount =
event.deltaY > 0
? Math.min(event.deltaY, 16)
: Math.max(event.deltaY, -16);
scroll(amount);
event.preventDefault();
});
```
So, in most broken web apps, current hack must work as expected because
`deltaMode` is not referred.
If `deltaMode` is checked but after referring `deltaY`, the web apps
will lost raw value, but must work mostly as expected since they must
treat the delta value as `DOM_DELTA_LINE`.
Indeed, in long term goal must be that we'd dispatch exactly same wheel
events as Chrome/Chromium. However, without implementing alternative new
API, web apps will not be able to handle raw value for better UX.
Therefore, I filed a spec issue, but it's not been fixed yet.
https://github.com/w3c/uievents/issues/181
(FYI: On Windows, mouse diver/utility can consider wheel delta amount
with native window's class name or process name. E.g., whether the app
support or does not support high resolution wheel events. Therefore,
this fact would cause that it's impossible to dispatch **exactly** same
wheel events as Chrome/Chromium.)
--
Masayuki Nakano <
masa...@d-toybox.com>
Working on DOM, Events, editor and IME handling for Gecko