diff --git a/src/mousetracker.js b/src/mousetracker.js index eb1fb94f..6f58ffa5 100644 --- a/src/mousetracker.js +++ b/src/mousetracker.js @@ -193,7 +193,7 @@ mousemove: function ( event ) { onMouseMove( _this, event ); }, mousemovecaptured: function ( event ) { onMouseMoveCaptured( _this, event ); }, - mouseoutdocument: function ( event ) { onMouseUp( _this, event ); }, + mouseoutdocument: function ( event ) { onMouseOutDocument( _this, event ); }, touchenter: function ( event ) { onTouchEnter( _this, event ); }, touchleave: function ( event ) { onTouchLeave( _this, event ); }, @@ -1053,7 +1053,7 @@ } // handle mouse out of document area - $.addEvent(document, "mouseout", delegate.mouseoutdocument); + $.addEvent(document.body, "mouseout", delegate.mouseoutdocument); delegate.tracking = true; } @@ -1081,7 +1081,7 @@ } // handle mouse out of document area - $.removeEvent(document, "mouseout", delegate.mouseoutdocument); + $.removeEvent(document.body, "mouseout", delegate.mouseoutdocument); delegate.tracking = false; } @@ -1537,6 +1537,17 @@ } } + function onMouseOutDocument( tracker, event ) { + event = $.getEvent( event ); + + var html = document.getElementsByTagName("html")[0]; + if ((event.relatedTarget!==html && event.relatedTarget!==null) || event.currentTarget !== document.body) { + return; // not a mouseout of the iframe + } + event.buttons = undefined; + event.button = 0; + handleMouseUp(tracker,event); + } /** * @private diff --git a/test/events.js b/test/events.js index 36a49b17..ac796cd8 100644 --- a/test/events.js +++ b/test/events.js @@ -165,6 +165,13 @@ var simulateLeave = function (x, y) { simEvent.clientX = offset.left + x; simEvent.clientY = offset.top + y; + simEvent.relatedTarget = document.body; + $canvas.simulate( OpenSeadragon.MouseTracker.haveMouseEnter ? 'mouseleave' : 'mouseout', simEvent ); + }; + var simulateLeaveFrame = function (x, y) { + simEvent.clientX = offset.left + x; + simEvent.clientY = offset.top + y; + simEvent.relatedTarget = document.getElementsByTagName("html")[0]; $canvas.simulate( OpenSeadragon.MouseTracker.haveMouseEnter ? 'mouseleave' : 'mouseout', simEvent ); }; @@ -446,6 +453,33 @@ quickClick: false }); + + // enter-press-move-exit-move-release (drag, release outside tracked element) + resetForAssessment(); + simulateEnter(0, 0); + simulateDown(0, 0); + simulateMove(1, 1, 5); + simulateMove(105, 105, 5); + simulateLeaveFrame(105, 105); + simulateMove(105, 105, 5); + // you don't actually receive the mouseup if you mouseup outside of the document + assessGestureExpectations({ + description: 'enter-press-move-exit-move-release-outside (drag, release outside iframe): ', + enterCount: 1, + exitCount: 1, + pressCount: 1, + releaseCount: 1, + moveCount: 15, + clickCount: 0, + dblClickCount: 0, + dragCount: 10, + dragEndCount: 1, + insideElementPressed: true, + insideElementReleased: false, + contacts: 0, + trackedPointers: 0, + quickClick: false + }); unhookViewerHandlers(); viewer.close();