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

Fixes StaticCanvas.onBeforeScaleRotate not triggering when canvas is zoomed #4748

Merged
merged 2 commits into from
Feb 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/mixins/canvas_events.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@
this.stateful && target.saveState();

// determine if it's a drag or rotate case
if (target._findTargetCorner(this.getPointer(e))) {
if (target._findTargetCorner(this.getPointer(e, true))) {
this.onBeforeScaleRotate(target);
}

Expand Down
50 changes: 50 additions & 0 deletions test/unit/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -2337,6 +2337,56 @@
fabric.Canvas.prototype._onResize = originalResize;
});

QUnit.test('_beforeTransform', function (assert) {
assert.ok(typeof canvas._beforeTransform === 'function');

var canvasEl = canvas.getElement(),
canvasOffset = fabric.util.getElementOffset(canvasEl);

var rect = new fabric.Rect({ left: 50, top: 50, width: 50, height: 50 });
canvas.add(rect);
canvas.setActiveObject(rect);

var t, counter = 0;
var _onBeforeScaleRotate = canvas.onBeforeScaleRotate;
canvas.onBeforeScaleRotate = function (target) {
t = target;
counter++;
};

var corners = ['tl', 'mt', 'tr', 'mr', 'br', 'mb', 'bl', 'ml', 'mtr'];
for (var i = 0; i < corners.length; i++) {
var co = rect.oCoords[corners[i]].corner;
var e = {
clientX: canvasOffset.left + (co.tl.x + co.tr.x) / 2,
clientY: canvasOffset.top + (co.tl.y + co.bl.y) / 2,
which: 1
};
canvas._beforeTransform(e, rect);
}
assert.equal(counter, corners.length, '_beforeTransform should trigger onBeforeScaleRotate for all corners');
assert.equal(t, rect, 'onBeforeScaleRotate should receive correct target');

canvas.zoomToPoint({ x: 25, y: 25 }, 2);

t = null;
counter = 0;
for (var i = 0; i < corners.length; i++) {
var c = corners[i];
var co = rect.oCoords[c].corner;
var e = {
clientX: canvasOffset.left + (co.tl.x + co.tr.x) / 2,
clientY: canvasOffset.top + (co.tl.y + co.bl.y) / 2,
which: 1
};
canvas._beforeTransform(e, rect);
}
assert.equal(counter, corners.length, '_beforeTransform should trigger onBeforeScaleRotate when canvas is zoomed');
assert.equal(t, rect, 'onBeforeScaleRotate should receive correct target when canvas is zoomed');

canvas.zoomToPoint({ x: 0, y: 0 }, 1);
canvas.onBeforeScaleRotate = _onBeforeScaleRotate;
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect test.


QUnit.test('actionIsDisabled ', function(assert) {
assert.ok(typeof fabric.Canvas.prototype.actionIsDisabled === 'function', 'actionIsDisabled is a function');
Expand Down