Fix: cannot detect mac touchpad : switch to throttling

This commit is contained in:
jdescottes 2014-05-18 16:05:59 +02:00
parent 6dc3a2bdf7
commit 0fec4eff4a

View File

@ -1,8 +1,7 @@
(function () { (function () {
var ns = $.namespace("pskl.controller"); var ns = $.namespace("pskl.controller");
var MOUSEWHEEL_THROTTLING = 20;
var MAC_TOUCHPAD_SKIP = 8;
ns.DrawingController = function (piskelController, paletteController, container) { ns.DrawingController = function (piskelController, paletteController, container) {
/** /**
@ -47,7 +46,7 @@
this.previousMousemoveTime = 0; this.previousMousemoveTime = 0;
this.currentToolBehavior = null; this.currentToolBehavior = null;
this.skipMouseWheelCounter_ = 0; this.lastMouseWheel_ = 0;
// State of clicked button (need to be stateful here, see comment in getCurrentColor_) // State of clicked button (need to be stateful here, see comment in getCurrentColor_)
this.currentMouseButton_ = Constants.LEFT_BUTTON; this.currentMouseButton_ = Constants.LEFT_BUTTON;
@ -227,21 +226,18 @@
}; };
ns.DrawingController.prototype.onMousewheel_ = function (jQueryEvent) { ns.DrawingController.prototype.onMousewheel_ = function (jQueryEvent) {
var now = Date.now();
if (now - this.lastMouseWheel_ > MOUSEWHEEL_THROTTLING) {
this.lastMouseWheel_ = now;
var event = jQueryEvent.originalEvent; var event = jQueryEvent.originalEvent;
var delta = event.wheelDeltaY || (-2 * event.deltaY); var delta = event.wheelDeltaY || (-2 * event.deltaY);
var isMacTouchpad = typeof event.webkitDirectionInvertedFromDevice === 'boolean';
if (isMacTouchpad) {
if ((++this.skipMouseWheelCounter_%MAC_TOUCHPAD_SKIP)) {
return;
}
}
if (delta > 0) { if (delta > 0) {
this.increaseZoom_(); this.increaseZoom_();
} else if (delta < 0) { } else if (delta < 0) {
this.decreaseZoom_(); this.decreaseZoom_();
} }
}
}; };
/** /**