diff --git a/src/mixins/canvas_events.mixin.js b/src/mixins/canvas_events.mixin.js index 14755d744ca..50f0e045da7 100644 --- a/src/mixins/canvas_events.mixin.js +++ b/src/mixins/canvas_events.mixin.js @@ -44,6 +44,7 @@ addListener(this.upperCanvasEl, 'mousedown', this._onMouseDown); addListener(this.upperCanvasEl, 'mousemove', this._onMouseMove); addListener(this.upperCanvasEl, 'mousewheel', this._onMouseWheel); + addListener(this.upperCanvasEl, 'mouseout', this._onMouseOut); // touch events addListener(this.upperCanvasEl, 'touchstart', this._onMouseDown); @@ -72,6 +73,7 @@ this._onLongPress = this._onLongPress.bind(this); this._onOrientationChange = this._onOrientationChange.bind(this); this._onMouseWheel = this._onMouseWheel.bind(this); + this._onMouseOut = this._onMouseOut.bind(this); }, /** @@ -83,6 +85,7 @@ removeListener(this.upperCanvasEl, 'mousedown', this._onMouseDown); removeListener(this.upperCanvasEl, 'mousemove', this._onMouseMove); removeListener(this.upperCanvasEl, 'mousewheel', this._onMouseWheel); + removeListener(this.upperCanvasEl, 'mouseout', this._onMouseOut); removeListener(this.upperCanvasEl, 'touchstart', this._onMouseDown); removeListener(this.upperCanvasEl, 'touchmove', this._onMouseMove); @@ -123,6 +126,17 @@ this.__onMouseWheel && this.__onMouseWheel(e, self); }, + /** + * @private + * @param {Event} e Event object fired on mousedown + */ + _onMouseOut: function(e) { + var target = this._hoveredTarget; + this.fire('mouse:out', { target: target, e: e }); + this._hoveredTarget = null; + target && target.fire('mouseout', { e: e }); + }, + /** * @private * @param {Event} [e] Event object fired on Event.js orientation change @@ -435,9 +449,16 @@ target = this.getActiveGroup(); } - if (target && target.selectable && (target.__corner || !shouldGroup)) { - this._beforeTransform(e, target); - this._setupCurrentTransform(e, target); + if (target) { + if (target.selectable && (target.__corner || !shouldGroup)) { + this._beforeTransform(e, target); + this._setupCurrentTransform(e, target); + } + + if (target !== this.getActiveGroup() && target !== this.getActiveObject()) { + this.deactivateAll(); + this.setActiveObject(target, e); + } } // we must renderAll so that active image is placed on the top canvas shouldRender && this.renderAll(); @@ -457,10 +478,6 @@ this.onBeforeScaleRotate(target); } - if (target !== this.getActiveGroup() && target !== this.getActiveObject()) { - this.deactivateAll(); - this.setActiveObject(target, e); - } }, /** diff --git a/src/shapes/object.class.js b/src/shapes/object.class.js index 7ecf74b549f..8c55e9a3894 100644 --- a/src/shapes/object.class.js +++ b/src/shapes/object.class.js @@ -31,6 +31,8 @@ * * @fires mousedown * @fires mouseup + * @fires mouseover + * @fires mouseout */ fabric.Object = fabric.util.createClass(/** @lends fabric.Object.prototype */ {