Skip to content

Commit

Permalink
Inline _ignoreEvent into mousedown
Browse files Browse the repository at this point in the history
mousemove or mouseup handlers are bound only during the drag, and should never be ignored.
  • Loading branch information
jfirebaugh committed Aug 17, 2017
1 parent 9eae411 commit 211b753
Showing 1 changed file with 13 additions and 22 deletions.
35 changes: 13 additions & 22 deletions src/ui/handler/drag_rotate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -108,8 +120,6 @@ class DragRotateHandler {
}

_onMove(e: MouseEvent) {
if (this._ignoreEvent(e)) return;

if (!this.isActive()) {
this._active = true;
this._map.moving = true;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit 211b753

Please sign in to comment.