Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trackpad scrolling on Chromebook #514

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Trackpad scrolling on Chromebook
Change-Id: Iaccda3e98cca17dbd9a2099293ccbc15e434d8f1
Signed-off-by: mert <mert.tumer@collabora.com>
  • Loading branch information
mert committed Nov 4, 2020
commit 4fcb14bb62c64f80c55c1be4a97971ba1f4ea320
43 changes: 43 additions & 0 deletions loleaflet/src/map/handler/Map.Scroll.js
Expand Up @@ -17,13 +17,56 @@ L.Map.Scroll = L.Handler.extend({

this._delta = 0;
this._vertical = 1;
this.lastY = 0;
this.lastX = 0;

if (!this._map.touchGesture) {
L.DomEvent.on(this._map._container, {
touchstart: this._onTouchScrollStart,
touchmove: this._onTouchScroll,
}, this);
}
},

removeHooks: function () {
L.DomEvent.off(this._map._container, {
mousewheel: this._onWheelScroll,
MozMousePixelScroll: L.DomEvent.preventDefault
}, this);
if (!this._map.touchGesture) {
L.DomEvent.off(this._map._container, {
touchstart: this._onTouchScrollStart,
touchmove: this._onTouchScroll,
}, this);
}
},

_onTouchScrollStart: function (e) {
this.lastX = e.touches[0].clientX;
this.lastY = e.touches[0].clientY;
},

_onTouchScroll: function (e) {
var top = e.touches[0].clientY;
var start = e.touches[0].clientX;
var deltaX = (start - this.lastX);
var deltaY = (top - this.lastY);
var debounce = this._map.options.wheelDebounceTime;
if (!this._startTime) {
this._startTime = +new Date();
}
var left = Math.max(debounce - (+new Date() - this._startTime), 0);
clearTimeout(this._timer);

this.lastY = top;
if (Math.abs(deltaX) > Math.abs(deltaY)) {
this._vertical = 0;
this._delta += deltaX / 120;
} else {
this._delta += deltaY / 120;
this._vertical = 1;
}
this._timer = setTimeout(L.bind(this._performScroll, this), left);
},

_onWheelScroll: function (e) {
Expand Down