From ebdfe029ce4bef3d8dd867aeefc4297d92afd822 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 16 Aug 2017 17:23:45 -0700 Subject: [PATCH] Inline _ignoreEvent into mousedown mousemove or mouseup handlers are bound only during the drag, and should never be ignored. --- src/ui/handler/drag_rotate.js | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/src/ui/handler/drag_rotate.js b/src/ui/handler/drag_rotate.js index 657e344d620..b204b0f2431 100644 --- a/src/ui/handler/drag_rotate.js +++ b/src/ui/handler/drag_rotate.js @@ -91,9 +91,21 @@ class DragRotateHandler { } _onDown(e: MouseEvent) { - if (this._ignoreEvent(e)) return; + if (this._map.boxZoom && this._map.boxZoom.isActive()) return; + if (this._map.dragPan && this._map.dragPan.isActive()) return; if (this.isActive()) return; + const button = (e.ctrlKey ? 0 : 2); // ? ctrl+left button : right button + let eventButton = e.button; + if (typeof window.InstallTrigger !== 'undefined' && e.button === 2 && e.ctrlKey && + window.navigator.platform.toUpperCase().indexOf('MAC') >= 0) { + // Fix for https://github.com/mapbox/mapbox-gl-js/issues/3131: + // Firefox (detected by InstallTrigger) on Mac determines e.button = 2 when + // using Control + left click + eventButton = 0; + } + if (eventButton !== button) return; + window.document.addEventListener('mousemove', this._onMove, {capture: true}); 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. */ @@ -108,8 +120,6 @@ class DragRotateHandler { } _onMove(e: MouseEvent) { - if (this._ignoreEvent(e)) return; - if (!this.isActive()) { this._active = true; this._map.moving = true; @@ -148,7 +158,6 @@ class DragRotateHandler { } _onUp(e: MouseEvent) { - if (this._ignoreEvent(e)) return; window.document.removeEventListener('mousemove', this._onMove); window.document.removeEventListener('mouseup', this._onUp); window.removeEventListener('blur', (this._onUp: any)); @@ -216,24 +225,6 @@ class DragRotateHandler { return this._map.fire(type, { originalEvent: e }); } - _ignoreEvent(e: MouseEvent) { - const map = this._map; - - if (map.boxZoom && map.boxZoom.isActive()) return true; - if (map.dragPan && map.dragPan.isActive()) return true; - - const button = (e.ctrlKey ? 0 : 2); // ? ctrl+left button : right button - let eventButton = e.button; - if (typeof window.InstallTrigger !== 'undefined' && e.button === 2 && e.ctrlKey && - window.navigator.platform.toUpperCase().indexOf('MAC') >= 0) { - // Fix for https://github.com/mapbox/mapbox-gl-js/issues/3131: - // Firefox (detected by InstallTrigger) on Mac determines e.button = 2 when - // using Control + left click - eventButton = 0; - } - return e.type !== 'mousemove' && !this.isActive() && eventButton !== button; - } - _drainInertiaBuffer() { const inertia = this._inertia, now = Date.now(),