diff --git a/changelog.txt b/changelog.txt index bdc7bc02..ab324cfb 100644 --- a/changelog.txt +++ b/changelog.txt @@ -37,6 +37,7 @@ OPENSEADRAGON CHANGELOG * Fixed simulated drag events in navigator tests (#1949 @msalsbery) * Added preventDefault option to MouseTracker.contextMenuHandler and Viewer 'canvas-contextmenu' event args (#1951 @msalsbery) * MouseTracker: Added preProcessEventHandler for keydown, keyup, keypress, focus, blur Events (#1951 @msalsbery) +* Fixed preventDefaultAction functionality in viewer events (#1953 @msalsbery) 2.4.2: diff --git a/src/mousetracker.js b/src/mousetracker.js index b14a32e3..1b0699f2 100644 --- a/src/mousetracker.js +++ b/src/mousetracker.js @@ -495,8 +495,6 @@ * True if the original event is a touch event, otherwise false. Deprecated. Use pointerType and/or originalEvent instead. * @param {Object} event.originalEvent * The original event object. - * @param {Boolean} event.preventDefaultAction - * Set to true to prevent the tracker subscriber from performing its default action (subscriber implementation dependent). Default: false. * @param {Object} event.userData * Arbitrary user-defined object. */ @@ -528,8 +526,6 @@ * True if the original event is a touch event, otherwise false. Deprecated. Use pointerType and/or originalEvent instead. * @param {Object} event.originalEvent * The original event object. - * @param {Boolean} event.preventDefaultAction - * Set to true to prevent the tracker subscriber from performing its default action (subscriber implementation dependent). Default: false. * @param {Object} event.userData * Arbitrary user-defined object. */ @@ -561,8 +557,6 @@ * True if the original event is a touch event, otherwise false. Deprecated. Use pointerType and/or originalEvent instead. * @param {Object} event.originalEvent * The original event object. - * @param {Boolean} event.preventDefaultAction - * Set to true to prevent the tracker subscriber from performing its default action (subscriber implementation dependent). Default: false. * @param {Object} event.userData * Arbitrary user-defined object. */ @@ -586,8 +580,6 @@ * True if the original event is a touch event, otherwise false. Deprecated. Use pointerType and/or originalEvent instead. * @param {Object} event.originalEvent * The original event object. - * @param {Boolean} event.preventDefaultAction - * Set to true to prevent the tracker subscriber from performing its default action (subscriber implementation dependent). Default: false. * @param {Object} event.userData * Arbitrary user-defined object. */ @@ -614,8 +606,6 @@ * True if the original event is a touch event, otherwise false. Deprecated. Use pointerType and/or originalEvent instead. * @param {Object} event.originalEvent * The original event object. - * @param {Boolean} event.preventDefaultAction - * Set to true to prevent the tracker subscriber from performing its default action (subscriber implementation dependent). Default: false. * @param {Object} event.userData * Arbitrary user-defined object. */ @@ -644,8 +634,6 @@ * True if the original event is a touch event, otherwise false. Deprecated. Use pointerType and/or originalEvent instead. * @param {Object} event.originalEvent * The original event object. - * @param {Boolean} event.preventDefaultAction - * Set to true to prevent the tracker subscriber from performing its default action (subscriber implementation dependent). Default: false. * @param {Object} event.userData * Arbitrary user-defined object. */ @@ -672,8 +660,6 @@ * True if the original event is a touch event, otherwise false. Deprecated. Use pointerType and/or originalEvent instead. * @param {Object} event.originalEvent * The original event object. - * @param {Boolean} event.preventDefaultAction - * Set to true to prevent the tracker subscriber from performing its default action (subscriber implementation dependent). Default: false. * @param {Object} event.userData * Arbitrary user-defined object. */ @@ -697,8 +683,6 @@ * True if the original event is a touch event, otherwise false. Deprecated. Use pointerType and/or originalEvent instead. * @param {Object} event.originalEvent * The original event object. - * @param {Boolean} event.preventDefaultAction - * Set to true to prevent the tracker subscriber from performing its default action (subscriber implementation dependent). Default: false. * @param {Object} event.userData * Arbitrary user-defined object. */ @@ -723,8 +707,6 @@ * True if the original event is a touch event, otherwise false. Deprecated. Use pointerType and/or originalEvent instead. Touch devices no longer generate scroll event. * @param {Object} event.originalEvent * The original event object. - * @param {Boolean} event.preventDefaultAction - * Set to true to prevent the tracker subscriber from performing its default action (subscriber implementation dependent). Default: false. * @param {Object} event.userData * Arbitrary user-defined object. */ @@ -749,8 +731,6 @@ * True if the original event is a touch event, otherwise false. Deprecated. Use pointerType and/or originalEvent instead. * @param {Object} event.originalEvent * The original event object. - * @param {Boolean} event.preventDefaultAction - * Set to true to prevent the tracker subscriber from performing its default action (subscriber implementation dependent). Default: false. * @param {Object} event.userData * Arbitrary user-defined object. */ @@ -773,8 +753,6 @@ * True if the original event is a touch event, otherwise false. Deprecated. Use pointerType and/or originalEvent instead. * @param {Object} event.originalEvent * The original event object. - * @param {Boolean} event.preventDefaultAction - * Set to true to prevent the tracker subscriber from performing its default action (subscriber implementation dependent). Default: false. * @param {Object} event.userData * Arbitrary user-defined object. */ @@ -806,8 +784,6 @@ * True if the original event is a touch event, otherwise false. Deprecated. Use pointerType and/or originalEvent instead. * @param {Object} event.originalEvent * The original event object. - * @param {Boolean} event.preventDefaultAction - * Set to true to prevent the tracker subscriber from performing its default action (subscriber implementation dependent). Default: false. * @param {Object} event.userData * Arbitrary user-defined object. */ @@ -834,8 +810,6 @@ * True if the original event is a touch event, otherwise false. Deprecated. Use pointerType and/or originalEvent instead. * @param {Object} event.originalEvent * The original event object. - * @param {Boolean} event.preventDefaultAction - * Set to true to prevent the tracker subscriber from performing its default action (subscriber implementation dependent). Default: false. * @param {Object} event.userData * Arbitrary user-defined object. */ @@ -864,8 +838,6 @@ * True if the shift key was pressed during this event. * @param {Object} event.originalEvent * The original event object. - * @param {Boolean} event.preventDefaultAction - * Set to true to prevent the tracker subscriber from performing its default action (subscriber implementation dependent). Default: false. * @param {Object} event.userData * Arbitrary user-defined object. */ @@ -889,8 +861,6 @@ * True if the original event is a touch event, otherwise false. Deprecated. Use pointerType and/or originalEvent instead. * @param {Object} event.originalEvent * The original event object. - * @param {Boolean} event.preventDefaultAction - * Set to true to prevent the tracker subscriber from performing its default action (subscriber implementation dependent). Default: false. * @param {Object} event.userData * Arbitrary user-defined object. */ @@ -915,8 +885,6 @@ * True if the meta key was pressed during this event. * @param {Object} event.originalEvent * The original event object. - * @param {Boolean} event.preventDefaultAction - * Set to true to prevent the tracker subscriber from performing its default action (subscriber implementation dependent). Default: false. * @param {Object} event.userData * Arbitrary user-defined object. */ @@ -941,8 +909,6 @@ * True if the meta key was pressed during this event. * @param {Object} event.originalEvent * The original event object. - * @param {Boolean} event.preventDefaultAction - * Set to true to prevent the tracker subscriber from performing its default action (subscriber implementation dependent). Default: false. * @param {Object} event.userData * Arbitrary user-defined object. */ @@ -967,8 +933,6 @@ * True if the meta key was pressed during this event. * @param {Object} event.originalEvent * The original event object. - * @param {Boolean} event.preventDefaultAction - * Set to true to prevent the tracker subscriber from performing its default action (subscriber implementation dependent). Default: false. * @param {Object} event.userData * Arbitrary user-defined object. */ @@ -983,8 +947,6 @@ * A reference to the tracker instance. * @param {Object} event.originalEvent * The original event object. - * @param {Boolean} event.preventDefaultAction - * Set to true to prevent the tracker subscriber from performing its default action (subscriber implementation dependent). Default: false. * @param {Object} event.userData * Arbitrary user-defined object. */ @@ -999,8 +961,6 @@ * A reference to the tracker instance. * @param {Object} event.originalEvent * The original event object. - * @param {Boolean} event.preventDefaultAction - * Set to true to prevent the tracker subscriber from performing its default action (subscriber implementation dependent). Default: false. * @param {Object} event.userData * Arbitrary user-defined object. */ @@ -1830,7 +1790,6 @@ alt: event.altKey, meta: event.metaKey, originalEvent: event, - preventDefaultAction: false, userData: tracker.userData } ); @@ -1870,7 +1829,6 @@ alt: event.altKey, meta: event.metaKey, originalEvent: event, - preventDefaultAction: false, userData: tracker.userData } ); @@ -1910,7 +1868,6 @@ alt: event.altKey, meta: event.metaKey, originalEvent: event, - preventDefaultAction: false, userData: tracker.userData } ); @@ -1948,7 +1905,6 @@ { eventSource: tracker, originalEvent: event, - preventDefaultAction: false, userData: tracker.userData } ); @@ -1979,7 +1935,6 @@ { eventSource: tracker, originalEvent: event, - preventDefaultAction: false, userData: tracker.userData } ); @@ -2107,7 +2062,6 @@ shift: event.shiftKey, isTouchEvent: false, originalEvent: originalEvent, - preventDefaultAction: false, userData: tracker.userData } ); @@ -3170,7 +3124,6 @@ buttonDownAny: pointsList.buttons !== 0, isTouchEvent: gPoint.type === 'touch', originalEvent: eventInfo.originalEvent, - preventDefaultAction: false, userData: tracker.userData } ); @@ -3216,7 +3169,6 @@ buttonDownAny: pointsList.buttons !== 0, isTouchEvent: gPoint.type === 'touch', originalEvent: eventInfo.originalEvent, - preventDefaultAction: false, userData: tracker.userData } ); } @@ -3287,7 +3239,6 @@ buttons: pointsList.buttons, isTouchEvent: gPoint.type === 'touch', originalEvent: eventInfo.originalEvent, - preventDefaultAction: false, userData: tracker.userData } ); @@ -3342,7 +3293,6 @@ buttons: pointsList.buttons, isTouchEvent: gPoint.type === 'touch', originalEvent: eventInfo.originalEvent, - preventDefaultAction: false, userData: tracker.userData } ); @@ -3431,7 +3381,6 @@ buttons: pointsList.buttons, isTouchEvent: gPoint.type === 'touch', originalEvent: eventInfo.originalEvent, - preventDefaultAction: false, userData: tracker.userData } ); @@ -3497,7 +3446,6 @@ insideElementReleased: updateGPoint.insideElement, isTouchEvent: updateGPoint.type === 'touch', originalEvent: eventInfo.originalEvent, - preventDefaultAction: false, userData: tracker.userData } ); @@ -3515,7 +3463,6 @@ shift: eventInfo.originalEvent.shiftKey, isTouchEvent: updateGPoint.type === 'touch', originalEvent: eventInfo.originalEvent, - preventDefaultAction: false, userData: tracker.userData } ); @@ -3537,7 +3484,6 @@ shift: eventInfo.originalEvent.shiftKey, isTouchEvent: updateGPoint.type === 'touch', originalEvent: eventInfo.originalEvent, - preventDefaultAction: false, userData: tracker.userData } ); @@ -3565,7 +3511,6 @@ shift: eventInfo.originalEvent.shiftKey, isTouchEvent: updateGPoint.type === 'touch', originalEvent: eventInfo.originalEvent, - preventDefaultAction: false, userData: tracker.userData } ); @@ -3599,7 +3544,6 @@ insideElementReleased: updateGPoint.insideElement, isTouchEvent: updateGPoint.type === 'touch', originalEvent: eventInfo.originalEvent, - preventDefaultAction: false, userData: tracker.userData } ); @@ -3672,7 +3616,6 @@ buttons: pointsList.buttons, isTouchEvent: gPoint.type === 'touch', originalEvent: eventInfo.originalEvent, - preventDefaultAction: false, userData: tracker.userData } ); @@ -3689,7 +3632,6 @@ buttons: pointsList.buttons, isTouchEvent: updateGPoint.type === 'touch', originalEvent: eventInfo.originalEvent, - preventDefaultAction: false, userData: tracker.userData } ); @@ -3711,7 +3653,6 @@ shift: eventInfo.originalEvent.shiftKey, isTouchEvent: updateGPoint.type === 'touch', originalEvent: eventInfo.originalEvent, - preventDefaultAction: false, userData: tracker.userData } ); @@ -3729,7 +3670,6 @@ buttons: pointsList.buttons, isTouchEvent: gPointArray[ 0 ].type === 'touch', originalEvent: eventInfo.originalEvent, - preventDefaultAction: false, userData: tracker.userData } ); @@ -3755,7 +3695,6 @@ distance: delegate.currentPinchDist, shift: eventInfo.originalEvent.shiftKey, originalEvent: eventInfo.originalEvent, - preventDefaultAction: false, userData: tracker.userData } ); @@ -3802,7 +3741,6 @@ buttons: tracker.getActivePointersListByType( pointerType ).buttons, isTouchEvent: pointerType === 'touch', originalEvent: originalMoveEvent, - preventDefaultAction: false, userData: tracker.userData } ); } diff --git a/src/navigator.js b/src/navigator.js index cbe0780e..82d2cbad 100644 --- a/src/navigator.js +++ b/src/navigator.js @@ -471,7 +471,7 @@ function onCanvasClick( event ) { quick: event.quick, shift: event.shift, originalEvent: event.originalEvent, - preventDefaultAction: event.preventDefaultAction + preventDefaultAction: false }; /** * Raised when a click event occurs on the {@link OpenSeadragon.Viewer#navigator} element. @@ -523,7 +523,7 @@ function onCanvasDrag( event ) { direction: event.direction, shift: event.shift, originalEvent: event.originalEvent, - preventDefaultAction: event.preventDefaultAction + preventDefaultAction: false }; /** * Raised when a drag event occurs on the {@link OpenSeadragon.Viewer#navigator} element. diff --git a/src/referencestrip.js b/src/referencestrip.js index ee609057..80ebf566 100644 --- a/src/referencestrip.js +++ b/src/referencestrip.js @@ -524,7 +524,7 @@ function onStripLeave( event ) { function onKeyDown( event ) { //console.log( event.keyCode ); - if ( !event.preventDefaultAction && !event.ctrl && !event.alt && !event.meta ) { + if ( !event.ctrl && !event.alt && !event.meta ) { switch ( event.keyCode ) { case 38: //up arrow onStripScroll.call( this, { eventSource: this.tracker, position: null, scroll: 1, shift: null } ); @@ -556,7 +556,7 @@ function onKeyDown( event ) { function onKeyPress( event ) { //console.log( event.keyCode ); - if ( !event.preventDefaultAction && !event.ctrl && !event.alt && !event.meta ) { + if ( !event.ctrl && !event.alt && !event.meta ) { switch ( event.keyCode ) { case 61: //=|+ onStripScroll.call( this, { eventSource: this.tracker, position: null, scroll: 1, shift: null } ); diff --git a/src/viewer.js b/src/viewer.js index 21d6f469..6e9c65b1 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -2574,7 +2574,7 @@ function onCanvasContextMenu( event ) { function onCanvasKeyDown( event ) { var canvasKeyDownEventArgs = { originalEvent: event.originalEvent, - preventDefaultAction: event.preventDefaultAction, + preventDefaultAction: false, preventVerticalPan: event.preventVerticalPan, preventHorizontalPan: event.preventHorizontalPan }; @@ -2606,7 +2606,7 @@ function onCanvasKeyDown( event ) { } this.viewport.applyConstraints(); } - return false; + break; case 40://down arrow if (!canvasKeyDownEventArgs.preventVerticalPan) { if ( event.shift ) { @@ -2616,31 +2616,29 @@ function onCanvasKeyDown( event ) { } this.viewport.applyConstraints(); } - return false; + break; case 37://left arrow if (!canvasKeyDownEventArgs.preventHorizontalPan) { this.viewport.panBy(this.viewport.deltaPointsFromPixels(new $.Point(-this.pixelsPerArrowPress, 0))); this.viewport.applyConstraints(); } - return false; + break; case 39://right arrow if (!canvasKeyDownEventArgs.preventHorizontalPan) { this.viewport.panBy(this.viewport.deltaPointsFromPixels(new $.Point(this.pixelsPerArrowPress, 0))); this.viewport.applyConstraints(); } - return false; + break; default: //console.log( 'navigator keycode %s', event.keyCode ); - return true; + break; } - } else { - return true; } } function onCanvasKeyPress( event ) { var canvasKeyPressEventArgs = { originalEvent: event.originalEvent, - preventDefaultAction: event.preventDefaultAction, + preventDefaultAction: false, preventVerticalPan: event.preventVerticalPan, preventHorizontalPan: event.preventHorizontalPan }; @@ -2654,15 +2652,15 @@ function onCanvasKeyPress( event ) { case 61://=|+ this.viewport.zoomBy(1.1); this.viewport.applyConstraints(); - return false; + break; case 45://-|_ this.viewport.zoomBy(0.9); this.viewport.applyConstraints(); - return false; + break; case 48://0|) this.viewport.goHome(); this.viewport.applyConstraints(); - return false; + break; case 119://w case 87://W if (!canvasKeyPressEventArgs.preventVerticalPan) { @@ -2673,7 +2671,7 @@ function onCanvasKeyPress( event ) { } this.viewport.applyConstraints(); } - return false; + break; case 115://s case 83://S if (!canvasKeyPressEventArgs.preventVerticalPan) { @@ -2684,19 +2682,19 @@ function onCanvasKeyPress( event ) { } this.viewport.applyConstraints(); } - return false; + break; case 97://a if (!canvasKeyPressEventArgs.preventHorizontalPan) { this.viewport.panBy(this.viewport.deltaPointsFromPixels(new $.Point(-40, 0))); this.viewport.applyConstraints(); } - return false; + break; case 100://d if (!canvasKeyPressEventArgs.preventHorizontalPan) { this.viewport.panBy(this.viewport.deltaPointsFromPixels(new $.Point(40, 0))); this.viewport.applyConstraints(); } - return false; + break; case 114: //r - clockwise rotation if(this.viewport.flipped){ this.viewport.setRotation($.positiveModulo(this.viewport.degrees - this.rotationIncrement, 360)); @@ -2704,7 +2702,7 @@ function onCanvasKeyPress( event ) { this.viewport.setRotation($.positiveModulo(this.viewport.degrees + this.rotationIncrement, 360)); } this.viewport.applyConstraints(); - return false; + break; case 82: //R - counterclockwise rotation if(this.viewport.flipped){ this.viewport.setRotation($.positiveModulo(this.viewport.degrees + this.rotationIncrement, 360)); @@ -2712,16 +2710,14 @@ function onCanvasKeyPress( event ) { this.viewport.setRotation($.positiveModulo(this.viewport.degrees - this.rotationIncrement, 360)); } this.viewport.applyConstraints(); - return false; + break; case 102: //f this.viewport.toggleFlip(); - return false; + break; default: // console.log( 'navigator keycode %s', event.keyCode ); - return true; + break; } - } else { - return true; } } @@ -2744,7 +2740,7 @@ function onCanvasClick( event ) { quick: event.quick, shift: event.shift, originalEvent: event.originalEvent, - preventDefaultAction: event.preventDefaultAction + preventDefaultAction: false }; /** @@ -2784,7 +2780,7 @@ function onCanvasDblClick( event ) { position: event.position, shift: event.shift, originalEvent: event.originalEvent, - preventDefaultAction: event.preventDefaultAction + preventDefaultAction: false }; /** @@ -2827,7 +2823,7 @@ function onCanvasDrag( event ) { direction: event.direction, shift: event.shift, originalEvent: event.originalEvent, - preventDefaultAction: event.preventDefaultAction + preventDefaultAction: false }; /** @@ -2888,7 +2884,37 @@ function onCanvasDrag( event ) { } function onCanvasDragEnd( event ) { - if (!event.preventDefaultAction && this.viewport) { + var canvasDragEndEventArgs = { + tracker: event.eventSource, + pointerType: event.pointerType, + position: event.position, + speed: event.speed, + direction: event.direction, + shift: event.shift, + originalEvent: event.originalEvent, + preventDefaultAction: false + }; + + /** + * Raised when a mouse or touch drag operation ends on the {@link OpenSeadragon.Viewer#canvas} element. + * + * @event canvas-drag-end + * @memberof OpenSeadragon.Viewer + * @type {object} + * @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised this event. + * @property {OpenSeadragon.MouseTracker} tracker - A reference to the MouseTracker which originated this event. + * @property {String} pointerType - "mouse", "touch", "pen", etc. + * @property {OpenSeadragon.Point} position - The position of the event relative to the tracked element. + * @property {Number} speed - Speed at the end of a drag gesture, in pixels per second. + * @property {Number} direction - Direction at the end of a drag gesture, expressed as an angle counterclockwise relative to the positive X axis (-pi to pi, in radians). Only valid if speed > 0. + * @property {Boolean} shift - True if the shift key was pressed during this event. + * @property {Object} originalEvent - The original DOM event. + * @property {Boolean} preventDefaultAction - Set to true to prevent default drag-end flick behaviour. Default: false. + * @property {?Object} userData - Arbitrary subscriber-defined object. + */ + this.raiseEvent('canvas-drag-end', canvasDragEndEventArgs); + + if (!canvasDragEndEventArgs.preventDefaultAction && this.viewport) { var gestureSettings = this.gestureSettingsByDeviceType(event.pointerType); if (gestureSettings.flickEnabled && event.speed >= gestureSettings.flickMinSpeed) { @@ -2910,31 +2936,6 @@ function onCanvasDragEnd( event ) { } this.viewport.applyConstraints(); } - /** - * Raised when a mouse or touch drag operation ends on the {@link OpenSeadragon.Viewer#canvas} element. - * - * @event canvas-drag-end - * @memberof OpenSeadragon.Viewer - * @type {object} - * @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised this event. - * @property {OpenSeadragon.MouseTracker} tracker - A reference to the MouseTracker which originated this event. - * @property {String} pointerType - "mouse", "touch", "pen", etc. - * @property {OpenSeadragon.Point} position - The position of the event relative to the tracked element. - * @property {Number} speed - Speed at the end of a drag gesture, in pixels per second. - * @property {Number} direction - Direction at the end of a drag gesture, expressed as an angle counterclockwise relative to the positive X axis (-pi to pi, in radians). Only valid if speed > 0. - * @property {Boolean} shift - True if the shift key was pressed during this event. - * @property {Object} originalEvent - The original DOM event. - * @property {?Object} userData - Arbitrary subscriber-defined object. - */ - this.raiseEvent('canvas-drag-end', { - tracker: event.eventSource, - pointerType: event.pointerType, - position: event.position, - speed: event.speed, - direction: event.direction, - shift: event.shift, - originalEvent: event.originalEvent - }); } function onCanvasEnter( event ) { @@ -3111,33 +3112,21 @@ function onCanvasPinch( event ) { lastCenterPt, panByPt; - if ( !event.preventDefaultAction && this.viewport ) { - gestureSettings = this.gestureSettingsByDeviceType( event.pointerType ); - if ( gestureSettings.pinchToZoom ) { - centerPt = this.viewport.pointFromPixel( event.center, true ); - lastCenterPt = this.viewport.pointFromPixel( event.lastCenter, true ); - panByPt = lastCenterPt.minus( centerPt ); - if( !this.panHorizontal ) { - panByPt.x = 0; - } - if( !this.panVertical ) { - panByPt.y = 0; - } - this.viewport.zoomBy( event.distance / event.lastDistance, centerPt, true ); - if ( gestureSettings.zoomToRefPoint ) { - this.viewport.panBy(panByPt, true); - } - this.viewport.applyConstraints(); - } - if ( gestureSettings.pinchRotate ) { - // Pinch rotate - var angle1 = Math.atan2(event.gesturePoints[0].currentPos.y - event.gesturePoints[1].currentPos.y, - event.gesturePoints[0].currentPos.x - event.gesturePoints[1].currentPos.x); - var angle2 = Math.atan2(event.gesturePoints[0].lastPos.y - event.gesturePoints[1].lastPos.y, - event.gesturePoints[0].lastPos.x - event.gesturePoints[1].lastPos.x); - this.viewport.setRotation(this.viewport.getRotation() + ((angle1 - angle2) * (180 / Math.PI))); - } - } + var canvasPinchEventArgs = { + tracker: event.eventSource, + pointerType: event.pointerType, + gesturePoints: event.gesturePoints, + lastCenter: event.lastCenter, + center: event.center, + lastDistance: event.lastDistance, + distance: event.distance, + shift: event.shift, + originalEvent: event.originalEvent, + preventDefaultPanAction: false, + preventDefaultZoomAction: false, + preventDefaultRotateAction: false + }; + /** * Raised when a pinch event occurs on the {@link OpenSeadragon.Viewer#canvas} element. * @@ -3154,25 +3143,48 @@ function onCanvasPinch( event ) { * @property {Number} distance - The distance between the two pinch contact points in CSS pixels. * @property {Boolean} shift - True if the shift key was pressed during this event. * @property {Object} originalEvent - The original DOM event. + * @property {Boolean} preventDefaultPanAction - Set to true to prevent default pinch to pan behaviour. Default: false. + * @property {Boolean} preventDefaultZoomAction - Set to true to prevent default pinch to zoom behaviour. Default: false. + * @property {Boolean} preventDefaultRotateAction - Set to true to prevent default pinch to rotate behaviour. Default: false. * @property {?Object} userData - Arbitrary subscriber-defined object. */ - this.raiseEvent('canvas-pinch', { - tracker: event.eventSource, - pointerType: event.pointerType, - gesturePoints: event.gesturePoints, - lastCenter: event.lastCenter, - center: event.center, - lastDistance: event.lastDistance, - distance: event.distance, - shift: event.shift, - originalEvent: event.originalEvent - }); - //cancels event - return false; + this.raiseEvent('canvas-pinch', canvasPinchEventArgs); + + if ( this.viewport ) { + gestureSettings = this.gestureSettingsByDeviceType( event.pointerType ); + if ( gestureSettings.pinchToZoom && + (!canvasPinchEventArgs.preventDefaultPanAction || !canvasPinchEventArgs.preventDefaultZoomAction) ) { + centerPt = this.viewport.pointFromPixel( event.center, true ); + if ( !canvasPinchEventArgs.preventDefaultZoomAction ) { + this.viewport.zoomBy( event.distance / event.lastDistance, centerPt, true ); + } + if ( gestureSettings.zoomToRefPoint && !canvasPinchEventArgs.preventDefaultPanAction ) { + lastCenterPt = this.viewport.pointFromPixel( event.lastCenter, true ); + panByPt = lastCenterPt.minus( centerPt ); + if( !this.panHorizontal ) { + panByPt.x = 0; + } + if( !this.panVertical ) { + panByPt.y = 0; + } + this.viewport.panBy(panByPt, true); + } + this.viewport.applyConstraints(); + } + if ( gestureSettings.pinchRotate && !canvasPinchEventArgs.preventDefaultRotateAction ) { + // Pinch rotate + var angle1 = Math.atan2(event.gesturePoints[0].currentPos.y - event.gesturePoints[1].currentPos.y, + event.gesturePoints[0].currentPos.x - event.gesturePoints[1].currentPos.x); + var angle2 = Math.atan2(event.gesturePoints[0].lastPos.y - event.gesturePoints[1].lastPos.y, + event.gesturePoints[0].lastPos.x - event.gesturePoints[1].lastPos.x); + this.viewport.setRotation(this.viewport.getRotation() + ((angle1 - angle2) * (180 / Math.PI))); + } + } } function onCanvasScroll( event ) { - var gestureSettings, + var canvasScrollEventArgs, + gestureSettings, factor, thisScrollTime, deltaScrollTime; @@ -3185,21 +3197,15 @@ function onCanvasScroll( event ) { if (deltaScrollTime > this.minScrollDeltaTime) { this._lastScrollTime = thisScrollTime; - if(this.viewport.flipped){ - event.position.x = this.viewport.getContainerSize().x - event.position.x; - } + canvasScrollEventArgs = { + tracker: event.eventSource, + position: event.position, + scroll: event.scroll, + shift: event.shift, + originalEvent: event.originalEvent, + preventDefaultAction: false + }; - if ( !event.preventDefaultAction && this.viewport ) { - gestureSettings = this.gestureSettingsByDeviceType( event.pointerType ); - if ( gestureSettings.scrollToZoom ) { - factor = Math.pow( this.zoomPerScroll, event.scroll ); - this.viewport.zoomBy( - factor, - gestureSettings.zoomToRefPoint ? this.viewport.pointFromPixel( event.position, true ) : null - ); - this.viewport.applyConstraints(); - } - } /** * Raised when a scroll event occurs on the {@link OpenSeadragon.Viewer#canvas} element (mouse wheel). * @@ -3212,28 +3218,27 @@ function onCanvasScroll( event ) { * @property {Number} scroll - The scroll delta for the event. * @property {Boolean} shift - True if the shift key was pressed during this event. * @property {Object} originalEvent - The original DOM event. + * @property {Boolean} preventDefaultAction - Set to true to prevent default scroll to zoom behaviour. Default: false. * @property {?Object} userData - Arbitrary subscriber-defined object. */ - this.raiseEvent( 'canvas-scroll', { - tracker: event.eventSource, - position: event.position, - scroll: event.scroll, - shift: event.shift, - originalEvent: event.originalEvent - }); - if (gestureSettings && gestureSettings.scrollToZoom) { - //cancels event - return false; - } - } - else { - gestureSettings = this.gestureSettingsByDeviceType( event.pointerType ); - if (gestureSettings && gestureSettings.scrollToZoom) { - return false; // We are swallowing this event - } - } + this.raiseEvent('canvas-scroll', canvasScrollEventArgs ); - return undefined; + if ( !canvasScrollEventArgs.preventDefaultAction && this.viewport ) { + if(this.viewport.flipped){ + event.position.x = this.viewport.getContainerSize().x - event.position.x; + } + + gestureSettings = this.gestureSettingsByDeviceType( event.pointerType ); + if ( gestureSettings.scrollToZoom ) { + factor = Math.pow( this.zoomPerScroll, event.scroll ); + this.viewport.zoomBy( + factor, + gestureSettings.zoomToRefPoint ? this.viewport.pointFromPixel( event.position, true ) : null + ); + this.viewport.applyConstraints(); + } + } + } } function onContainerEnter( event ) { diff --git a/test/modules/events.js b/test/modules/events.js index d07a3eea..5fdf9cbb 100644 --- a/test/modules/events.js +++ b/test/modules/events.js @@ -679,8 +679,7 @@ if ('TouchEvent' in window) { QUnit.test( 'MouseTracker: touch events', function (assert) { var done = assert.async(); - var $canvas = $( viewer.element ).find( '.openseadragon-canvas' ).not( '.navigator .openseadragon-canvas' ), - tracker = viewer.innerTracker, + var tracker = viewer.innerTracker, touches; var reset = function () { @@ -757,7 +756,6 @@ var done = assert.async(); var $canvas = $(viewer.element).find('.openseadragon-canvas') .not('.navigator .openseadragon-canvas'); - var tracker = viewer.innerTracker; var epsilon = 0.0000001; function simulateClickAndDrag() { @@ -787,16 +785,14 @@ viewer.removeHandler('open', onOpen); // Hook viewer events to set preventDefaultAction - var origClickHandler = tracker.clickHandler; - tracker.clickHandler = function(event) { + var onCanvasClick = function (event) { event.preventDefaultAction = true; - return origClickHandler(event); }; - var origDragHandler = tracker.dragHandler; - tracker.dragHandler = function(event) { + var onCanvasDrag = function (event) { event.preventDefaultAction = true; - return origDragHandler(event); }; + viewer.addHandler("canvas-click", onCanvasClick); + viewer.addHandler("canvas-drag", onCanvasDrag); var originalZoom = viewer.viewport.getZoom(); var originalBounds = viewer.viewport.getBounds(); @@ -810,8 +806,8 @@ Util.assertRectangleEquals(assert, bounds, originalBounds, epsilon, 'Pan should be prevented'); - tracker.clickHandler = origClickHandler; - tracker.dragHandler = origDragHandler; + viewer.removeHandler("canvas-click", onCanvasClick); + viewer.removeHandler("canvas-drag", onCanvasDrag); simulateClickAndDrag(); @@ -855,12 +851,12 @@ var originalZoom = viewer.viewport.getZoom(); - var origDblClickHandler = tracker.dblClickHandler; - tracker.dblClickHandler = function(event) { + var onCanvasDblClick = function (event) { event.preventDefaultAction = true; - return origDblClickHandler(event); }; + viewer.addHandler('canvas-double-click', onCanvasDblClick); + TouchUtil.initTracker(tracker); simulateDblTap(); @@ -869,36 +865,16 @@ "Zoom on double tap should be prevented"); // Reset event handler to original - tracker.dblClickHandler = origDblClickHandler; + viewer.removeHandler("canvas-double-click", onCanvasDblClick); simulateDblTap(); - originalZoom = originalZoom * viewer.zoomPerClick; + originalZoom *= viewer.zoomPerClick; zoom = viewer.viewport.getZoom(); Util.assessNumericValue(assert, originalZoom, zoom, epsilon, "Zoom on double tap should not be prevented"); - var dblClickHandler = function(event) { - event.preventDefaultAction = true; - }; - - viewer.addHandler('canvas-double-click', dblClickHandler); - - zoom = viewer.viewport.getZoom(); - Util.assessNumericValue(assert, originalZoom, zoom, epsilon, - "Zoom on double tap should be prevented"); - - // Remove custom event handler - viewer.removeHandler('canvas-double-click', dblClickHandler); - - simulateDblTap(); - originalZoom = originalZoom * viewer.zoomPerClick; - - zoom = viewer.viewport.getZoom(); - Util.assessNumericValue(assert, originalZoom, zoom, epsilon, - "Zoom on double tap should not be prevented"); - TouchUtil.resetTracker(tracker); viewer.close(); done(); @@ -926,10 +902,9 @@ eventsHandledViewer = 0, originalEventsPassedViewer = 0, dragEndsExpected = 1, - releasesExpected = 1, - clicksExpected = 1; + releasesExpected = 1; - var onOpen = function ( event ) { + var onOpen = function ( ) { viewer.removeHandler( 'open', onOpen ); viewer.addHandler( 'canvas-drag', onEventSourceDrag );