fix mouseleave on stage. close #811

This commit is contained in:
Anton Lavrenov
2019-12-18 13:16:03 -05:00
parent 7787dfdf14
commit 961e61c1bc
5 changed files with 73 additions and 5 deletions

View File

@@ -8,7 +8,7 @@
* Konva JavaScript Framework v4.0.18 * Konva JavaScript Framework v4.0.18
* http://konvajs.org/ * http://konvajs.org/
* Licensed under the MIT * Licensed under the MIT
* Date: Thu Nov 28 2019 * Date: Wed Dec 18 2019
* *
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS) * Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
* Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva) * Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva)
@@ -6041,6 +6041,7 @@
if (targetShape && eventsEnabled) { if (targetShape && eventsEnabled) {
targetShape._fireAndBubble(MOUSEOUT, { evt: evt }); targetShape._fireAndBubble(MOUSEOUT, { evt: evt });
targetShape._fireAndBubble(MOUSELEAVE$1, { evt: evt }); targetShape._fireAndBubble(MOUSELEAVE$1, { evt: evt });
this._fire(MOUSELEAVE$1, { evt: evt, target: this, currentTarget: this });
this.targetShape = null; this.targetShape = null;
} }
else if (eventsEnabled) { else if (eventsEnabled) {

4
konva.min.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -443,6 +443,7 @@ export class Stage extends Container<BaseLayer> {
if (targetShape && eventsEnabled) { if (targetShape && eventsEnabled) {
targetShape._fireAndBubble(MOUSEOUT, { evt: evt }); targetShape._fireAndBubble(MOUSEOUT, { evt: evt });
targetShape._fireAndBubble(MOUSELEAVE, { evt: evt }); targetShape._fireAndBubble(MOUSELEAVE, { evt: evt });
this._fire(MOUSELEAVE, { evt: evt, target: this, currentTarget: this });
this.targetShape = null; this.targetShape = null;
} else if (eventsEnabled) { } else if (eventsEnabled) {
this._fire(MOUSELEAVE, { this._fire(MOUSELEAVE, {

View File

@@ -1983,6 +1983,72 @@ suite('MouseEvents', function() {
assert.equal(mouseleave, 1, 'mouseleave should be 1'); assert.equal(mouseleave, 1, 'mouseleave should be 1');
}); });
test('test mouseleave from the shape', function() {
var stage = addStage();
var layer = new Konva.Layer();
stage.add(layer);
var circle = new Konva.Circle({
fill: 'red',
radius: 100,
x: 200,
y: 0
})
layer.add(circle);
layer.draw();
var mouseleave = 0;
stage.on('mouseleave', function() {
mouseleave += 1;
});
var mouseout = 0;
stage.on('mouseout', function() {
mouseout += 1;
});
var circleMouseleave = 0;
circle.on('mouseleave', function() {
circleMouseleave += 1;
});
var circleMouseout = 0;
circle.on('mouseout', function() {
circleMouseout += 1;
});
var layerMouseleave = 0;
layer.on('mouseleave', function() {
layerMouseleave += 1;
});
var layerMouseout = 0;
layer.on('mouseout', function() {
layerMouseout += 1;
});
// move into a circle
stage.simulateMouseMove({ x: 200, y : 5});
var top = stage.content.getBoundingClientRect().top;
var evt = {
clientX: 200,
clientY: -5 + top,
button: 0
};
stage._mouseout(evt);
assert.equal(circleMouseleave, 1, 'circleMouseleave should be 1');
assert.equal(circleMouseout, 1, 'circleMouseout should be 1');
assert.equal(layerMouseleave, 1, 'layerMouseleave should be 1');
assert.equal(layerMouseout, 1, 'layerMouseout should be 1');
assert.equal(mouseleave, 1, 'mouseleave should be 1');
assert.equal(mouseout, 1, 'mouseout should be 1');
});
test('should not trigger mouseenter on stage when we go to the shape from empty space', function() { test('should not trigger mouseenter on stage when we go to the shape from empty space', function() {
var stage = addStage(); var stage = addStage();
var layer = new Konva.Layer(); var layer = new Konva.Layer();

View File

@@ -769,9 +769,9 @@ suite('Caching', function() {
}); });
group.add(circle); group.add(circle);
group.cache(); group.cache();
stage.draw();
cloneAndCompareLayer(layer, 210); const canvas = group._cache.get('canvas').scene;
assert.equal(canvas.width, 105 * canvas.pixelRatio)
}); });
test('cache group with rectangle with fill and opacity', function() { test('cache group with rectangle with fill and opacity', function() {