Trigger mouse over on canvas enter (#3389)

* 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
This commit is contained in:
Stefan Hayden 2016-11-01 06:11:01 -04:00 committed by Andrea Bogazzi
parent d69d471db0
commit 5915ca8d38

View file

@ -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);
@ -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);
},
@ -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);
@ -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