Fix item-level mousedrag events again.

This commit is contained in:
Jürg Lehni 2013-12-11 00:10:03 +01:00
parent e2b48ebf33
commit 45f9fcd830

View file

@ -103,7 +103,7 @@ var CanvasView = View.extend(/** @lends CanvasView# */{
downItem, downItem,
lastItem, lastItem,
overItem, overItem,
hasDrag, dragItem,
dblClick, dblClick,
clickTime; clickTime;
@ -171,22 +171,26 @@ var CanvasView = View.extend(/** @lends CanvasView# */{
dblClick = lastItem == item && (Date.now() - clickTime < 300); dblClick = lastItem == item && (Date.now() - clickTime < 300);
downItem = lastItem = item; downItem = lastItem = item;
downPoint = lastPoint = overPoint = point; downPoint = lastPoint = overPoint = point;
hasDrag = downItem && downItem.responds('mousedrag'); dragItem = downItem;
// Find the first item pu the chain that responds to drag.
// NOTE: Drag event don't bubble
while (dragItem && !dragItem.responds('mousedrag'))
dragItem = dragItem._parent;
break; break;
case 'mouseup': case 'mouseup':
// stopping mousup events does not prevent mousedrag / mousemove // stopping mousup events does not prevent mousedrag / mousemove
// hanlding here, but it does click / doubleclick // hanlding here, but it does click / doubleclick
stopped = callEvent(this, type, event, point, item, downPoint); stopped = callEvent(this, type, event, point, item, downPoint);
if (hasDrag) { if (dragItem) {
// If the point has changed since the last mousedrag event, // If the point has changed since the last mousedrag event,
// send another one // send another one
if (lastPoint && !lastPoint.equals(point)) if (lastPoint && !lastPoint.equals(point))
callEvent(this, 'mousedrag', event, point, downItem, callEvent(this, 'mousedrag', event, point, dragItem,
lastPoint); lastPoint);
// If we end up over another item, send it a mousemove event // If we end up over another item, send it a mousemove event
// now. Use point as overPoint, so delta is (0, 0) since // now. Use point as overPoint, so delta is (0, 0) since
// this will be the first mousemove event for this item. // this will be the first mousemove event for this item.
if (item !== downItem) { if (item !== dragItem) {
overPoint = point; overPoint = point;
callEvent(this, 'mousemove', event, point, item, callEvent(this, 'mousemove', event, point, item,
overPoint); overPoint);
@ -198,15 +202,14 @@ var CanvasView = View.extend(/** @lends CanvasView# */{
? 'doubleclick' : 'click', event, downPoint, item); ? 'doubleclick' : 'click', event, downPoint, item);
dblClick = false; dblClick = false;
} }
downItem = null; downItem = dragItem = null;
hasDrag = false;
break; break;
case 'mousemove': case 'mousemove':
// Allow both mousedrag and mousemove events to stop mousemove // Allow both mousedrag and mousemove events to stop mousemove
// events from reaching tools. // events from reaching tools.
if (hasDrag) if (dragItem)
stopped = callEvent(this, 'mousedrag', event, point, stopped = callEvent(this, 'mousedrag', event, point,
downItem, lastPoint); dragItem, lastPoint);
// TODO: Consider implementing this again? "If we have a // TODO: Consider implementing this again? "If we have a
// mousedrag event, do not send mousemove events to any // mousedrag event, do not send mousemove events to any
// item while we're dragging." // item while we're dragging."