Skip to content

Commit

Permalink
Trigger mouse over on canvas enter (fabricjs#3389)
Browse files Browse the repository at this point in the history
* fire a mouse:over event once when mouse enters the canvas
* only fire if we don't find a target
* only fire if we find no target and set the hoveredTarget to null
  • Loading branch information
stefanhayden authored and asturur committed Nov 1, 2016
1 parent d69d471 commit 5915ca8
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/mixins/canvas_events.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
addListener(this.upperCanvasEl, 'mousedown', this._onMouseDown);
addListener(this.upperCanvasEl, 'mousemove', this._onMouseMove);
addListener(this.upperCanvasEl, 'mouseout', this._onMouseOut);
addListener(this.upperCanvasEl, 'mouseenter', this._onMouseEnter);
addListener(this.upperCanvasEl, 'wheel', this._onMouseWheel);
addListener(this.upperCanvasEl, 'contextmenu', this._onContextMenu);

Expand Down Expand Up @@ -75,6 +76,7 @@
this._onOrientationChange = this._onOrientationChange.bind(this);
this._onMouseWheel = this._onMouseWheel.bind(this);
this._onMouseOut = this._onMouseOut.bind(this);
this._onMouseEnter = this._onMouseEnter.bind(this);
this._onContextMenu = this._onContextMenu.bind(this);
},

Expand All @@ -87,6 +89,7 @@
removeListener(this.upperCanvasEl, 'mousedown', this._onMouseDown);
removeListener(this.upperCanvasEl, 'mousemove', this._onMouseMove);
removeListener(this.upperCanvasEl, 'mouseout', this._onMouseOut);
removeListener(this.upperCanvasEl, 'mouseenter', this._onMouseEnter);
removeListener(this.upperCanvasEl, 'wheel', this._onMouseWheel);
removeListener(this.upperCanvasEl, 'contextmenu', this._onContextMenu);

Expand Down Expand Up @@ -139,6 +142,17 @@
target && target.fire('mouseout', { e: e });
},

/**
* @private
* @param {Event} e Event object fired on mouseenter
*/
_onMouseEnter: function(e) {
if (!this.findTarget(e)) {
this.fire('mouse:over', { target: null, e: e });
this._hoveredTarget = null;
}
},

/**
* @private
* @param {Event} [e] Event object fired on Event.js orientation change
Expand Down

0 comments on commit 5915ca8

Please sign in to comment.