2013-08-28 16:50:22 +04:00
|
|
|
/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog */
|
|
|
|
|
|
|
|
(function () {
|
|
|
|
var viewer;
|
|
|
|
|
|
|
|
module( 'Events', {
|
|
|
|
setup: function () {
|
2013-08-28 22:33:41 +04:00
|
|
|
var example = $( '<div id="eventsexample"></div>' ).appendTo( "#qunit-fixture" );
|
2013-08-28 16:50:22 +04:00
|
|
|
|
|
|
|
testLog.reset();
|
|
|
|
|
|
|
|
viewer = OpenSeadragon( {
|
2013-08-28 22:33:41 +04:00
|
|
|
id: 'eventsexample',
|
2013-08-28 16:50:22 +04:00
|
|
|
prefixUrl: '/build/openseadragon/images/',
|
|
|
|
springStiffness: 100 // Faster animation = faster tests
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
teardown: function () {
|
|
|
|
if ( viewer && viewer.close ) {
|
|
|
|
viewer.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
viewer = null;
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
// ----------
|
2014-04-15 05:17:18 +04:00
|
|
|
asyncTest( 'MouseTracker: mouse gestures', function () {
|
|
|
|
var $canvas = $( viewer.element ).find( '.openseadragon-canvas' ).not( '.navigator .openseadragon-canvas' ),
|
2014-04-16 00:04:08 +04:00
|
|
|
simEvent = {},
|
2014-04-15 05:17:18 +04:00
|
|
|
offset = $canvas.offset(),
|
|
|
|
tracker = viewer.innerTracker,
|
2014-04-16 00:04:08 +04:00
|
|
|
intervalId,
|
2014-04-15 05:17:18 +04:00
|
|
|
origEnterHandler,
|
|
|
|
origExitHandler,
|
|
|
|
origPressHandler,
|
|
|
|
origReleaseHandler,
|
2015-01-12 22:02:54 +03:00
|
|
|
origNonPrimaryPressHandler,
|
|
|
|
origNonPrimaryReleaseHandler,
|
2014-04-15 05:17:18 +04:00
|
|
|
origMoveHandler,
|
|
|
|
origClickHandler,
|
2014-04-22 20:23:56 +04:00
|
|
|
origDblClickHandler,
|
2014-04-15 05:17:18 +04:00
|
|
|
origDragHandler,
|
|
|
|
origDragEndHandler,
|
|
|
|
enterCount,
|
|
|
|
exitCount,
|
|
|
|
pressCount,
|
|
|
|
releaseCount,
|
2015-01-11 21:06:07 +03:00
|
|
|
rightPressCount,
|
|
|
|
rightReleaseCount,
|
2015-01-12 22:02:54 +03:00
|
|
|
middlePressCount,
|
|
|
|
middleReleaseCount,
|
2014-04-15 05:17:18 +04:00
|
|
|
moveCount,
|
|
|
|
clickCount,
|
2014-04-22 20:23:56 +04:00
|
|
|
dblClickCount,
|
2014-04-15 05:17:18 +04:00
|
|
|
dragCount,
|
|
|
|
dragEndCount,
|
|
|
|
insideElementPressed,
|
|
|
|
insideElementReleased,
|
2014-04-16 00:04:08 +04:00
|
|
|
quickClick,
|
|
|
|
speed,
|
|
|
|
direction;
|
2014-04-15 05:17:18 +04:00
|
|
|
|
|
|
|
var hookViewerHandlers = function () {
|
|
|
|
origEnterHandler = tracker.enterHandler;
|
|
|
|
tracker.enterHandler = function ( event ) {
|
|
|
|
enterCount++;
|
|
|
|
if (origEnterHandler) {
|
|
|
|
return origEnterHandler( event );
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
origExitHandler = tracker.exitHandler;
|
|
|
|
tracker.exitHandler = function ( event ) {
|
|
|
|
exitCount++;
|
|
|
|
if (origExitHandler) {
|
|
|
|
return origExitHandler( event );
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
origPressHandler = tracker.pressHandler;
|
|
|
|
tracker.pressHandler = function ( event ) {
|
|
|
|
pressCount++;
|
|
|
|
if (origPressHandler) {
|
|
|
|
return origPressHandler( event );
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
origReleaseHandler = tracker.releaseHandler;
|
|
|
|
tracker.releaseHandler = function ( event ) {
|
|
|
|
releaseCount++;
|
|
|
|
insideElementPressed = event.insideElementPressed;
|
|
|
|
insideElementReleased = event.insideElementReleased;
|
|
|
|
if (origReleaseHandler) {
|
|
|
|
return origReleaseHandler( event );
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2015-01-12 22:02:54 +03:00
|
|
|
origNonPrimaryPressHandler = tracker.nonPrimaryPressHandler;
|
|
|
|
tracker.nonPrimaryPressHandler = function ( event ) {
|
2015-01-11 21:06:07 +03:00
|
|
|
if (event.button === 0) {
|
|
|
|
pressCount++;
|
|
|
|
} else if (event.button === 1) {
|
2015-01-12 22:02:54 +03:00
|
|
|
middlePressCount++;
|
2015-01-11 21:06:07 +03:00
|
|
|
} else if (event.button === 2) {
|
|
|
|
rightPressCount++;
|
|
|
|
}
|
2015-01-12 22:02:54 +03:00
|
|
|
if (origNonPrimaryPressHandler) {
|
|
|
|
return origNonPrimaryPressHandler( event );
|
2015-01-11 21:06:07 +03:00
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2015-01-12 22:02:54 +03:00
|
|
|
origNonPrimaryReleaseHandler = tracker.nonPrimaryReleaseHandler;
|
|
|
|
tracker.nonPrimaryReleaseHandler = function ( event ) {
|
2015-01-11 21:06:07 +03:00
|
|
|
if (event.button === 0) {
|
|
|
|
releaseCount++;
|
|
|
|
} else if (event.button === 1) {
|
2015-01-12 22:02:54 +03:00
|
|
|
middleReleaseCount++;
|
2015-01-11 21:06:07 +03:00
|
|
|
} else if (event.button === 2) {
|
|
|
|
rightReleaseCount++;
|
|
|
|
}
|
2015-01-12 22:02:54 +03:00
|
|
|
if (origNonPrimaryReleaseHandler) {
|
|
|
|
return origNonPrimaryReleaseHandler( event );
|
2015-01-11 21:06:07 +03:00
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2014-04-15 05:17:18 +04:00
|
|
|
origMoveHandler = tracker.moveHandler;
|
|
|
|
tracker.moveHandler = function ( event ) {
|
|
|
|
moveCount++;
|
|
|
|
if (origMoveHandler) {
|
|
|
|
return origMoveHandler( event );
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
origClickHandler = tracker.clickHandler;
|
|
|
|
tracker.clickHandler = function ( event ) {
|
|
|
|
clickCount++;
|
|
|
|
quickClick = event.quick;
|
|
|
|
if (origClickHandler) {
|
|
|
|
return origClickHandler( event );
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2014-04-22 20:23:56 +04:00
|
|
|
origDblClickHandler = tracker.dblClickHandler;
|
|
|
|
tracker.dblClickHandler = function ( event ) {
|
|
|
|
dblClickCount++;
|
|
|
|
if (origDblClickHandler) {
|
|
|
|
return origDblClickHandler( event );
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2014-04-15 05:17:18 +04:00
|
|
|
origDragHandler = tracker.dragHandler;
|
|
|
|
tracker.dragHandler = function ( event ) {
|
|
|
|
dragCount++;
|
|
|
|
if (origDragHandler) {
|
|
|
|
return origDragHandler( event );
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
origDragEndHandler = tracker.dragEndHandler;
|
|
|
|
tracker.dragEndHandler = function ( event ) {
|
|
|
|
dragEndCount++;
|
2014-04-16 00:04:08 +04:00
|
|
|
speed = event.speed;
|
|
|
|
direction = event.direction;
|
2014-04-15 05:17:18 +04:00
|
|
|
if (origDragEndHandler) {
|
|
|
|
return origDragEndHandler( event );
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
var unhookViewerHandlers = function () {
|
|
|
|
tracker.enterHandler = origEnterHandler;
|
|
|
|
tracker.exitHandler = origExitHandler;
|
|
|
|
tracker.pressHandler = origPressHandler;
|
|
|
|
tracker.releaseHandler = origReleaseHandler;
|
|
|
|
tracker.moveHandler = origMoveHandler;
|
|
|
|
tracker.clickHandler = origClickHandler;
|
2014-04-22 20:23:56 +04:00
|
|
|
tracker.dblClickHandler = origDblClickHandler;
|
2014-04-15 05:17:18 +04:00
|
|
|
tracker.dragHandler = origDragHandler;
|
|
|
|
tracker.dragEndHandler = origDragEndHandler;
|
|
|
|
};
|
|
|
|
|
2014-04-16 06:19:47 +04:00
|
|
|
var simulateEnter = function (x, y) {
|
2014-04-16 00:04:08 +04:00
|
|
|
simEvent.clientX = offset.left + x;
|
|
|
|
simEvent.clientY = offset.top + y;
|
2014-04-16 01:16:10 +04:00
|
|
|
$canvas.simulate( OpenSeadragon.MouseTracker.haveMouseEnter ? 'mouseenter' : 'mouseover', simEvent );
|
2014-04-15 05:17:18 +04:00
|
|
|
};
|
|
|
|
|
2014-04-16 06:19:47 +04:00
|
|
|
var simulateLeave = function (x, y) {
|
2014-04-16 00:04:08 +04:00
|
|
|
simEvent.clientX = offset.left + x;
|
|
|
|
simEvent.clientY = offset.top + y;
|
2015-01-13 19:41:02 +03:00
|
|
|
simEvent.relatedTarget = document.body;
|
|
|
|
$canvas.simulate( OpenSeadragon.MouseTracker.haveMouseEnter ? 'mouseleave' : 'mouseout', simEvent );
|
|
|
|
};
|
|
|
|
|
2014-12-30 23:57:17 +03:00
|
|
|
//var simulateLeaveFrame = function (x, y) {
|
|
|
|
// simEvent.clientX = offset.left + x;
|
|
|
|
// simEvent.clientY = offset.top + y;
|
|
|
|
// simEvent.relatedTarget = document.getElementsByTagName("html")[0];
|
2015-01-13 19:41:02 +03:00
|
|
|
// $canvas.simulate( OpenSeadragon.MouseTracker.haveMouseEnter ? 'mouseleave' : 'mouseout', simEvent );
|
|
|
|
//};
|
2014-04-15 05:17:18 +04:00
|
|
|
|
2014-04-16 06:19:47 +04:00
|
|
|
var simulateDown = function (x, y) {
|
2015-01-11 21:06:07 +03:00
|
|
|
simEvent.button = 0;
|
2014-04-16 00:04:08 +04:00
|
|
|
simEvent.clientX = offset.left + x;
|
|
|
|
simEvent.clientY = offset.top + y;
|
|
|
|
$canvas.simulate( 'mousedown', simEvent );
|
2014-04-15 05:17:18 +04:00
|
|
|
};
|
|
|
|
|
2014-04-16 06:19:47 +04:00
|
|
|
var simulateUp = function (x, y) {
|
2015-01-11 21:06:07 +03:00
|
|
|
simEvent.button = 0;
|
|
|
|
simEvent.clientX = offset.left + x;
|
|
|
|
simEvent.clientY = offset.top + y;
|
|
|
|
$canvas.simulate( 'mouseup', simEvent );
|
|
|
|
};
|
|
|
|
|
2015-01-12 22:02:54 +03:00
|
|
|
var simulateNonPrimaryDown = function (x, y, button) {
|
2015-01-11 21:06:07 +03:00
|
|
|
simEvent.button = button;
|
|
|
|
simEvent.clientX = offset.left + x;
|
|
|
|
simEvent.clientY = offset.top + y;
|
|
|
|
$canvas.simulate( 'mousedown', simEvent );
|
|
|
|
};
|
|
|
|
|
2015-01-12 22:02:54 +03:00
|
|
|
var simulateNonPrimaryUp = function (x, y, button) {
|
2015-01-11 21:06:07 +03:00
|
|
|
simEvent.button = button;
|
2014-04-16 00:04:08 +04:00
|
|
|
simEvent.clientX = offset.left + x;
|
|
|
|
simEvent.clientY = offset.top + y;
|
|
|
|
$canvas.simulate( 'mouseup', simEvent );
|
2014-04-15 05:17:18 +04:00
|
|
|
};
|
|
|
|
|
2014-04-16 06:19:47 +04:00
|
|
|
var simulateMove = function (dX, dY, count) {
|
|
|
|
var i;
|
|
|
|
for ( i = 0; i < count; i++ ) {
|
|
|
|
simEvent.clientX += dX;
|
|
|
|
simEvent.clientY += dY;
|
|
|
|
$canvas.simulate( 'mousemove', simEvent );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-04-15 05:17:18 +04:00
|
|
|
var resetForAssessment = function () {
|
2014-04-16 00:04:08 +04:00
|
|
|
simEvent = {
|
2015-01-11 21:06:07 +03:00
|
|
|
button: 0,
|
2014-04-16 00:04:08 +04:00
|
|
|
clientX: offset.left,
|
|
|
|
clientY: offset.top
|
|
|
|
};
|
2014-04-15 05:17:18 +04:00
|
|
|
enterCount = 0;
|
|
|
|
exitCount = 0;
|
|
|
|
pressCount = 0;
|
|
|
|
releaseCount = 0;
|
2015-01-11 21:06:07 +03:00
|
|
|
rightPressCount = 0;
|
|
|
|
rightReleaseCount = 0;
|
2015-01-12 22:02:54 +03:00
|
|
|
middlePressCount = 0;
|
|
|
|
middleReleaseCount = 0;
|
2014-04-15 05:17:18 +04:00
|
|
|
moveCount = 0;
|
|
|
|
clickCount = 0;
|
2014-04-22 20:23:56 +04:00
|
|
|
dblClickCount = 0;
|
2014-04-15 05:17:18 +04:00
|
|
|
dragCount = 0;
|
|
|
|
dragEndCount = 0;
|
|
|
|
insideElementPressed = false;
|
|
|
|
insideElementReleased = false;
|
|
|
|
quickClick = false;
|
2014-04-16 00:04:08 +04:00
|
|
|
speed = 0;
|
|
|
|
direction = 2 * Math.PI;
|
2014-04-15 05:17:18 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
var assessGestureExpectations = function (expected) {
|
|
|
|
var pointersList = tracker.getActivePointersListByType('mouse');
|
|
|
|
if ('enterCount' in expected) {
|
|
|
|
equal( enterCount, expected.enterCount, expected.description + 'enterHandler event count matches expected (' + expected.enterCount + ')' );
|
|
|
|
}
|
|
|
|
if ('exitCount' in expected) {
|
|
|
|
equal( exitCount, expected.exitCount, expected.description + 'exitHandler event count matches expected (' + expected.exitCount + ')' );
|
|
|
|
}
|
|
|
|
if ('pressCount' in expected) {
|
|
|
|
equal( pressCount, expected.pressCount, expected.description + 'pressHandler event count matches expected (' + expected.pressCount + ')' );
|
2013-08-28 16:50:22 +04:00
|
|
|
}
|
2014-04-15 05:17:18 +04:00
|
|
|
if ('releaseCount' in expected) {
|
|
|
|
equal( releaseCount, expected.releaseCount, expected.description + 'releaseHandler event count matches expected (' + expected.releaseCount + ')' );
|
|
|
|
}
|
2015-01-11 21:06:07 +03:00
|
|
|
if ('rightPressCount' in expected) {
|
2015-01-12 22:02:54 +03:00
|
|
|
equal( rightPressCount, expected.rightPressCount, expected.description + 'nonPrimaryPressHandler event count (secondary/right button) matches expected (' + expected.rightPressCount + ')' );
|
2015-01-11 21:06:07 +03:00
|
|
|
}
|
|
|
|
if ('rightReleaseCount' in expected) {
|
2015-01-12 22:02:54 +03:00
|
|
|
equal( rightReleaseCount, expected.rightReleaseCount, expected.description + 'nonPrimaryReleaseHandler event count (secondary/right button) matches expected (' + expected.rightReleaseCount + ')' );
|
2015-01-11 21:06:07 +03:00
|
|
|
}
|
2015-01-12 22:02:54 +03:00
|
|
|
if ('middlePressCount' in expected) {
|
|
|
|
equal( middlePressCount, expected.middlePressCount, expected.description + 'nonPrimaryPressHandler event count (aux/middle button) matches expected (' + expected.middlePressCount + ')' );
|
2015-01-11 21:06:07 +03:00
|
|
|
}
|
2015-01-12 22:02:54 +03:00
|
|
|
if ('middleReleaseCount' in expected) {
|
|
|
|
equal( middleReleaseCount, expected.middleReleaseCount, expected.description + 'nonPrimaryReleaseHandler event count (aux/middle button) matches expected (' + expected.middleReleaseCount + ')' );
|
2015-01-11 21:06:07 +03:00
|
|
|
}
|
2014-04-15 05:17:18 +04:00
|
|
|
if ('moveCount' in expected) {
|
|
|
|
equal( moveCount, expected.moveCount, expected.description + 'moveHandler event count matches expected (' + expected.moveCount + ')' );
|
|
|
|
}
|
|
|
|
if ('clickCount' in expected) {
|
|
|
|
equal( clickCount, expected.clickCount, expected.description + 'clickHandler event count matches expected (' + expected.clickCount + ')' );
|
|
|
|
}
|
2014-04-22 20:23:56 +04:00
|
|
|
if ('dblClickCount' in expected) {
|
|
|
|
equal( dblClickCount, expected.dblClickCount, expected.description + 'dblClickHandler event count matches expected (' + expected.dblClickCount + ')' );
|
|
|
|
}
|
2014-04-15 05:17:18 +04:00
|
|
|
if ('dragCount' in expected) {
|
|
|
|
equal( dragCount, expected.dragCount, expected.description + 'dragHandler event count matches expected (' + expected.dragCount + ')' );
|
|
|
|
}
|
|
|
|
if ('dragEndCount' in expected) {
|
|
|
|
equal( dragEndCount, expected.dragEndCount, expected.description + 'dragEndHandler event count matches expected (' + expected.dragEndCount + ')' );
|
|
|
|
}
|
|
|
|
if ('insideElementPressed' in expected) {
|
|
|
|
equal( insideElementPressed, expected.insideElementPressed, expected.description + 'releaseHandler event.insideElementPressed matches expected (' + expected.insideElementPressed + ')' );
|
|
|
|
}
|
|
|
|
if ('insideElementReleased' in expected) {
|
|
|
|
equal( insideElementReleased, expected.insideElementReleased, expected.description + 'releaseHandler event.insideElementReleased matches expected (' + expected.insideElementReleased + ')' );
|
|
|
|
}
|
|
|
|
if ('contacts' in expected) {
|
|
|
|
equal( pointersList.contacts, expected.contacts, expected.description + 'Remaining pointer contact count matches expected (' + expected.contacts + ')' );
|
|
|
|
}
|
|
|
|
if ('trackedPointers' in expected) {
|
|
|
|
equal( pointersList.getLength(), expected.trackedPointers, expected.description + 'Remaining tracked pointer count matches expected (' + expected.trackedPointers + ')' );
|
|
|
|
}
|
|
|
|
if ('quickClick' in expected) {
|
|
|
|
equal( quickClick, expected.quickClick, expected.description + 'clickHandler event.quick matches expected (' + expected.quickClick + ')' );
|
|
|
|
}
|
2014-04-16 00:04:08 +04:00
|
|
|
if ('speed' in expected) {
|
2014-04-16 06:19:47 +04:00
|
|
|
Util.assessNumericValue(expected.speed, speed, 1.0, expected.description + 'Drag speed ');
|
2014-04-16 00:04:08 +04:00
|
|
|
}
|
|
|
|
if ('direction' in expected) {
|
2014-04-16 06:19:47 +04:00
|
|
|
Util.assessNumericValue(expected.direction, direction, 0.2, expected.description + 'Drag direction ');
|
2014-04-16 00:04:08 +04:00
|
|
|
}
|
2014-04-15 05:17:18 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
var onOpen = function ( event ) {
|
2014-04-16 00:04:08 +04:00
|
|
|
var timeStart,
|
|
|
|
timeElapsed;
|
|
|
|
|
2014-04-15 05:17:18 +04:00
|
|
|
viewer.removeHandler( 'open', onOpen );
|
|
|
|
|
|
|
|
hookViewerHandlers();
|
|
|
|
|
|
|
|
// enter-move-release (release in tracked element, press in unknown element)
|
|
|
|
// (Note we also test to see if the pointer is still being tracked by not simulating a leave event until after assessment)
|
|
|
|
resetForAssessment();
|
2014-04-16 06:19:47 +04:00
|
|
|
simulateEnter(0, 0);
|
|
|
|
simulateMove(1, 1, 10);
|
|
|
|
simulateMove(-1, -1, 10);
|
|
|
|
simulateUp(0, 0);
|
2014-04-15 05:17:18 +04:00
|
|
|
assessGestureExpectations({
|
|
|
|
description: 'enter-move-release (release in tracked element, press in unknown element): ',
|
|
|
|
enterCount: 1,
|
|
|
|
exitCount: 0,
|
|
|
|
pressCount: 0,
|
|
|
|
releaseCount: 1,
|
2015-01-11 21:06:07 +03:00
|
|
|
rightPressCount: 0,
|
|
|
|
rightReleaseCount: 0,
|
2015-01-12 22:02:54 +03:00
|
|
|
middlePressCount: 0,
|
|
|
|
middleReleaseCount: 0,
|
2014-04-15 05:17:18 +04:00
|
|
|
moveCount: 20,
|
|
|
|
clickCount: 0,
|
2014-04-22 20:23:56 +04:00
|
|
|
dblClickCount: 0,
|
2014-04-15 05:17:18 +04:00
|
|
|
dragCount: 0,
|
|
|
|
dragEndCount: 0,
|
|
|
|
insideElementPressed: false,
|
|
|
|
insideElementReleased: true,
|
|
|
|
contacts: 0,
|
|
|
|
trackedPointers: 1
|
|
|
|
//quickClick: false
|
|
|
|
});
|
2014-04-16 06:19:47 +04:00
|
|
|
simulateLeave(-1, -1); // flush tracked pointer
|
2014-04-15 05:17:18 +04:00
|
|
|
|
|
|
|
// enter-move-exit (fly-over)
|
|
|
|
resetForAssessment();
|
2014-04-16 06:19:47 +04:00
|
|
|
simulateEnter(0, 0);
|
|
|
|
simulateMove(1, 1, 10);
|
|
|
|
simulateMove(-1, -1, 10);
|
|
|
|
simulateLeave(-1, -1);
|
2014-04-15 05:17:18 +04:00
|
|
|
assessGestureExpectations({
|
|
|
|
description: 'enter-move-exit (fly-over): ',
|
|
|
|
enterCount: 1,
|
|
|
|
exitCount: 1,
|
|
|
|
pressCount: 0,
|
|
|
|
releaseCount: 0,
|
2015-01-11 21:06:07 +03:00
|
|
|
rightPressCount: 0,
|
|
|
|
rightReleaseCount: 0,
|
2015-01-12 22:02:54 +03:00
|
|
|
middlePressCount: 0,
|
|
|
|
middleReleaseCount: 0,
|
2014-04-15 05:17:18 +04:00
|
|
|
moveCount: 20,
|
|
|
|
clickCount: 0,
|
2014-04-22 20:23:56 +04:00
|
|
|
dblClickCount: 0,
|
2014-04-15 05:17:18 +04:00
|
|
|
dragCount: 0,
|
|
|
|
dragEndCount: 0,
|
|
|
|
//insideElementPressed: false,
|
|
|
|
//insideElementReleased: false,
|
|
|
|
contacts: 0,
|
|
|
|
trackedPointers: 0
|
|
|
|
//quickClick: false
|
|
|
|
});
|
|
|
|
|
|
|
|
// move-exit (fly-over, no enter event)
|
|
|
|
resetForAssessment();
|
2014-04-16 06:19:47 +04:00
|
|
|
simulateMove(1, 1, 10);
|
|
|
|
simulateMove(-1, -1, 10);
|
|
|
|
simulateLeave(-1, -1);
|
2014-04-15 05:17:18 +04:00
|
|
|
assessGestureExpectations({
|
|
|
|
description: 'move-exit (fly-over, no enter event): ',
|
|
|
|
enterCount: 0,
|
|
|
|
exitCount: 1,
|
|
|
|
pressCount: 0,
|
|
|
|
releaseCount: 0,
|
2015-01-11 21:06:07 +03:00
|
|
|
rightPressCount: 0,
|
|
|
|
rightReleaseCount: 0,
|
2015-01-12 22:02:54 +03:00
|
|
|
middlePressCount: 0,
|
|
|
|
middleReleaseCount: 0,
|
2014-04-15 05:17:18 +04:00
|
|
|
moveCount: 20,
|
|
|
|
clickCount: 0,
|
2014-04-22 20:23:56 +04:00
|
|
|
dblClickCount: 0,
|
2014-04-15 05:17:18 +04:00
|
|
|
dragCount: 0,
|
|
|
|
dragEndCount: 0,
|
|
|
|
//insideElementPressed: false,
|
|
|
|
//insideElementReleased: false,
|
|
|
|
contacts: 0,
|
|
|
|
trackedPointers: 0
|
|
|
|
//quickClick: false
|
|
|
|
});
|
|
|
|
|
2015-01-11 21:06:07 +03:00
|
|
|
// enter-press-release-press-release-exit (primary/left double click)
|
2014-04-22 20:23:56 +04:00
|
|
|
resetForAssessment();
|
|
|
|
simulateEnter(0, 0);
|
|
|
|
simulateDown(0, 0);
|
|
|
|
simulateUp(0, 0);
|
|
|
|
simulateDown(0, 0);
|
|
|
|
simulateUp(0, 0);
|
|
|
|
simulateLeave(-1, -1);
|
|
|
|
assessGestureExpectations({
|
2015-01-11 21:06:07 +03:00
|
|
|
description: 'enter-press-release-press-release-exit (primary/left double click): ',
|
2014-04-22 20:23:56 +04:00
|
|
|
enterCount: 1,
|
|
|
|
exitCount: 1,
|
|
|
|
pressCount: 2,
|
|
|
|
releaseCount: 2,
|
2015-01-11 21:06:07 +03:00
|
|
|
rightPressCount: 0,
|
|
|
|
rightReleaseCount: 0,
|
2015-01-12 22:02:54 +03:00
|
|
|
middlePressCount: 0,
|
|
|
|
middleReleaseCount: 0,
|
2014-04-22 20:23:56 +04:00
|
|
|
moveCount: 0,
|
|
|
|
clickCount: 2,
|
|
|
|
dblClickCount: 1,
|
|
|
|
dragCount: 0,
|
|
|
|
dragEndCount: 0,
|
|
|
|
insideElementPressed: true,
|
|
|
|
insideElementReleased: true,
|
|
|
|
contacts: 0,
|
|
|
|
trackedPointers: 0
|
|
|
|
//quickClick: true
|
|
|
|
});
|
|
|
|
|
2015-01-11 21:06:07 +03:00
|
|
|
// enter-press-release-exit (primary/left click)
|
2014-04-15 05:17:18 +04:00
|
|
|
resetForAssessment();
|
2014-04-16 06:19:47 +04:00
|
|
|
simulateEnter(0, 0);
|
|
|
|
simulateDown(0, 0);
|
|
|
|
simulateUp(0, 0);
|
|
|
|
simulateLeave(-1, -1);
|
2014-04-15 05:17:18 +04:00
|
|
|
assessGestureExpectations({
|
2015-01-11 21:06:07 +03:00
|
|
|
description: 'enter-press-release-exit (primary/left click): ',
|
2014-04-15 05:17:18 +04:00
|
|
|
enterCount: 1,
|
|
|
|
exitCount: 1,
|
|
|
|
pressCount: 1,
|
|
|
|
releaseCount: 1,
|
2015-01-11 21:06:07 +03:00
|
|
|
rightPressCount: 0,
|
|
|
|
rightReleaseCount: 0,
|
2015-01-12 22:02:54 +03:00
|
|
|
middlePressCount: 0,
|
|
|
|
middleReleaseCount: 0,
|
2014-04-15 05:17:18 +04:00
|
|
|
moveCount: 0,
|
|
|
|
clickCount: 1,
|
2014-04-22 20:23:56 +04:00
|
|
|
dblClickCount: 0,
|
2014-04-15 05:17:18 +04:00
|
|
|
dragCount: 0,
|
|
|
|
dragEndCount: 0,
|
|
|
|
insideElementPressed: true,
|
|
|
|
insideElementReleased: true,
|
|
|
|
contacts: 0,
|
|
|
|
trackedPointers: 0,
|
|
|
|
quickClick: true
|
|
|
|
});
|
|
|
|
|
2015-01-12 22:02:54 +03:00
|
|
|
// enter-nonprimarypress-nonprimaryrelease-exit (secondary/right click)
|
2015-01-11 21:06:07 +03:00
|
|
|
resetForAssessment();
|
|
|
|
simulateEnter(0, 0);
|
2015-01-12 22:02:54 +03:00
|
|
|
simulateNonPrimaryDown(0, 0, 2);
|
|
|
|
simulateNonPrimaryUp(0, 0, 2);
|
2015-01-11 21:06:07 +03:00
|
|
|
simulateLeave(-1, -1);
|
|
|
|
assessGestureExpectations({
|
2015-01-12 22:02:54 +03:00
|
|
|
description: 'enter-nonprimarypress-nonprimaryrelease-exit (secondary/right click): ',
|
2015-01-11 21:06:07 +03:00
|
|
|
enterCount: 1,
|
|
|
|
exitCount: 1,
|
|
|
|
pressCount: 0,
|
|
|
|
releaseCount: 0,
|
|
|
|
rightPressCount: 1,
|
|
|
|
rightReleaseCount: 1,
|
2015-01-12 22:02:54 +03:00
|
|
|
middlePressCount: 0,
|
|
|
|
middleReleaseCount: 0,
|
2015-01-11 21:06:07 +03:00
|
|
|
moveCount: 0,
|
|
|
|
clickCount: 0,
|
|
|
|
dblClickCount: 0,
|
|
|
|
dragCount: 0,
|
|
|
|
dragEndCount: 0,
|
|
|
|
//insideElementPressed: true,
|
|
|
|
//insideElementReleased: true,
|
|
|
|
contacts: 0,
|
|
|
|
trackedPointers: 0,
|
|
|
|
//quickClick: true
|
|
|
|
});
|
|
|
|
|
2015-01-12 22:02:54 +03:00
|
|
|
// enter-nonprimarypress-nonprimaryrelease-exit (aux/middle click)
|
2015-01-11 21:06:07 +03:00
|
|
|
resetForAssessment();
|
|
|
|
simulateEnter(0, 0);
|
2015-01-12 22:02:54 +03:00
|
|
|
simulateNonPrimaryDown(0, 0, 1);
|
|
|
|
simulateNonPrimaryUp(0, 0, 1);
|
2015-01-11 21:06:07 +03:00
|
|
|
simulateLeave(-1, -1);
|
|
|
|
assessGestureExpectations({
|
2015-01-12 22:02:54 +03:00
|
|
|
description: 'enter-nonprimarypress-nonprimaryrelease-exit (aux/middle click): ',
|
2015-01-11 21:06:07 +03:00
|
|
|
enterCount: 1,
|
|
|
|
exitCount: 1,
|
|
|
|
pressCount: 0,
|
|
|
|
releaseCount: 0,
|
|
|
|
rightPressCount: 0,
|
|
|
|
rightReleaseCount: 0,
|
2015-01-12 22:02:54 +03:00
|
|
|
middlePressCount: 1,
|
|
|
|
middleReleaseCount: 1,
|
2015-01-11 21:06:07 +03:00
|
|
|
moveCount: 0,
|
|
|
|
clickCount: 0,
|
|
|
|
dblClickCount: 0,
|
|
|
|
dragCount: 0,
|
|
|
|
dragEndCount: 0,
|
|
|
|
//insideElementPressed: true,
|
|
|
|
//insideElementReleased: true,
|
|
|
|
contacts: 0,
|
|
|
|
trackedPointers: 0,
|
|
|
|
//quickClick: true
|
|
|
|
});
|
|
|
|
|
2015-01-12 22:02:54 +03:00
|
|
|
// enter-nonprimarypress-move-nonprimaryrelease-move-exit (secondary/right button drag, release in tracked element)
|
2015-01-11 21:06:07 +03:00
|
|
|
resetForAssessment();
|
|
|
|
simulateEnter(0, 0);
|
2015-01-12 22:02:54 +03:00
|
|
|
simulateNonPrimaryDown(0, 0, 2);
|
2015-01-11 21:06:07 +03:00
|
|
|
simulateMove(1, 1, 100);
|
2015-01-12 22:02:54 +03:00
|
|
|
simulateNonPrimaryUp(10, 10, 2);
|
2015-01-11 21:06:07 +03:00
|
|
|
simulateMove(-1, -1, 100);
|
|
|
|
simulateLeave(-1, -1);
|
|
|
|
assessGestureExpectations({
|
2015-01-12 22:02:54 +03:00
|
|
|
description: 'enter-nonprimarypress-move-nonprimaryrelease-move-exit (secondary/right button drag, release in tracked element): ',
|
2015-01-11 21:06:07 +03:00
|
|
|
enterCount: 1,
|
|
|
|
exitCount: 1,
|
|
|
|
pressCount: 0,
|
|
|
|
releaseCount: 0,
|
|
|
|
rightPressCount: 1,
|
|
|
|
rightReleaseCount: 1,
|
2015-01-12 22:02:54 +03:00
|
|
|
middlePressCount: 0,
|
|
|
|
middleReleaseCount: 0,
|
2015-01-11 21:06:07 +03:00
|
|
|
moveCount: 200,
|
|
|
|
clickCount: 0,
|
|
|
|
dblClickCount: 0,
|
|
|
|
dragCount: 0,
|
|
|
|
dragEndCount: 0,
|
|
|
|
//insideElementPressed: true,
|
|
|
|
//insideElementReleased: true,
|
|
|
|
contacts: 0,
|
|
|
|
trackedPointers: 0,
|
|
|
|
//quickClick: false
|
|
|
|
});
|
|
|
|
|
2014-04-15 05:17:18 +04:00
|
|
|
// enter-press-move-release-move-exit (drag, release in tracked element)
|
|
|
|
resetForAssessment();
|
2014-04-16 06:19:47 +04:00
|
|
|
simulateEnter(0, 0);
|
|
|
|
simulateDown(0, 0);
|
|
|
|
simulateMove(1, 1, 100);
|
|
|
|
simulateUp(10, 10);
|
|
|
|
simulateMove(-1, -1, 100);
|
|
|
|
simulateLeave(-1, -1);
|
2014-04-15 05:17:18 +04:00
|
|
|
assessGestureExpectations({
|
|
|
|
description: 'enter-press-move-release-move-exit (drag, release in tracked element): ',
|
|
|
|
enterCount: 1,
|
|
|
|
exitCount: 1,
|
|
|
|
pressCount: 1,
|
|
|
|
releaseCount: 1,
|
2015-01-11 21:06:07 +03:00
|
|
|
rightPressCount: 0,
|
|
|
|
rightReleaseCount: 0,
|
2015-01-12 22:02:54 +03:00
|
|
|
middlePressCount: 0,
|
|
|
|
middleReleaseCount: 0,
|
2014-04-16 00:04:08 +04:00
|
|
|
moveCount: 200,
|
2014-04-15 05:17:18 +04:00
|
|
|
clickCount: 1,
|
2014-04-22 20:23:56 +04:00
|
|
|
dblClickCount: 0,
|
2014-04-16 00:04:08 +04:00
|
|
|
dragCount: 100,
|
2014-04-15 05:17:18 +04:00
|
|
|
dragEndCount: 1,
|
|
|
|
insideElementPressed: true,
|
|
|
|
insideElementReleased: true,
|
|
|
|
contacts: 0,
|
|
|
|
trackedPointers: 0,
|
|
|
|
quickClick: false
|
|
|
|
});
|
|
|
|
|
|
|
|
// enter-press-move-exit-move-release (drag, release outside tracked element)
|
|
|
|
resetForAssessment();
|
2014-04-16 06:19:47 +04:00
|
|
|
simulateEnter(0, 0);
|
|
|
|
simulateDown(0, 0);
|
|
|
|
simulateMove(1, 1, 5);
|
|
|
|
simulateMove(-1, -1, 5);
|
|
|
|
simulateLeave(-1, -1);
|
|
|
|
simulateMove(-1, -1, 5);
|
|
|
|
simulateUp(-5, -5);
|
2014-04-15 05:17:18 +04:00
|
|
|
assessGestureExpectations({
|
|
|
|
description: 'enter-press-move-exit-move-release (drag, release outside tracked element): ',
|
|
|
|
enterCount: 1,
|
|
|
|
exitCount: 1,
|
|
|
|
pressCount: 1,
|
|
|
|
releaseCount: 1,
|
2015-01-11 21:06:07 +03:00
|
|
|
rightPressCount: 0,
|
|
|
|
rightReleaseCount: 0,
|
2015-01-12 22:02:54 +03:00
|
|
|
middlePressCount: 0,
|
|
|
|
middleReleaseCount: 0,
|
2014-04-15 05:17:18 +04:00
|
|
|
moveCount: 15,
|
|
|
|
clickCount: 0,
|
2014-04-22 20:23:56 +04:00
|
|
|
dblClickCount: 0,
|
2014-04-15 05:17:18 +04:00
|
|
|
dragCount: 15,
|
|
|
|
dragEndCount: 1,
|
|
|
|
insideElementPressed: true,
|
|
|
|
insideElementReleased: false,
|
|
|
|
contacts: 0,
|
|
|
|
trackedPointers: 0,
|
|
|
|
quickClick: false
|
|
|
|
});
|
|
|
|
|
2014-12-30 23:57:17 +03:00
|
|
|
//// enter-press-move-exit-move-release-outside (drag, release outside iframe)
|
|
|
|
//resetForAssessment();
|
|
|
|
//simulateEnter(0, 0);
|
|
|
|
//simulateDown(0, 0);
|
|
|
|
//simulateMove(1, 1, 5);
|
|
|
|
//simulateMove(-1, -1, 5);
|
|
|
|
//simulateLeaveFrame(-1, -1);
|
|
|
|
//// 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,
|
2015-01-11 21:06:07 +03:00
|
|
|
// rightPressCount: 0,
|
|
|
|
// rightReleaseCount: 0,
|
2015-01-12 22:02:54 +03:00
|
|
|
// middlePressCount: 0,
|
|
|
|
// middleReleaseCount: 0,
|
2014-12-30 23:57:17 +03:00
|
|
|
// moveCount: 10,
|
|
|
|
// clickCount: 0,
|
|
|
|
// dblClickCount: 0,
|
|
|
|
// dragCount: 10,
|
|
|
|
// dragEndCount: 1,
|
|
|
|
// insideElementPressed: true,
|
|
|
|
// insideElementReleased: false,
|
|
|
|
// contacts: 0,
|
|
|
|
// trackedPointers: 0,
|
|
|
|
// quickClick: false
|
|
|
|
//});
|
2015-01-11 21:06:07 +03:00
|
|
|
|
2014-04-15 05:17:18 +04:00
|
|
|
unhookViewerHandlers();
|
|
|
|
|
2013-08-28 16:50:22 +04:00
|
|
|
viewer.close();
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
|
2014-04-15 05:17:18 +04:00
|
|
|
viewer.addHandler( 'open', onOpen );
|
2013-08-28 16:50:22 +04:00
|
|
|
viewer.open( '/test/data/testpattern.dzi' );
|
|
|
|
} );
|
|
|
|
|
|
|
|
// ----------
|
2014-04-16 17:40:19 +04:00
|
|
|
asyncTest( 'Viewer: preventDefaultAction', function () {
|
2014-04-15 05:17:18 +04:00
|
|
|
var $canvas = $( viewer.element ).find( '.openseadragon-canvas' ).not( '.navigator .openseadragon-canvas' ),
|
|
|
|
tracker = viewer.innerTracker,
|
|
|
|
origClickHandler,
|
|
|
|
origDragHandler,
|
|
|
|
dragCount = 10,
|
|
|
|
originalZoom = 0,
|
|
|
|
originalBounds = null;
|
|
|
|
|
|
|
|
var onOpen = function ( event ) {
|
|
|
|
viewer.removeHandler( 'open', onOpen );
|
|
|
|
|
|
|
|
// Hook viewer events to set preventDefaultAction
|
|
|
|
origClickHandler = tracker.clickHandler;
|
|
|
|
tracker.clickHandler = function ( event ) {
|
|
|
|
event.preventDefaultAction = true;
|
|
|
|
return origClickHandler( event );
|
|
|
|
};
|
|
|
|
origDragHandler = tracker.dragHandler;
|
|
|
|
tracker.dragHandler = function ( event ) {
|
|
|
|
event.preventDefaultAction = true;
|
|
|
|
return origDragHandler( event );
|
|
|
|
};
|
|
|
|
|
|
|
|
originalZoom = viewer.viewport.getZoom();
|
|
|
|
originalBounds = viewer.viewport.getBounds();
|
|
|
|
|
|
|
|
var event = {
|
|
|
|
clientX:1,
|
|
|
|
clientY:1
|
|
|
|
};
|
|
|
|
|
|
|
|
$canvas.simulate( 'focus', event );
|
|
|
|
// Drag to pan
|
|
|
|
Util.simulateViewerClickWithDrag( {
|
|
|
|
viewer: viewer,
|
|
|
|
widthFactor: 0.25,
|
|
|
|
heightFactor: 0.25,
|
|
|
|
dragCount: dragCount,
|
|
|
|
dragDx: 1,
|
|
|
|
dragDy: 1
|
|
|
|
} );
|
|
|
|
// Click to zoom
|
|
|
|
Util.simulateViewerClickWithDrag( {
|
|
|
|
viewer: viewer,
|
|
|
|
widthFactor: 0.25,
|
|
|
|
heightFactor: 0.25,
|
|
|
|
dragCount: 0,
|
|
|
|
dragDx: 0,
|
|
|
|
dragDy: 0
|
|
|
|
} );
|
|
|
|
$canvas.simulate( 'blur', event );
|
|
|
|
|
|
|
|
var zoom = viewer.viewport.getZoom(),
|
|
|
|
bounds = viewer.viewport.getBounds();
|
|
|
|
|
|
|
|
equal( zoom, originalZoom, "Zoom prevented" );
|
|
|
|
ok( bounds.x == originalBounds.x && bounds.y == originalBounds.y, 'Pan prevented' );
|
2013-08-28 16:50:22 +04:00
|
|
|
|
|
|
|
viewer.close();
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
|
2014-04-15 05:17:18 +04:00
|
|
|
viewer.addHandler( 'open', onOpen );
|
2013-08-28 16:50:22 +04:00
|
|
|
viewer.open( '/test/data/testpattern.dzi' );
|
|
|
|
} );
|
|
|
|
|
2013-08-28 22:33:41 +04:00
|
|
|
// ----------
|
2014-04-15 05:17:18 +04:00
|
|
|
asyncTest( 'EventSource/MouseTracker/Viewer: event.originalEvent event.userData canvas-drag canvas-drag-end canvas-release canvas-click', function () {
|
2013-09-20 20:17:48 +04:00
|
|
|
var $canvas = $( viewer.element ).find( '.openseadragon-canvas' ).not( '.navigator .openseadragon-canvas' ),
|
|
|
|
mouseTracker = null,
|
|
|
|
userData = { item1: 'Test user data', item2: Math.random() },
|
|
|
|
originalUserData = { item1: userData.item1, item2: userData.item2 },
|
|
|
|
dragCount = 10,
|
2013-09-25 00:36:13 +04:00
|
|
|
dragsHandledEventSource = 0,
|
2014-04-15 05:17:18 +04:00
|
|
|
dragEndsHandledEventSource = 0,
|
2013-09-25 00:36:13 +04:00
|
|
|
releasesHandledEventSource = 0,
|
|
|
|
clicksHandledEventSource = 0,
|
2013-09-20 20:17:48 +04:00
|
|
|
eventsHandledMouseTracker = 0,
|
2013-10-11 04:00:15 +04:00
|
|
|
eventSourcePassedMouseTracker = 0,
|
2013-09-20 20:17:48 +04:00
|
|
|
originalEventsPassedMouseTracker = 0,
|
2013-10-15 22:27:21 +04:00
|
|
|
eventsHandledViewer = 0,
|
|
|
|
originalEventsPassedViewer = 0,
|
2014-04-15 05:17:18 +04:00
|
|
|
dragEndsExpected = 1,
|
2013-09-20 20:17:48 +04:00
|
|
|
releasesExpected = 1,
|
|
|
|
clicksExpected = 1;
|
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
var onOpen = function ( event ) {
|
2013-09-20 20:17:48 +04:00
|
|
|
viewer.removeHandler( 'open', onOpen );
|
|
|
|
|
2013-09-25 00:36:13 +04:00
|
|
|
viewer.addHandler( 'canvas-drag', onEventSourceDrag );
|
2014-04-15 05:17:18 +04:00
|
|
|
viewer.addHandler( 'canvas-drag-end', onEventSourceDragEnd );
|
2013-09-25 00:36:13 +04:00
|
|
|
viewer.addHandler( 'canvas-release', onEventSourceRelease );
|
|
|
|
viewer.addHandler( 'canvas-click', onEventSourceClick );
|
2013-09-20 20:17:48 +04:00
|
|
|
|
|
|
|
mouseTracker = new OpenSeadragon.MouseTracker( {
|
|
|
|
element: $canvas[0],
|
|
|
|
userData: userData,
|
|
|
|
clickTimeThreshold: OpenSeadragon.DEFAULT_SETTINGS.clickTimeThreshold,
|
|
|
|
clickDistThreshold: OpenSeadragon.DEFAULT_SETTINGS.clickDistThreshold,
|
2014-04-22 20:23:56 +04:00
|
|
|
dblClickTimeThreshold: OpenSeadragon.DEFAULT_SETTINGS.dblClickTimeThreshold,
|
|
|
|
dblClickDistThreshold: OpenSeadragon.DEFAULT_SETTINGS.dblClickDistThreshold,
|
2013-09-20 20:17:48 +04:00
|
|
|
focusHandler: onMouseTrackerFocus,
|
|
|
|
blurHandler: onMouseTrackerBlur,
|
|
|
|
enterHandler: onMouseTrackerEnter,
|
|
|
|
pressHandler: onMouseTrackerPress,
|
|
|
|
moveHandler: onMouseTrackerMove,
|
|
|
|
dragHandler: onMouseTrackerDrag,
|
2014-04-15 05:17:18 +04:00
|
|
|
dragEndHandler: onMouseTrackerDragEnd,
|
2013-09-20 20:17:48 +04:00
|
|
|
releaseHandler: onMouseTrackerRelease,
|
|
|
|
clickHandler: onMouseTrackerClick,
|
|
|
|
exitHandler: onMouseTrackerExit
|
|
|
|
} ).setTracking( true );
|
|
|
|
|
|
|
|
var event = {
|
|
|
|
clientX:1,
|
|
|
|
clientY:1
|
|
|
|
};
|
|
|
|
|
|
|
|
$canvas.simulate( 'focus', event );
|
2013-08-30 21:09:22 +04:00
|
|
|
Util.simulateViewerClickWithDrag( {
|
|
|
|
viewer: viewer,
|
|
|
|
widthFactor: 0.25,
|
|
|
|
heightFactor: 0.25,
|
|
|
|
dragCount: dragCount,
|
|
|
|
dragDx: 1,
|
|
|
|
dragDy: 1
|
2013-08-30 00:01:07 +04:00
|
|
|
} );
|
2013-09-20 20:17:48 +04:00
|
|
|
$canvas.simulate( 'blur', event );
|
|
|
|
};
|
|
|
|
|
2013-10-15 22:27:21 +04:00
|
|
|
var checkOriginalEventReceivedViewer = function ( event ) {
|
|
|
|
eventsHandledViewer++;
|
2014-11-08 03:07:04 +03:00
|
|
|
//TODO Provide a better check for the original event...simulate doesn't currently extend the object
|
2013-10-15 22:27:21 +04:00
|
|
|
// with arbitrary user data.
|
|
|
|
if ( event && event.originalEvent ) {
|
|
|
|
originalEventsPassedViewer++;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
var onEventSourceDrag = function ( event ) {
|
2013-10-15 22:27:21 +04:00
|
|
|
checkOriginalEventReceivedViewer( event );
|
2013-09-25 00:36:13 +04:00
|
|
|
dragsHandledEventSource++;
|
2013-09-20 20:17:48 +04:00
|
|
|
};
|
|
|
|
|
2014-04-15 05:17:18 +04:00
|
|
|
var onEventSourceDragEnd = function ( event ) {
|
|
|
|
checkOriginalEventReceivedViewer( event );
|
|
|
|
dragEndsHandledEventSource++;
|
|
|
|
};
|
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
var onEventSourceRelease = function ( event ) {
|
2013-10-15 22:27:21 +04:00
|
|
|
checkOriginalEventReceivedViewer( event );
|
2013-09-25 00:36:13 +04:00
|
|
|
releasesHandledEventSource++;
|
2013-09-20 20:17:48 +04:00
|
|
|
};
|
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
var onEventSourceClick = function ( event ) {
|
2013-10-15 22:27:21 +04:00
|
|
|
checkOriginalEventReceivedViewer( event );
|
2013-09-25 00:36:13 +04:00
|
|
|
clicksHandledEventSource++;
|
2013-09-20 20:17:48 +04:00
|
|
|
};
|
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
var checkOriginalEventReceived = function ( event ) {
|
2013-09-20 20:17:48 +04:00
|
|
|
eventsHandledMouseTracker++;
|
2013-10-11 04:00:15 +04:00
|
|
|
if ( event && event.eventSource === mouseTracker ) {
|
|
|
|
eventSourcePassedMouseTracker++;
|
|
|
|
}
|
2014-11-08 03:07:04 +03:00
|
|
|
//TODO Provide a better check for the original event...simulate doesn't currently extend the object
|
2013-09-25 00:36:13 +04:00
|
|
|
// with arbitrary user data.
|
2013-10-11 04:00:15 +04:00
|
|
|
if ( event && event.originalEvent ) {
|
2013-09-20 20:17:48 +04:00
|
|
|
originalEventsPassedMouseTracker++;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
var onMouseTrackerFocus = function ( event ) {
|
|
|
|
checkOriginalEventReceived( event );
|
2013-08-28 22:33:41 +04:00
|
|
|
};
|
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
var onMouseTrackerBlur = function ( event ) {
|
|
|
|
checkOriginalEventReceived( event );
|
2013-08-28 22:33:41 +04:00
|
|
|
};
|
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
var onMouseTrackerEnter = function ( event ) {
|
|
|
|
checkOriginalEventReceived( event );
|
2013-08-28 22:33:41 +04:00
|
|
|
};
|
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
var onMouseTrackerPress = function ( event ) {
|
|
|
|
checkOriginalEventReceived( event );
|
2013-09-20 20:17:48 +04:00
|
|
|
};
|
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
var onMouseTrackerMove = function ( event ) {
|
|
|
|
checkOriginalEventReceived( event );
|
2013-09-20 20:17:48 +04:00
|
|
|
};
|
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
var onMouseTrackerDrag = function ( event ) {
|
|
|
|
checkOriginalEventReceived( event );
|
2013-09-20 20:17:48 +04:00
|
|
|
};
|
|
|
|
|
2014-04-15 05:17:18 +04:00
|
|
|
var onMouseTrackerDragEnd = function ( event ) {
|
|
|
|
checkOriginalEventReceived( event );
|
|
|
|
};
|
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
var onMouseTrackerRelease = function ( event ) {
|
|
|
|
checkOriginalEventReceived( event );
|
2013-09-20 20:17:48 +04:00
|
|
|
};
|
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
var onMouseTrackerClick = function ( event ) {
|
|
|
|
checkOriginalEventReceived( event );
|
2013-09-20 20:17:48 +04:00
|
|
|
};
|
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
var onMouseTrackerExit = function ( event ) {
|
|
|
|
checkOriginalEventReceived( event );
|
2013-09-20 20:17:48 +04:00
|
|
|
|
|
|
|
mouseTracker.destroy();
|
2013-09-25 00:36:13 +04:00
|
|
|
viewer.removeHandler( 'canvas-drag', onEventSourceDrag );
|
|
|
|
viewer.removeHandler( 'canvas-release', onEventSourceRelease );
|
|
|
|
viewer.removeHandler( 'canvas-click', onEventSourceClick );
|
2013-09-20 20:17:48 +04:00
|
|
|
|
2013-09-25 00:36:13 +04:00
|
|
|
equal( dragsHandledEventSource, dragCount, "'canvas-drag' event count matches 'mousemove' event count (" + dragCount + ")" );
|
2014-04-15 05:17:18 +04:00
|
|
|
equal( dragEndsHandledEventSource, dragEndsExpected, "'canvas-drag-end' event count matches expected (" + dragEndsExpected + ")" );
|
2013-09-25 00:36:13 +04:00
|
|
|
equal( releasesHandledEventSource, releasesExpected, "'canvas-release' event count matches expected (" + releasesExpected + ")" );
|
|
|
|
equal( clicksHandledEventSource, releasesExpected, "'canvas-click' event count matches expected (" + releasesExpected + ")" );
|
2013-10-15 22:27:21 +04:00
|
|
|
equal( originalEventsPassedViewer, eventsHandledViewer, "Original event received count matches expected (" + eventsHandledViewer + ")" );
|
2013-09-20 20:17:48 +04:00
|
|
|
|
2013-10-11 04:00:15 +04:00
|
|
|
equal( eventSourcePassedMouseTracker, eventsHandledMouseTracker, "Event source received count matches expected (" + eventsHandledMouseTracker + ")" );
|
2013-09-20 20:17:48 +04:00
|
|
|
equal( originalEventsPassedMouseTracker, eventsHandledMouseTracker, "Original event received count matches expected (" + eventsHandledMouseTracker + ")" );
|
2013-10-11 04:00:15 +04:00
|
|
|
deepEqual( event.userData, originalUserData, 'MouseTracker userData was untouched' );
|
2013-09-20 20:17:48 +04:00
|
|
|
|
2013-08-28 22:33:41 +04:00
|
|
|
viewer.close();
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
|
2013-09-20 20:17:48 +04:00
|
|
|
viewer.addHandler( 'open', onOpen );
|
2013-08-28 22:33:41 +04:00
|
|
|
viewer.open( '/test/data/testpattern.dzi' );
|
|
|
|
} );
|
|
|
|
|
2013-11-08 20:24:44 +04:00
|
|
|
// ----------
|
2014-04-16 17:40:19 +04:00
|
|
|
asyncTest( 'EventSource: addHandler without userData', function () {
|
2014-04-15 05:17:18 +04:00
|
|
|
var openHandler = function ( event ) {
|
|
|
|
viewer.removeHandler( 'open', openHandler );
|
|
|
|
ok( event, 'Event handler received event data' );
|
|
|
|
if ( event ) {
|
|
|
|
strictEqual( event.eventSource, viewer, 'eventSource sent, eventSource is viewer' );
|
|
|
|
strictEqual( event.userData, null, 'User data defaulted to null' );
|
|
|
|
}
|
|
|
|
viewer.close();
|
|
|
|
start();
|
|
|
|
};
|
2013-11-08 20:24:44 +04:00
|
|
|
|
2014-04-15 05:17:18 +04:00
|
|
|
viewer.addHandler( 'open', openHandler );
|
|
|
|
viewer.open( '/test/data/testpattern.dzi' );
|
|
|
|
} );
|
2013-11-08 20:24:44 +04:00
|
|
|
|
2014-04-15 05:17:18 +04:00
|
|
|
// ----------
|
2014-04-16 17:40:19 +04:00
|
|
|
asyncTest( 'EventSource: addHandler with userData', function () {
|
2014-04-15 05:17:18 +04:00
|
|
|
var userData = { item1: 'Test user data', item2: Math.random() },
|
|
|
|
originalUserData = { item1: userData.item1, item2: userData.item2 };
|
2013-11-08 20:24:44 +04:00
|
|
|
|
2014-04-15 05:17:18 +04:00
|
|
|
var openHandler = function ( event ) {
|
|
|
|
viewer.removeHandler( 'open', openHandler );
|
|
|
|
ok( event, 'Event handler received event data' );
|
|
|
|
ok( event && event.userData, 'Event handler received user data' );
|
|
|
|
if ( event && event.userData ) {
|
|
|
|
deepEqual( event.userData, originalUserData, 'User data was untouched' );
|
|
|
|
}
|
2013-11-08 20:24:44 +04:00
|
|
|
viewer.close();
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
|
2014-04-15 05:17:18 +04:00
|
|
|
viewer.addHandler( 'open', openHandler, userData );
|
2013-11-08 20:24:44 +04:00
|
|
|
viewer.open( '/test/data/testpattern.dzi' );
|
|
|
|
} );
|
|
|
|
|
2014-03-04 03:19:40 +04:00
|
|
|
// ----------
|
2014-04-15 05:17:18 +04:00
|
|
|
asyncTest( 'Viewer: tile-drawing event', function () {
|
2014-03-04 03:19:40 +04:00
|
|
|
var tileDrawing = function ( event ) {
|
|
|
|
viewer.removeHandler( 'tile-drawing', tileDrawing );
|
2014-03-06 19:58:56 +04:00
|
|
|
ok( event, 'Event handler should be invoked' );
|
2014-03-04 03:19:40 +04:00
|
|
|
if ( event ) {
|
|
|
|
// Make sure we have the expected elements set
|
2014-03-06 19:58:56 +04:00
|
|
|
ok(event.context, "Context should be set");
|
|
|
|
ok(event.tile, "Tile should be set");
|
|
|
|
ok(event.rendered, "Rendered should be set");
|
2014-03-04 03:19:40 +04:00
|
|
|
}
|
|
|
|
viewer.close();
|
|
|
|
start();
|
|
|
|
};
|
|
|
|
|
|
|
|
viewer.addHandler( 'tile-drawing', tileDrawing );
|
|
|
|
viewer.open( '/test/data/testpattern.dzi' );
|
|
|
|
} );
|
|
|
|
|
2013-08-28 16:50:22 +04:00
|
|
|
} )();
|