Skip to content

Commit

Permalink
Ensure DragRotate stops when the window looses focus. Fixes mapbox#3389
Browse files Browse the repository at this point in the history
… (mapbox#4390)

* Ensure DragRotate stops when the window looses focus. Fixes mapbox#3389

* simplify approach to de-activate DragRotate when the window loosese focus

* de-activate DragPan when window loosese focus
  • Loading branch information
andrewharvey committed Mar 17, 2017
1 parent c07008c commit 59d75b5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/ui/handler/drag_pan.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ class DragPanHandler {
window.document.addEventListener('mousemove', this._onMove);
window.document.addEventListener('mouseup', this._onMouseUp);
}
/* Deactivate DragPan when the window looses focus. Otherwise if a mouseup occurs when the window isn't in focus, DragPan will still be active even though the mouse is no longer pressed. */
window.addEventListener('blur', this._onMouseUp);

this._active = false;
this._startPos = this._pos = DOM.mousePos(this._el, e);
Expand Down Expand Up @@ -169,6 +171,7 @@ class DragPanHandler {
this._onUp(e);
window.document.removeEventListener('mousemove', this._onMove);
window.document.removeEventListener('mouseup', this._onMouseUp);
window.removeEventListener('blur', this._onMouseUp);
}

_onTouchEnd(e) {
Expand All @@ -193,7 +196,7 @@ class DragPanHandler {
if (e.ctrlKey) return true;
const buttons = 1, // left button
button = 0; // left button
return (e.type === 'mousemove' ? e.buttons & buttons === 0 : e.button !== button);
return (e.type === 'mousemove' ? e.buttons & buttons === 0 : e.button && e.button !== button);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/ui/handler/drag_rotate.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ class DragRotateHandler {

window.document.addEventListener('mousemove', this._onMove);
window.document.addEventListener('mouseup', this._onUp);
/* Deactivate DragRotate when the window looses focus. Otherwise if a mouseup occurs when the window isn't in focus, DragRotate will still be active even though the mouse is no longer pressed. */
window.addEventListener('blur', this._onUp);

this._active = false;
this._inertia = [[Date.now(), this._map.getBearing()]];
Expand Down Expand Up @@ -129,6 +131,7 @@ class DragRotateHandler {
if (this._ignoreEvent(e)) return;
window.document.removeEventListener('mousemove', this._onMove);
window.document.removeEventListener('mouseup', this._onUp);
window.removeEventListener('blur', this._onUp);

if (!this.isActive()) return;

Expand Down

0 comments on commit 59d75b5

Please sign in to comment.