[webkit-dev] Mouse wheel event precision

Nathan Vander Wilt nate-lists at calftrail.com
Tue Jun 8 20:34:43 PDT 2010


On Jun 8, 2010, at 7:50 PM, Andy Estes wrote:
> Hi Nathan,
> 
> It is true that Safari now emits mousewheel events in increments of 120 for compatibility reasons.  However, there is no loss of granularity in the sense that events are generated on fractional wheel ticks and are accelerated on platforms that support it.  The only difference is that you will see increments of 120 rather than increments of 1.  It's been a few months since I've checked (and I can't look at the URL you attached on my phone), but I believe you'll see the same behavior in Chrome and IE.

I will not have access to IE for some time, but I think the old behaviour was more compatible. I am not the original author of the OpenLayers code (just made some un-integrated improvements, not shown below, to deal with WebKit's wheelDelta acting like wheelDeltaX at times) but I think it demonstrates the previous state of scroll wheel delta across browsers:

var delta;		// one scroll wheel "click" (corresponds to zoom level zoom level)
if (e.wheelDelta) {
	delta = e.wheelDelta/120; 
	if (window.opera && window.opera.version() < 9.2) {
		delta = -delta;
	}
} else if (e.detail) {
	delta = -e.detail / 3;
}

Webkit, IE and Opera seemed to be giving a wheelDelta in pixels or something where one "line" was about 40 units, while Gecko gave a detail where one line corresponds to 1 unit (assuming one old-school mouse wheel "click" scrolled ~3 lines).

What Safari 4 seemed to do was simply provide much greater precision, where scrolling half a line simply yielded about 20 units instead of being ignored. So the above code would yield integral deltas in browsers that only fired events in 3-line increments, but nice fractional deltas in WebKit.


What Safari 5's WebKit does is turn one "line" into 4800 (!) units instead of 40. For Safari 5 the code above needs to read as follows to work the same. You can see it isn't really "more compatible" at all:

var delta;		// one scroll wheel "click" (corresponds to zoom level zoom level)
if (isSafari5) {
	delta = e.wheelDelta / 120 / 120;
} else if (e.wheelDelta) {
	delta = e.wheelDelta/120; 
	if (window.opera && window.opera.version() < 9.2) {
		delta = -delta;
	}
} else if (e.detail) {
	delta = -e.detail / 3;
}


It sounds like this was a well-intentioned change, but missed the fact that that the values that are now being re-multiplied by 120 were *already* scaled to the "1 'click' = 120 units" range.

hope this helps,
-natevw



> I would also point out that in DOM Level 3 Events, mousewheel events are considered deprecated and the unit of wheelDelta is left up to the implementor.  IE set this increment to 120 some time ago, and we chose to match this behavior to be compatible with sites that expect it.  As you can imagine, the opposite problem occurs on those sites (extremely slow scrolling).  Unfortunately any decision we made here was bound to break some sites.
> 
> -Andy
> 
> Sent from my iPhone
> 
> On Jun 8, 2010, at 19:09, Nathan Vander Wilt <nate-lists at calftrail.com> wrote:
> 
>> In Safari 4, the following event handler would log nice smooth values when scrolling:
>> // logs: -3, -9, -6, -48, ...
>> document.addEventListener("mousewheel", function(e) { console.log(e.wheelDeltaY); });
>> 
>> In Safari 5, the mousewheel events have lost all precision, and are now big ugly integral multiples of 120:
>> // logs: -120, -240, -120, -480, ... (no correspondence with above values, of course)
>> document.addEventListener("mousewheel", function(e) { console.log(e.wheelDeltaY); });
>> 
>> This is a serious loss of precision, and brings us back to the primitive days when a mouse a had 1-axis clicky scroll wheel if it had one at all, and Firefox was the top browser. Compare the smooth, precise scroll zooming of http://calftrail.com/Share/multitouch/ in Safari 4 to the jerky, way-too-fast zooming in Safari 5.
>> 
>> Is this a regression introduced directly in recent WebKit builds, or is it Safari-specific? If the former, was it really necessary and can it please be rolled back?
>> 
>> thanks,
>> -natevw
>> _______________________________________________
>> webkit-dev mailing list
>> webkit-dev at lists.webkit.org
>> http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev



More information about the webkit-dev mailing list