mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -05:00
Clean up previous fix for #1069 by better handling mouseenter / leave events.
This commit is contained in:
parent
6b3d8ecdfd
commit
93e4d81645
1 changed files with 15 additions and 14 deletions
|
@ -1272,6 +1272,7 @@ new function() { // Injection scope for event handling on the browser
|
||||||
// event requires an item hit-test or not, before changing type
|
// event requires an item hit-test or not, before changing type
|
||||||
// to the virtual value (e.g. mousemove -> mousedrag):
|
// to the virtual value (e.g. mousemove -> mousedrag):
|
||||||
hitItems = itemEvents.native[type],
|
hitItems = itemEvents.native[type],
|
||||||
|
nativeMove = type === 'mousemove',
|
||||||
tool = this._scope.tool,
|
tool = this._scope.tool,
|
||||||
view = this;
|
view = this;
|
||||||
|
|
||||||
|
@ -1284,7 +1285,7 @@ new function() { // Injection scope for event handling on the browser
|
||||||
// least one of the events responds to mousedrag, convert to it.
|
// least one of the events responds to mousedrag, convert to it.
|
||||||
// NOTE: emitMouseEvent(), as well as Tool#_handleMouseEvent() fall
|
// NOTE: emitMouseEvent(), as well as Tool#_handleMouseEvent() fall
|
||||||
// back to mousemove if the objects don't respond to mousedrag.
|
// back to mousemove if the objects don't respond to mousedrag.
|
||||||
if (type === 'mousemove' && dragging && responds('mousedrag'))
|
if (nativeMove && dragging && responds('mousedrag'))
|
||||||
type = 'mousedrag';
|
type = 'mousedrag';
|
||||||
if (!point)
|
if (!point)
|
||||||
point = this.getEventPoint(event);
|
point = this.getEventPoint(event);
|
||||||
|
@ -1297,9 +1298,7 @@ new function() { // Injection scope for event handling on the browser
|
||||||
fill: true,
|
fill: true,
|
||||||
stroke: true
|
stroke: true
|
||||||
}),
|
}),
|
||||||
// If the event doesn't require hit-testing, use the last
|
item = hit && hit.item || null,
|
||||||
// overItem as its current item, for mouseenter / mouseleave.
|
|
||||||
item = (hitItems ? hit && hit.item : overItem) || undefined,
|
|
||||||
// Keep track if view event should be handled, so we can use it
|
// Keep track if view event should be handled, so we can use it
|
||||||
// to decide if tool._handleMouseEvent() shall be called after.
|
// to decide if tool._handleMouseEvent() shall be called after.
|
||||||
handle = false,
|
handle = false,
|
||||||
|
@ -1310,18 +1309,17 @@ new function() { // Injection scope for event handling on the browser
|
||||||
|
|
||||||
// Always first call the view's mouse handlers, as required by
|
// Always first call the view's mouse handlers, as required by
|
||||||
// CanvasView, and then handle the active tool after, if any.
|
// CanvasView, and then handle the active tool after, if any.
|
||||||
// Handle mousemove first, even if this is not actually a mousemove
|
if (hitItems && item !== overItem) {
|
||||||
// event but the mouse has moved since the last event, but do not
|
// But first handle mouseenter / leave between items and also on
|
||||||
// allow it to stop the other events in that case.
|
// the view, but only if hitItems is true, see above.
|
||||||
var moveType = mouse.move || mouse.drag ? type : 'mousemove';
|
if (overItem) {
|
||||||
// Handle mouseenter / leave between items.
|
|
||||||
if (item !== overItem) {
|
|
||||||
if (overItem)
|
|
||||||
emitMouseEvent(overItem, 'mouseleave', event, point);
|
emitMouseEvent(overItem, 'mouseleave', event, point);
|
||||||
if (item)
|
}
|
||||||
|
if (item) {
|
||||||
emitMouseEvent(item, 'mouseenter', event, point);
|
emitMouseEvent(item, 'mouseenter', event, point);
|
||||||
}
|
}
|
||||||
overItem = item;
|
overItem = item;
|
||||||
|
}
|
||||||
// Handle mouseenter / leave on the view.
|
// Handle mouseenter / leave on the view.
|
||||||
if (wasInView ^ inView) {
|
if (wasInView ^ inView) {
|
||||||
emitMouseEvent(this, inView ? 'mouseenter' : 'mouseleave',
|
emitMouseEvent(this, inView ? 'mouseenter' : 'mouseleave',
|
||||||
|
@ -1333,7 +1331,10 @@ new function() { // Injection scope for event handling on the browser
|
||||||
// mousedrag is allowed to leave the view and still triggers events,
|
// mousedrag is allowed to leave the view and still triggers events,
|
||||||
// but do not trigger two subsequent even with the same location.
|
// but do not trigger two subsequent even with the same location.
|
||||||
if ((inView || mouse.drag) && !point.equals(lastPoint)) {
|
if ((inView || mouse.drag) && !point.equals(lastPoint)) {
|
||||||
emitMouseEvents(this, item, moveType, event, point, lastPoint);
|
// Handle mousemove even if this is not actually a mousemove
|
||||||
|
// event but the mouse has moved since the last event.
|
||||||
|
emitMouseEvents(this, item, nativeMove ? type : 'mousemove',
|
||||||
|
event, point, lastPoint);
|
||||||
handle = true;
|
handle = true;
|
||||||
}
|
}
|
||||||
wasInView = inView;
|
wasInView = inView;
|
||||||
|
|
Loading…
Reference in a new issue