From eeef463ba654efbe0aa0a75610a82c5267b2be83 Mon Sep 17 00:00:00 2001 From: Andrew Harvey Date: Thu, 9 Mar 2017 22:49:08 +1100 Subject: [PATCH 1/3] Ensure DragRotate stops when the window looses focus. Fixes #3389 --- src/ui/handler/drag_rotate.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/ui/handler/drag_rotate.js b/src/ui/handler/drag_rotate.js index 8511b872d80..1d6caa4844f 100644 --- a/src/ui/handler/drag_rotate.js +++ b/src/ui/handler/drag_rotate.js @@ -29,7 +29,8 @@ class DragRotateHandler { util.bindAll([ '_onDown', '_onMove', - '_onUp' + '_onUp', + '_onBlur' ], this); } @@ -82,6 +83,7 @@ class DragRotateHandler { window.document.addEventListener('mousemove', this._onMove); window.document.addEventListener('mouseup', this._onUp); + window.addEventListener('blur', this._onBlur); this._active = false; this._inertia = [[Date.now(), this._map.getBearing()]]; @@ -91,6 +93,14 @@ class DragRotateHandler { e.preventDefault(); } + /** + * Deactivates DragRotate when the window looses focus. Otherwise the mouseup event is never fired and when the + * window comes back in focus DragRotate is still active even though the mouse isn't down. + */ + _onBlur(e) { + this._onUp(e); + } + _onMove(e) { if (this._ignoreEvent(e)) return; @@ -129,6 +139,7 @@ class DragRotateHandler { if (this._ignoreEvent(e)) return; window.document.removeEventListener('mousemove', this._onMove); window.document.removeEventListener('mouseup', this._onUp); + window.removeEventListener('blur', this._onBlur); if (!this.isActive()) return; From 39c04a418aa3587599f7b92d2d3eaa9aa8c8775f Mon Sep 17 00:00:00 2001 From: Andrew Harvey Date: Fri, 10 Mar 2017 08:12:08 +1100 Subject: [PATCH 2/3] simplify approach to de-activate DragRotate when the window loosese focus --- src/ui/handler/drag_rotate.js | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/ui/handler/drag_rotate.js b/src/ui/handler/drag_rotate.js index 1d6caa4844f..03d6897bfba 100644 --- a/src/ui/handler/drag_rotate.js +++ b/src/ui/handler/drag_rotate.js @@ -29,8 +29,7 @@ class DragRotateHandler { util.bindAll([ '_onDown', '_onMove', - '_onUp', - '_onBlur' + '_onUp' ], this); } @@ -83,7 +82,8 @@ class DragRotateHandler { window.document.addEventListener('mousemove', this._onMove); window.document.addEventListener('mouseup', this._onUp); - window.addEventListener('blur', this._onBlur); + /* 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()]]; @@ -93,14 +93,6 @@ class DragRotateHandler { e.preventDefault(); } - /** - * Deactivates DragRotate when the window looses focus. Otherwise the mouseup event is never fired and when the - * window comes back in focus DragRotate is still active even though the mouse isn't down. - */ - _onBlur(e) { - this._onUp(e); - } - _onMove(e) { if (this._ignoreEvent(e)) return; @@ -139,7 +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._onBlur); + window.removeEventListener('blur', this._onUp); if (!this.isActive()) return; From 1cdf1786f405b2562c0fddf4a7f7d1d1cdd24ff7 Mon Sep 17 00:00:00 2001 From: Andrew Harvey Date: Fri, 10 Mar 2017 08:29:42 +1100 Subject: [PATCH 3/3] de-activate DragPan when window loosese focus --- src/ui/handler/drag_pan.js | 5 ++++- src/ui/handler/drag_rotate.js | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ui/handler/drag_pan.js b/src/ui/handler/drag_pan.js index ba33b08de6c..0ac3cb38472 100644 --- a/src/ui/handler/drag_pan.js +++ b/src/ui/handler/drag_pan.js @@ -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); @@ -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) { @@ -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); } } diff --git a/src/ui/handler/drag_rotate.js b/src/ui/handler/drag_rotate.js index 03d6897bfba..4dc5b4d403a 100644 --- a/src/ui/handler/drag_rotate.js +++ b/src/ui/handler/drag_rotate.js @@ -82,7 +82,7 @@ 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. */ + /* 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;