Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISSUE-4115 - triggers in/out events for sub targets #6013

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
54c5923
Fixes #4115 - triggers in/out events for sub targets; and calls _setC…
jakedowns Dec 3, 2019
b6fa464
added a .__guid property to each object to simplify hoveredTargets an…
jakedowns Dec 4, 2019
3c082a9
Revert "added a .__guid property to each object to simplify hoveredTa…
jakedowns Dec 11, 2019
5fbf4a4
Merge branch 'master' into ISSUE-4115-mouse-over-out-sub-targets
jakedowns Dec 11, 2019
15ab4ba
reverting hoveredTargets to bare bones implementation
jakedowns Dec 11, 2019
38ae830
this is an idea
asturur Dec 14, 2019
bc48c2d
this is an idea
asturur Dec 14, 2019
f3bb7ed
adjustments to PR #6032
jakedowns Dec 15, 2019
69647aa
Merge branch 'sub-targeting-mouse-in-out' into ISSUE-4115-mouse-over-…
jakedowns Dec 15, 2019
4ab6f2a
adjust additional _hoveredTarget management
jakedowns Dec 15, 2019
f24f61f
move _this to where it's needed
jakedowns Dec 15, 2019
bd6590d
more cleanup of lingering stuff from earlier commits
jakedowns Dec 15, 2019
7d40b4d
fix linter error
jakedowns Dec 15, 2019
b4251d0
targets: default to empty array
jakedowns Dec 15, 2019
41978dd
correction to jsdoc array of fabric.Object type declaration
jakedowns Dec 15, 2019
deb64f0
remove genuine unique id GUID getter from object class
jakedowns Dec 15, 2019
426e68c
simplify & optimize for minification
jakedowns Dec 15, 2019
0cd4196
updated _fireEnterLeaveEvents to include subTargets
jakedowns Dec 15, 2019
1909d1f
adjusted _setCursorFromEvent to account for subTargets
jakedowns Dec 15, 2019
7483142
stub in unit test for #4115
jakedowns Dec 15, 2019
c4e53ce
revert change in _onDragOver, call to _fireEnterLeaveEvents should be…
jakedowns Dec 16, 2019
3826d2e
updates after running tests
jakedowns Dec 18, 2019
3714348
rm unused var
jakedowns Dec 18, 2019
dbaf781
replace Array.fill with for loop (IE support)
jakedowns Dec 18, 2019
06e9c7e
update _fireEnterLeaveEvents to match _fireOverOutEvents
jakedowns Dec 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/mixins/canvas_events.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,6 @@
* @param {Event} e Event object fired on mousedown
*/
_onMouseOut: function(e) {
console.log('_onMouseOut',e);

var target = this._hoveredTarget;
this.fire('mouse:out', { target: target, e: e });
this._hoveredTarget = null;
Expand Down Expand Up @@ -831,8 +829,9 @@
_fireOverOutEvents: function(target, e) {
var _this = this, _hoveredTarget = this._hoveredTarget,
_hoveredTargets = this._hoveredTargets, targets = this.targets,
diff = _hoveredTargets.length - targets.length;
[target].concat(targets, new Array(diff > 0 ? diff : 0)).forEach(function(_target, index) {
diff = _hoveredTargets.length - targets.length,
diffArrayLength = diff > 0 ? diff : 0;
[target].concat(targets, new Array(diffArrayLength).fill(null)).forEach(function(_target, index) {
_this.fireSyntheticInOutEvents(_target, e, {
oldTarget: index === 0 ? _hoveredTarget : _hoveredTargets[index - 1],
canvasEvtOut: 'mouse:out',
Expand Down
2 changes: 1 addition & 1 deletion src/shapes/group.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
strokeWidth: 0,

/**
* Indicates if click events should also check for subtargets
* Indicates if click, mouseover, mouseout events & hoverCursor should also check for subtargets
* @type Boolean
* @default
*/
Expand Down
24 changes: 19 additions & 5 deletions test/unit/canvas_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,6 @@
if (obj._objects) {
obj._objects.forEach(setSubTargetCheckRecursive);
}
// TODO: maybe this property could've been baked into the JSON?
// not sure if loadFromJSON accounts for it tho
obj.subTargetCheck = true;
obj.on('mouseover', function() {
counterOver++;
Expand All @@ -505,17 +503,33 @@
});
canvas.setActiveObject(activeSelection);
setSubTargetCheckRecursive(activeSelection);
// perform MouseOver event on deepest nested subTarget

// perform MouseOver event on a deeply nested subTarget
var moveEvent = fabric.document.createEvent('HTMLEvents');
moveEvent.initEvent('mousemove', true, true);
var target = canvas.item(1);
canvas.targets = [
target.item(1),
target.item(1).item(1),
target.item(1).item(1).item(1)
];
canvas._fireOverOutEvents(target, moveEvent);
assert.equal(counterOver, 4, 'mouseover fabric event fired 4 times for primary hoveredTarget & subTargets');
assert.equal(canvas._hoveredTarget, activeSelection, 'activeSelection is _hoveredTarget');
assert.equal(canvas._hoveredTarget, target, 'activeSelection is _hoveredTarget');
assert.equal(canvas._hoveredTargets.length, 3, '3 additional subTargets are captured as _hoveredTargets');

// perform MouseOut even on all hoveredTargets
assert.equal(counterOver, 4, 'mouseout fabric event fired 4 times for primary hoveredTarget & subTargets');
canvas.targets = [];
canvas._fireOverOutEvents(null, moveEvent);
assert.equal(counterOut, 4, 'mouseout fabric event fired 4 times for primary hoveredTarget & subTargets');
assert.equal(canvas._hoveredTarget, null, '_hoveredTarget has been set to null');
assert.equal(canvas._hoveredTargets.length, 0, '_hoveredTargets array is empty');
});
});

// TODO: QUnit.test('mousemove: subTargetCheck: setCursorFromEvent considers subTargets')
// TODO: QUnit.test('mousemove: subTargetCheck: setCursorFromEvent considers subTargets in reverse order, so the top-most subTarget's .hoverCursor takes precedence')

jakedowns marked this conversation as resolved.
Show resolved Hide resolved
['MouseDown', 'MouseMove', 'MouseOut', 'MouseEnter', 'MouseWheel', 'DoubleClick'].forEach(function(eventType) {
QUnit.test('avoid multiple registration - ' + eventType, function(assert) {
var funcName = '_on' + eventType;
Expand Down