From 0fec4eff4a27e4923e8c9ec6ae9a2f257833447e Mon Sep 17 00:00:00 2001 From: jdescottes Date: Sun, 18 May 2014 16:05:59 +0200 Subject: [PATCH] Fix: cannot detect mac touchpad : switch to throttling --- src/js/controller/DrawingController.js | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/js/controller/DrawingController.js b/src/js/controller/DrawingController.js index b979cf38..028d2fed 100644 --- a/src/js/controller/DrawingController.js +++ b/src/js/controller/DrawingController.js @@ -1,8 +1,7 @@ (function () { var ns = $.namespace("pskl.controller"); - - var MAC_TOUCHPAD_SKIP = 8; + var MOUSEWHEEL_THROTTLING = 20; ns.DrawingController = function (piskelController, paletteController, container) { /** @@ -47,7 +46,7 @@ this.previousMousemoveTime = 0; this.currentToolBehavior = null; - this.skipMouseWheelCounter_ = 0; + this.lastMouseWheel_ = 0; // State of clicked button (need to be stateful here, see comment in getCurrentColor_) this.currentMouseButton_ = Constants.LEFT_BUTTON; @@ -227,21 +226,18 @@ }; ns.DrawingController.prototype.onMousewheel_ = function (jQueryEvent) { - var event = jQueryEvent.originalEvent; - var delta = event.wheelDeltaY || (-2 * event.deltaY); + var now = Date.now(); - var isMacTouchpad = typeof event.webkitDirectionInvertedFromDevice === 'boolean'; - if (isMacTouchpad) { - if ((++this.skipMouseWheelCounter_%MAC_TOUCHPAD_SKIP)) { - return; + if (now - this.lastMouseWheel_ > MOUSEWHEEL_THROTTLING) { + this.lastMouseWheel_ = now; + var event = jQueryEvent.originalEvent; + var delta = event.wheelDeltaY || (-2 * event.deltaY); + if (delta > 0) { + this.increaseZoom_(); + } else if (delta < 0) { + this.decreaseZoom_(); } } - - if (delta > 0) { - this.increaseZoom_(); - } else if (delta < 0) { - this.decreaseZoom_(); - } }; /**