From 2b878cbdbf20bc0854f2b81315826f9815c463c8 Mon Sep 17 00:00:00 2001 From: Francesco Cretti Date: Tue, 6 Mar 2018 15:51:22 +0100 Subject: [PATCH 1/3] keyboard handlers patch --- src/viewer.js | 87 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 60 insertions(+), 27 deletions(-) diff --git a/src/viewer.js b/src/viewer.js index 51b22756..baecef38 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -2477,31 +2477,48 @@ function onBlur(){ } function onCanvasKeyDown( event ) { - if ( !event.preventDefaultAction && !event.ctrl && !event.alt && !event.meta ) { + var canvasKeyDownEventArgs = { + originalEvent: event.originalEvent, + preventDefaultAction: event.preventDefaultAction, + preventVerticalPan: event.preventVerticalPan, + preventHorizontalPan: event.preventHorizontalPan + }; + + this.raiseEvent( 'canvas-key-down', canvasKeyDownEventArgs); + + if ( !canvasKeyDownEventArgs.preventDefaultAction && !event.ctrl && !event.alt && !event.meta ) { switch( event.keyCode ){ case 38://up arrow - if ( event.shift ) { + if (!canvasKeyDownEventArgs.preventVerticalPan) { + if ( event.shift ) { this.viewport.zoomBy(1.1); - } else { + } else { this.viewport.panBy(this.viewport.deltaPointsFromPixels(new $.Point(0, -this.pixelsPerArrowPress))); + } + this.viewport.applyConstraints(); } - this.viewport.applyConstraints(); return false; case 40://down arrow - if ( event.shift ) { + if (!canvasKeyDownEventArgs.preventVerticalPan) { + if ( event.shift ) { this.viewport.zoomBy(0.9); - } else { + } else { this.viewport.panBy(this.viewport.deltaPointsFromPixels(new $.Point(0, this.pixelsPerArrowPress))); + } + this.viewport.applyConstraints(); } - this.viewport.applyConstraints(); return false; case 37://left arrow - this.viewport.panBy(this.viewport.deltaPointsFromPixels(new $.Point(-this.pixelsPerArrowPress, 0))); - this.viewport.applyConstraints(); + if (!canvasKeyDownEventArgs.preventHorizontalPan) { + this.viewport.panBy(this.viewport.deltaPointsFromPixels(new $.Point(-this.pixelsPerArrowPress, 0))); + this.viewport.applyConstraints(); + } return false; case 39://right arrow - this.viewport.panBy(this.viewport.deltaPointsFromPixels(new $.Point(this.pixelsPerArrowPress, 0))); - this.viewport.applyConstraints(); + if (!canvasKeyDownEventArgs.preventHorizontalPan) { + this.viewport.panBy(this.viewport.deltaPointsFromPixels(new $.Point(this.pixelsPerArrowPress, 0))); + this.viewport.applyConstraints(); + } return false; default: //console.log( 'navigator keycode %s', event.keyCode ); @@ -2511,9 +2528,17 @@ function onCanvasKeyDown( event ) { return true; } } - function onCanvasKeyPress( event ) { - if ( !event.preventDefaultAction && !event.ctrl && !event.alt && !event.meta ) { + var canvasKeyPressEventArgs = { + originalEvent: event.originalEvent, + preventDefaultAction: event.preventDefaultAction, + preventVerticalPan: event.preventVerticalPan, + preventHorizontalPan: event.preventHorizontalPan + }; + + this.raiseEvent( 'canvas-key-down', canvasKeyPressEventArgs); + + if ( !canvasKeyPressEventArgs.preventDefaultAction && !event.ctrl && !event.alt && !event.meta ) { switch( event.keyCode ){ case 43://=|+ case 61://=|+ @@ -2530,29 +2555,37 @@ function onCanvasKeyPress( event ) { return false; case 119://w case 87://W - if ( event.shift ) { - this.viewport.zoomBy(1.1); - } else { - this.viewport.panBy(this.viewport.deltaPointsFromPixels(new $.Point(0, -40))); - } - this.viewport.applyConstraints(); - return false; + if (!canvasKeyPressEventArgs.preventVerticalPan) { + if ( event.shift ) { + this.viewport.zoomBy(1.1); + } else { + this.viewport.panBy(this.viewport.deltaPointsFromPixels(new $.Point(0, -40))); + } + this.viewport.applyConstraints(); + } + return false; case 115://s case 83://S - if ( event.shift ) { + if (!canvasKeyPressEventArgs.preventVerticalPan) { + if ( event.shift ) { this.viewport.zoomBy(0.9); - } else { + } else { this.viewport.panBy(this.viewport.deltaPointsFromPixels(new $.Point(0, 40))); + } + this.viewport.applyConstraints(); } - this.viewport.applyConstraints(); return false; case 97://a - this.viewport.panBy(this.viewport.deltaPointsFromPixels(new $.Point(-40, 0))); - this.viewport.applyConstraints(); + if (!canvasKeyPressEventArgs.preventHorizontalPan) { + this.viewport.panBy(this.viewport.deltaPointsFromPixels(new $.Point(-40, 0))); + this.viewport.applyConstraints(); + } return false; case 100://d - this.viewport.panBy(this.viewport.deltaPointsFromPixels(new $.Point(40, 0))); - this.viewport.applyConstraints(); + if (!canvasKeyPressEventArgs.preventHorizontalPan) { + this.viewport.panBy(this.viewport.deltaPointsFromPixels(new $.Point(40, 0))); + this.viewport.applyConstraints(); + } return false; default: //console.log( 'navigator keycode %s', event.keyCode ); From 34f691df2851bc79944b77117b2139624f6179ea Mon Sep 17 00:00:00 2001 From: Francesco Cretti Date: Wed, 7 Mar 2018 10:32:31 +0100 Subject: [PATCH 2/3] Event name and documentation --- src/viewer.js | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/viewer.js b/src/viewer.js index baecef38..086ace7c 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -2484,7 +2484,22 @@ function onCanvasKeyDown( event ) { preventHorizontalPan: event.preventHorizontalPan }; - this.raiseEvent( 'canvas-key-down', canvasKeyDownEventArgs); + /** + * Raised when a keyboard key is pressed and the focus is on the {@link OpenSeadragon.Viewer#canvas} element. + * + * @event canvas-key + * @memberof OpenSeadragon.Viewer + * @type {object} + * @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised this event. + * @property {Object} originalEvent - The original DOM event. + * @property {Boolean} preventDefaultAction - Set to true to prevent default keyboard behaviour. Default: false. + * @property {Boolean} preventVerticalPan - Set to true to prevent keyboard vertical panning. Default: false. + * @property {Boolean} preventHorizontalPan - Set to true to prevent keyboard horizontal panning. Default: false. + * @property {?Object} userData - Arbitrary subscriber-defined object. + */ + + + this.raiseEvent( 'canvas-key', canvasKeyDownEventArgs); if ( !canvasKeyDownEventArgs.preventDefaultAction && !event.ctrl && !event.alt && !event.meta ) { switch( event.keyCode ){ @@ -2535,8 +2550,21 @@ function onCanvasKeyPress( event ) { preventVerticalPan: event.preventVerticalPan, preventHorizontalPan: event.preventHorizontalPan }; - - this.raiseEvent( 'canvas-key-down', canvasKeyPressEventArgs); + + /** + * Raised when a keyboard key is pressed and the focus is on the {@link OpenSeadragon.Viewer#canvas} element. + * + * @event canvas-key + * @memberof OpenSeadragon.Viewer + * @type {object} + * @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised this event. + * @property {Object} originalEvent - The original DOM event. + * @property {Boolean} preventDefaultAction - Set to true to prevent default keyboard behaviour. Default: false. + * @property {Boolean} preventVerticalPan - Set to true to prevent keyboard vertical panning. Default: false. + * @property {Boolean} preventHorizontalPan - Set to true to prevent keyboard horizontal panning. Default: false. + * @property {?Object} userData - Arbitrary subscriber-defined object. + */ + this.raiseEvent( 'canvas-key', canvasKeyPressEventArgs); if ( !canvasKeyPressEventArgs.preventDefaultAction && !event.ctrl && !event.alt && !event.meta ) { switch( event.keyCode ){ From 44ca4a79b8cce6ed43ff72abe58ec976b7ea7270 Mon Sep 17 00:00:00 2001 From: Francesco Cretti Date: Wed, 7 Mar 2018 11:07:29 +0100 Subject: [PATCH 3/3] trailing spaces removed --- src/viewer.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/viewer.js b/src/viewer.js index 086ace7c..fbceaf4f 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -2483,7 +2483,6 @@ function onCanvasKeyDown( event ) { preventVerticalPan: event.preventVerticalPan, preventHorizontalPan: event.preventHorizontalPan }; - /** * Raised when a keyboard key is pressed and the focus is on the {@link OpenSeadragon.Viewer#canvas} element. * @@ -2498,8 +2497,7 @@ function onCanvasKeyDown( event ) { * @property {?Object} userData - Arbitrary subscriber-defined object. */ - - this.raiseEvent( 'canvas-key', canvasKeyDownEventArgs); + this.raiseEvent('canvas-key', canvasKeyDownEventArgs); if ( !canvasKeyDownEventArgs.preventDefaultAction && !event.ctrl && !event.alt && !event.meta ) { switch( event.keyCode ){ @@ -2550,7 +2548,6 @@ function onCanvasKeyPress( event ) { preventVerticalPan: event.preventVerticalPan, preventHorizontalPan: event.preventHorizontalPan }; - /** * Raised when a keyboard key is pressed and the focus is on the {@link OpenSeadragon.Viewer#canvas} element. * @@ -2564,7 +2561,8 @@ function onCanvasKeyPress( event ) { * @property {Boolean} preventHorizontalPan - Set to true to prevent keyboard horizontal panning. Default: false. * @property {?Object} userData - Arbitrary subscriber-defined object. */ - this.raiseEvent( 'canvas-key', canvasKeyPressEventArgs); + + this.raiseEvent('canvas-key', canvasKeyPressEventArgs); if ( !canvasKeyPressEventArgs.preventDefaultAction && !event.ctrl && !event.alt && !event.meta ) { switch( event.keyCode ){