mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-03-16 22:10:32 +00:00
parent
e70e65fe92
commit
1c10b8c1e3
6 changed files with 731 additions and 545 deletions
|
|
@ -16,8 +16,6 @@
|
|||
* @tutorial {@link http://fabricjs.com/fabric-intro-part-1#canvas}
|
||||
* @see {@link fabric.Canvas#initialize} for constructor definition
|
||||
*
|
||||
* @fires object:added
|
||||
* @fires object:removed
|
||||
* @fires object:modified
|
||||
* @fires object:rotating
|
||||
* @fires object:scaling
|
||||
|
|
@ -37,6 +35,11 @@
|
|||
* @fires mouse:out
|
||||
* @fires mouse:dblclick
|
||||
*
|
||||
* @fires dragover
|
||||
* @fires dragenter
|
||||
* @fires dragleave
|
||||
* @fires drop
|
||||
*
|
||||
*/
|
||||
fabric.Canvas = fabric.util.createClass(fabric.StaticCanvas, /** @lends fabric.Canvas.prototype */ {
|
||||
|
||||
|
|
|
|||
|
|
@ -56,7 +56,10 @@
|
|||
addListener(this.upperCanvasEl, 'mouseenter', this._onMouseEnter);
|
||||
addListener(this.upperCanvasEl, 'wheel', this._onMouseWheel);
|
||||
addListener(this.upperCanvasEl, 'contextmenu', this._onContextMenu);
|
||||
|
||||
addListener(this.upperCanvasEl, 'dragover', this._onDragOver);
|
||||
addListener(this.upperCanvasEl, 'dragenter', this._onDragEnter);
|
||||
addListener(this.upperCanvasEl, 'dragleave', this._onDragLeave);
|
||||
addListener(this.upperCanvasEl, 'drop', this._onDrop);
|
||||
// touch events
|
||||
addListener(this.upperCanvasEl, 'touchstart', this._onMouseDown, { passive: false });
|
||||
addListener(this.upperCanvasEl, 'touchmove', this._onMouseMove, { passive: false });
|
||||
|
|
@ -74,7 +77,7 @@
|
|||
* @private
|
||||
*/
|
||||
_bindEvents: function() {
|
||||
if (this.eventsBinded) {
|
||||
if (this.eventsBound) {
|
||||
// for any reason we pass here twice we do not want to bind events twice.
|
||||
return;
|
||||
}
|
||||
|
|
@ -92,7 +95,11 @@
|
|||
this._onMouseEnter = this._onMouseEnter.bind(this);
|
||||
this._onContextMenu = this._onContextMenu.bind(this);
|
||||
this._onDoubleClick = this._onDoubleClick.bind(this);
|
||||
this.eventsBinded = true;
|
||||
this._onDragOver = this._onDragOver.bind(this);
|
||||
this._onDragEnter = this._simpleEventHandler.bind(this, 'dragenter');
|
||||
this._onDragLeave = this._simpleEventHandler.bind(this, 'dragleave');
|
||||
this._onDrop = this._simpleEventHandler.bind(this, 'drop');
|
||||
this.eventsBound = true;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -110,6 +117,10 @@
|
|||
removeListener(this.upperCanvasEl, 'doubleclick', this._onDoubleClick);
|
||||
removeListener(this.upperCanvasEl, 'touchstart', this._onMouseDown);
|
||||
removeListener(this.upperCanvasEl, 'touchmove', this._onMouseMove);
|
||||
removeListener(this.upperCanvasEl, 'dragover', this._onDragOver);
|
||||
removeListener(this.upperCanvasEl, 'dragenter', this._onDragEnter);
|
||||
removeListener(this.upperCanvasEl, 'dragleave', this._onDragLeave);
|
||||
removeListener(this.upperCanvasEl, 'drop', this._onDrop);
|
||||
|
||||
if (typeof eventjs !== 'undefined' && 'remove' in eventjs) {
|
||||
eventjs.remove(this.upperCanvasEl, 'gesture', this._onGesture);
|
||||
|
|
@ -202,6 +213,17 @@
|
|||
this.__onLongPress && this.__onLongPress(e, self);
|
||||
},
|
||||
|
||||
/**
|
||||
* prevent default to allow drop event to be fired
|
||||
* @private
|
||||
* @param {Event} [e] Event object fired on Event.js shake
|
||||
*/
|
||||
_onDragOver: function(e) {
|
||||
e.preventDefault();
|
||||
var target = this._simpleEventHandler('dragover', e);
|
||||
this._fireEnterLeaveEvents(target, e);
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {Event} e Event object fired on mousedown
|
||||
|
|
@ -378,6 +400,32 @@
|
|||
shouldRender && this.requestRenderAll();
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Handle event firing for target and subtargets
|
||||
* @param {Event} e event from mouse
|
||||
* @param {String} eventType event to fire (up, down or move)
|
||||
* @return {Fabric.Object} target return the the target found, for internal reasons.
|
||||
*/
|
||||
_simpleEventHandler: function(eventType, e) {
|
||||
var target = this.findTarget(e),
|
||||
targets = this.targets,
|
||||
options = {
|
||||
e: e,
|
||||
target: target,
|
||||
subTargets: targets,
|
||||
};
|
||||
this.fire(eventType, options);
|
||||
target && target.fire(eventType, options);
|
||||
if (!targets) {
|
||||
return target;
|
||||
}
|
||||
for (var i = 0; i < targets.length; i++) {
|
||||
targets[i].fire(eventType, options);
|
||||
}
|
||||
return target;
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Handle event firing for target and subtargets
|
||||
|
|
@ -663,28 +711,64 @@
|
|||
},
|
||||
|
||||
/**
|
||||
* Manage the mouseout, mouseover events for the fabric object on the canvas
|
||||
* @param {Fabric.Object} target the target where the target from the mousemove event
|
||||
* @param {Event} e Event object fired on mousemove
|
||||
* @private
|
||||
*/
|
||||
_fireOverOutEvents: function(target, e) {
|
||||
var overOpt, outOpt, hoveredTarget = this._hoveredTarget;
|
||||
if (hoveredTarget !== target) {
|
||||
overOpt = { e: e, target: target, previousTarget: this._hoveredTarget };
|
||||
outOpt = { e: e, target: this._hoveredTarget, nextTarget: target };
|
||||
this._hoveredTarget = target;
|
||||
this.fireSynteticInOutEvents(target, e, {
|
||||
targetName: '_hoveredTarget',
|
||||
canvasEvtOut: 'mouse:out',
|
||||
evtOut: 'mouseout',
|
||||
canvasEvtIn: 'mouse:over',
|
||||
evtIn: 'mouseover',
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Manage the dragEnter, dragLeave events for the fabric objects on the canvas
|
||||
* @param {Fabric.Object} target the target where the target from the onDrag event
|
||||
* @param {Event} e Event object fired on ondrag
|
||||
* @private
|
||||
*/
|
||||
_fireEnterLeaveEvents: function(target, e) {
|
||||
this.fireSynteticInOutEvents(target, e, {
|
||||
targetName: '_draggedoverTarget',
|
||||
evtOut: 'dragleave',
|
||||
evtIn: 'dragenter',
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Manage the syntetic in/out events for the fabric objects on the canvas
|
||||
* @param {Fabric.Object} target the target where the target from the supported events
|
||||
* @param {Event} e Event object fired
|
||||
* @param {Object} config configuration for the function to work
|
||||
* @param {String} config.targetName property on the canvas where the old target is stored
|
||||
* @param {String} [config.canvasEvtOut] name of the event to fire at canvas level for out
|
||||
* @param {String} config.evtOut name of the event to fire for out
|
||||
* @param {String} [config.canvasEvtIn] name of the event to fire at canvas level for in
|
||||
* @param {String} config.evtIn name of the event to fire for in
|
||||
* @private
|
||||
*/
|
||||
fireSynteticInOutEvents: function(target, e, config) {
|
||||
var inOpt, outOpt, oldTarget = this[config.targetName], outFires, inFires,
|
||||
targetChanged = oldTarget !== target, canvasEvtIn = config.canvasEvtIn, canvasEvtOut = config.canvasEvtOut;
|
||||
if (targetChanged) {
|
||||
inOpt = { e: e, target: target, previousTarget: oldTarget };
|
||||
outOpt = { e: e, target: oldTarget, nextTarget: target };
|
||||
this[config.targetName] = target;
|
||||
}
|
||||
if (target) {
|
||||
if (hoveredTarget !== target) {
|
||||
if (hoveredTarget) {
|
||||
this.fire('mouse:out', outOpt);
|
||||
hoveredTarget.fire('mouseout', outOpt);
|
||||
}
|
||||
this.fire('mouse:over', overOpt);
|
||||
target.fire('mouseover', overOpt);
|
||||
}
|
||||
inFires = target && targetChanged;
|
||||
outFires = oldTarget && targetChanged;
|
||||
if (outFires) {
|
||||
canvasEvtOut && this.fire(canvasEvtOut, outOpt);
|
||||
oldTarget.fire(config.evtOut, outOpt);
|
||||
}
|
||||
else if (hoveredTarget) {
|
||||
this.fire('mouse:out', outOpt);
|
||||
hoveredTarget.fire('mouseout', outOpt);
|
||||
if (inFires) {
|
||||
canvasEvtIn && this.fire(canvasEvtIn, inOpt);
|
||||
target.fire(config.evtIn, inOpt);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -39,6 +39,11 @@
|
|||
* @fires mouseout
|
||||
* @fires mousewheel
|
||||
* @fires mousedblclick
|
||||
*
|
||||
* @fires dragover
|
||||
* @fires dragenter
|
||||
* @fires dragleave
|
||||
* @fires drop
|
||||
*/
|
||||
fabric.Object = fabric.util.createClass(fabric.CommonMethods, /** @lends fabric.Object.prototype */ {
|
||||
|
||||
|
|
|
|||
1
test.js
1
test.js
|
|
@ -47,6 +47,7 @@ testrunner.run({
|
|||
'./test/unit/intersection.js',
|
||||
'./test/unit/stateful.js',
|
||||
'./test/unit/textbox.js',
|
||||
'./test/unit/canvas_events.js',
|
||||
],
|
||||
// tests: ['./test/unit/pattern.js'],
|
||||
}, function(err, report) {
|
||||
|
|
|
|||
|
|
@ -2094,527 +2094,4 @@
|
|||
|
||||
assert.ok(typeof InheritedCanvasClass === 'function');
|
||||
});
|
||||
|
||||
QUnit.test('mouse:down with different buttons', function(assert) {
|
||||
var clickCount = 0;
|
||||
function mouseHandler() {
|
||||
clickCount++;
|
||||
}
|
||||
canvas.on('mouse:down', mouseHandler);
|
||||
canvas.fireMiddleClick = false;
|
||||
canvas.fireRightClick = false;
|
||||
canvas._currentTransform = false;
|
||||
canvas.isDrawingMode = false;
|
||||
canvas.__onMouseDown({ which: 1 });
|
||||
assert.equal(clickCount, 1, 'mouse down fired');
|
||||
clickCount = 0;
|
||||
canvas.__onMouseDown({ which: 3 });
|
||||
assert.equal(clickCount, 0, 'rightclick did not fire a mouse:down event');
|
||||
canvas.fireRightClick = true;
|
||||
canvas.__onMouseDown({ which: 3 });
|
||||
assert.equal(clickCount, 1, 'rightclick did fire a mouse:down event');
|
||||
clickCount = 0;
|
||||
canvas.__onMouseDown({ which: 2 });
|
||||
assert.equal(clickCount, 0, 'middleClick did not fire a mouse:down event');
|
||||
canvas.fireMiddleClick = true;
|
||||
canvas.__onMouseDown({ which: 2 });
|
||||
assert.equal(clickCount, 1, 'middleClick did fire a mouse:down event');
|
||||
});
|
||||
|
||||
QUnit.test('mouse:down and group selector', function(assert) {
|
||||
var e = { clientX: 30, clientY: 30, which: 1 };
|
||||
var rect = new fabric.Rect({ width: 60, height: 60 });
|
||||
var expectedGroupSelector = { ex: 30, ey: 30, top: 0, left: 0 };
|
||||
canvas.__onMouseDown(e);
|
||||
assert.deepEqual(canvas._groupSelector, expectedGroupSelector, 'a new groupSelector is created');
|
||||
canvas.add(rect);
|
||||
canvas.__onMouseUp(e);
|
||||
canvas.__onMouseDown(e);
|
||||
assert.deepEqual(canvas._groupSelector, null, 'with object on target no groupSelector is started');
|
||||
rect.selectable = false;
|
||||
canvas.__onMouseUp(e);
|
||||
canvas.__onMouseDown(e);
|
||||
assert.deepEqual(canvas._groupSelector, null, 'with object non selectable but already selected groupSelector is not started');
|
||||
canvas.__onMouseUp(e);
|
||||
canvas.discardActiveObject();
|
||||
rect.isEditing = true;
|
||||
canvas.__onMouseDown(e);
|
||||
assert.deepEqual(canvas._groupSelector, null, 'with object editing, groupSelector is not started');
|
||||
canvas.__onMouseUp(e);
|
||||
canvas.discardActiveObject();
|
||||
rect.isEditing = false;
|
||||
canvas.__onMouseDown(e);
|
||||
assert.deepEqual(canvas._groupSelector, expectedGroupSelector, 'a new groupSelector is created');
|
||||
canvas.__onMouseUp(e);
|
||||
});
|
||||
|
||||
QUnit.test('mouse:up isClick = true', function(assert) {
|
||||
var e = { clientX: 30, clientY: 30, which: 1 };
|
||||
var isClick = false;
|
||||
canvas.on('mouse:up', function(opt) {
|
||||
isClick = opt.isClick;
|
||||
});
|
||||
canvas.__onMouseDown(e);
|
||||
canvas.__onMouseUp(e);
|
||||
assert.equal(isClick, true, 'without moving the pointer, the click is true');
|
||||
});
|
||||
|
||||
QUnit.test('setDimensions and active brush', function(assert) {
|
||||
var prepareFor = false;
|
||||
var rendered = false;
|
||||
var canva = new fabric.Canvas(null, { width: 500, height: 500 });
|
||||
var brush = new fabric.PencilBrush({ color: 'red', width: 4 });
|
||||
canva.isDrawingMode = true;
|
||||
canva.freeDrawingBrush = brush;
|
||||
canva._isCurrentlyDrawing = true;
|
||||
brush._render = function() { rendered = true; };
|
||||
brush._setBrushStyles = function() { prepareFor = true; };
|
||||
canva.setDimensions({ width: 200, height: 200 });
|
||||
canva.renderAll();
|
||||
assert.equal(rendered, true, 'the brush called the _render method');
|
||||
assert.equal(prepareFor, true, 'the brush called the _setBrushStyles method');
|
||||
});
|
||||
|
||||
QUnit.test('mouse:up isClick = false', function(assert) {
|
||||
var e = { clientX: 30, clientY: 30, which: 1 };
|
||||
var e2 = { clientX: 31, clientY: 31, which: 1 };
|
||||
var isClick = true;
|
||||
canvas.on('mouse:up', function(opt) {
|
||||
isClick = opt.isClick;
|
||||
});
|
||||
canvas.__onMouseDown(e);
|
||||
canvas.__onMouseMove(e2);
|
||||
canvas.__onMouseUp(e2);
|
||||
assert.equal(isClick, false, 'moving the pointer, the click is false');
|
||||
});
|
||||
|
||||
QUnit.test('avoid multiple bindings', function(assert) {
|
||||
var c = new fabric.Canvas();
|
||||
var eventsArray = [
|
||||
c._onMouseDown,
|
||||
c._onMouseMove,
|
||||
c._onMouseUp,
|
||||
c._onResize,
|
||||
c._onGesture,
|
||||
c._onDrag,
|
||||
c._onShake,
|
||||
c._onLongPress,
|
||||
c._onOrientationChange,
|
||||
c._onMouseWheel,
|
||||
c._onMouseOut,
|
||||
c._onMouseEnter,
|
||||
c._onContextMenu
|
||||
];
|
||||
// initialize canvas more than once
|
||||
c.initialize();
|
||||
c.initialize();
|
||||
var eventsArray2 = [
|
||||
c._onMouseDown,
|
||||
c._onMouseMove,
|
||||
c._onMouseUp,
|
||||
c._onResize,
|
||||
c._onGesture,
|
||||
c._onDrag,
|
||||
c._onShake,
|
||||
c._onLongPress,
|
||||
c._onOrientationChange,
|
||||
c._onMouseWheel,
|
||||
c._onMouseOut,
|
||||
c._onMouseEnter,
|
||||
c._onContextMenu
|
||||
];
|
||||
assert.deepEqual(eventsArray, eventsArray2, 'after first initialize, functions do not change.');
|
||||
});
|
||||
|
||||
QUnit.test('avoid multiple registration - mousedown', function(assert) {
|
||||
var originalMouseDown = fabric.Canvas.prototype._onMouseDown;
|
||||
var counter = 0;
|
||||
fabric.Canvas.prototype._onMouseDown = function() {
|
||||
counter++;
|
||||
};
|
||||
var c = new fabric.Canvas();
|
||||
// initialize canvas more than once
|
||||
c.initialize(c.lowerCanvasEl);
|
||||
c.initialize(c.lowerCanvasEl);
|
||||
var event = fabric.document.createEvent('MouseEvent');
|
||||
event.initEvent('mousedown', true, true);
|
||||
c.upperCanvasEl.dispatchEvent(event);
|
||||
assert.equal(counter, 1, 'listener executed once');
|
||||
fabric.Canvas.prototype._onMouseDown = originalMouseDown;
|
||||
});
|
||||
|
||||
QUnit.test('avoid multiple registration - mousemove', function(assert) {
|
||||
var originalMouseMove = fabric.Canvas.prototype._onMouseMove;
|
||||
var counter = 0;
|
||||
fabric.Canvas.prototype._onMouseMove = function() {
|
||||
counter++;
|
||||
};
|
||||
var c = new fabric.Canvas();
|
||||
// initialize canvas more than once
|
||||
c.initialize(c.lowerCanvasEl);
|
||||
c.initialize(c.lowerCanvasEl);
|
||||
var event = fabric.document.createEvent('MouseEvent');
|
||||
event.initEvent('mousemove', true, true);
|
||||
c.upperCanvasEl.dispatchEvent(event);
|
||||
assert.equal(counter, 1, 'listener executed once');
|
||||
fabric.Canvas.prototype._onMouseMove = originalMouseMove;
|
||||
});
|
||||
|
||||
QUnit.test('avoid multiple registration - mouseup', function(assert) {
|
||||
var done = assert.async();
|
||||
var originalMouseUp = fabric.Canvas.prototype._onMouseUp;
|
||||
var counter = 0;
|
||||
fabric.Canvas.prototype._onMouseUp = function() {
|
||||
counter++;
|
||||
};
|
||||
var c = new fabric.Canvas();
|
||||
// initialize canvas more than once
|
||||
c.initialize(c.lowerCanvasEl);
|
||||
c.initialize(c.lowerCanvasEl);
|
||||
|
||||
// a mouse down is necessary to register mouse up.
|
||||
var _event = fabric.document.createEvent('MouseEvent');
|
||||
_event.initEvent('mousedown', true, true);
|
||||
c.upperCanvasEl.dispatchEvent(_event);
|
||||
setTimeout(function() {
|
||||
var event = fabric.document.createEvent('MouseEvent');
|
||||
event.initEvent('mouseup', true, true);
|
||||
fabric.document.dispatchEvent(event);
|
||||
assert.equal(counter, 1, 'listener executed once');
|
||||
fabric.Canvas.prototype._onMouseUp = originalMouseUp;
|
||||
done();
|
||||
}, 200);
|
||||
});
|
||||
|
||||
QUnit.test('avoid multiple registration - mouseout', function(assert) {
|
||||
var originalMouseOut = fabric.Canvas.prototype._onMouseOut;
|
||||
var counter = 0;
|
||||
fabric.Canvas.prototype._onMouseOut = function() {
|
||||
counter++;
|
||||
};
|
||||
var c = new fabric.Canvas();
|
||||
// initialize canvas more than once
|
||||
c.initialize(c.lowerCanvasEl);
|
||||
c.initialize(c.lowerCanvasEl);
|
||||
var event = fabric.document.createEvent('MouseEvent');
|
||||
event.initEvent('mouseout', true, true);
|
||||
c.upperCanvasEl.dispatchEvent(event);
|
||||
assert.equal(counter, 1, 'listener executed once');
|
||||
fabric.Canvas.prototype._onMouseOut = originalMouseOut;
|
||||
});
|
||||
|
||||
QUnit.test('avoid multiple registration - mouseenter', function(assert) {
|
||||
var originalMouseEnter = fabric.Canvas.prototype._onMouseEnter;
|
||||
var counter = 0;
|
||||
fabric.Canvas.prototype._onMouseEnter = function() {
|
||||
counter++;
|
||||
};
|
||||
var c = new fabric.Canvas();
|
||||
// initialize canvas more than once
|
||||
c.initialize(c.lowerCanvasEl);
|
||||
c.initialize(c.lowerCanvasEl);
|
||||
var event = fabric.document.createEvent('MouseEvent');
|
||||
event.initEvent('mouseenter', true, true);
|
||||
c.upperCanvasEl.dispatchEvent(event);
|
||||
assert.equal(counter, 1, 'listener executed once');
|
||||
fabric.Canvas.prototype._onMouseEnter = originalMouseEnter;
|
||||
});
|
||||
|
||||
QUnit.test('avoid multiple events on window', function(assert) {
|
||||
var originalResize = fabric.Canvas.prototype._onResize;
|
||||
var counter = 0;
|
||||
fabric.Canvas.prototype._onResize = function() {
|
||||
counter++;
|
||||
};
|
||||
var c = new fabric.Canvas();
|
||||
// initialize canvas more than once
|
||||
c.initialize(c.lowerCanvasEl);
|
||||
c.initialize(c.lowerCanvasEl);
|
||||
var event = fabric.document.createEvent('UIEvents');
|
||||
event.initUIEvent('resize', true, false, fabric.window, 0);
|
||||
fabric.window.dispatchEvent(event);
|
||||
assert.equal(counter, 1, 'listener on window executed once');
|
||||
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;
|
||||
});
|
||||
|
||||
QUnit.test('actionIsDisabled ', function(assert) {
|
||||
assert.ok(typeof fabric.Canvas.prototype.actionIsDisabled === 'function', 'actionIsDisabled is a function');
|
||||
var key = canvas.altActionKey;
|
||||
var target = new fabric.Object();
|
||||
var e = { };
|
||||
e[key] = false;
|
||||
assert.equal(!!canvas.actionIsDisabled('mt', target, e), false, 'action is not disabled');
|
||||
assert.equal(!!canvas.actionIsDisabled('mb', target, e), false, 'action is not disabled');
|
||||
assert.equal(!!canvas.actionIsDisabled('ml', target, e), false, 'action is not disabled');
|
||||
assert.equal(!!canvas.actionIsDisabled('mr', target, e), false, 'action is not disabled');
|
||||
assert.equal(!!canvas.actionIsDisabled('tl', target, e), false, 'action is not disabled');
|
||||
assert.equal(!!canvas.actionIsDisabled('tr', target, e), false, 'action is not disabled');
|
||||
assert.equal(!!canvas.actionIsDisabled('bl', target, e), false, 'action is not disabled');
|
||||
assert.equal(!!canvas.actionIsDisabled('br', target, e), false, 'action is not disabled');
|
||||
assert.equal(!!canvas.actionIsDisabled('mtr', target, e), false, 'action is not disabled');
|
||||
target = new fabric.Object();
|
||||
target.lockScalingX = true;
|
||||
|
||||
assert.equal(!!canvas.actionIsDisabled('mt', target, e), false, 'mt action is not disabled lockScalingX');
|
||||
assert.equal(!!canvas.actionIsDisabled('mb', target, e), false, 'mb action is not disabled lockScalingX');
|
||||
assert.equal(!!canvas.actionIsDisabled('ml', target, e), true, 'ml action is disabled lockScalingX');
|
||||
assert.equal(!!canvas.actionIsDisabled('mr', target, e), true, 'mr action is disabled lockScalingX');
|
||||
assert.equal(!!canvas.actionIsDisabled('tl', target, e), true, 'tl action is disabled lockScalingX');
|
||||
assert.equal(!!canvas.actionIsDisabled('tr', target, e), true, 'tr action is disabled lockScalingX');
|
||||
assert.equal(!!canvas.actionIsDisabled('bl', target, e), true, 'bl action is disabled lockScalingX');
|
||||
assert.equal(!!canvas.actionIsDisabled('br', target, e), true, 'br action is disabled lockScalingX');
|
||||
assert.equal(!!canvas.actionIsDisabled('mtr', target, e), false, 'mtr action is not disabled lockScalingX');
|
||||
target = new fabric.Object();
|
||||
target.lockScalingY = true;
|
||||
assert.equal(!!canvas.actionIsDisabled('mt', target, e), true, 'mt action is disabled lockScalingY');
|
||||
assert.equal(!!canvas.actionIsDisabled('mb', target, e), true, 'mb action is disabled lockScalingY');
|
||||
assert.equal(!!canvas.actionIsDisabled('ml', target, e), false, 'ml action is not disabled lockScalingY');
|
||||
assert.equal(!!canvas.actionIsDisabled('mr', target, e), false, 'mr action is not disabled lockScalingY');
|
||||
assert.equal(!!canvas.actionIsDisabled('tl', target, e), true, 'tl action is not disabled lockScalingY');
|
||||
assert.equal(!!canvas.actionIsDisabled('tr', target, e), true, 'tr action is not disabled lockScalingY');
|
||||
assert.equal(!!canvas.actionIsDisabled('bl', target, e), true, 'bl action is not disabled lockScalingY');
|
||||
assert.equal(!!canvas.actionIsDisabled('br', target, e), true, 'br action is not disabled lockScalingY');
|
||||
assert.equal(!!canvas.actionIsDisabled('mtr', target, e), false, 'mtr action is not disabledlockScalingY');
|
||||
target = new fabric.Object();
|
||||
target.lockScalingY = true;
|
||||
target.lockScalingX = true;
|
||||
assert.equal(!!canvas.actionIsDisabled('mt', target, e), true, 'mt action is disabled scaling locked');
|
||||
assert.equal(!!canvas.actionIsDisabled('mb', target, e), true, 'mb action is disabled scaling locked');
|
||||
assert.equal(!!canvas.actionIsDisabled('ml', target, e), true, 'ml action is disabled scaling locked');
|
||||
assert.equal(!!canvas.actionIsDisabled('mr', target, e), true, 'mr action is disabled scaling locked');
|
||||
assert.equal(!!canvas.actionIsDisabled('tl', target, e), true, 'tl action is disabled scaling locked');
|
||||
assert.equal(!!canvas.actionIsDisabled('tr', target, e), true, 'tr action is disabled scaling locked');
|
||||
assert.equal(!!canvas.actionIsDisabled('bl', target, e), true, 'bl action is disabled scaling locked');
|
||||
assert.equal(!!canvas.actionIsDisabled('br', target, e), true, 'br action is disabled scaling locked');
|
||||
assert.equal(!!canvas.actionIsDisabled('mtr', target, e), false, 'mtr action is not disabled scaling locked');
|
||||
target = new fabric.Object();
|
||||
target.lockRotation = true;
|
||||
assert.equal(!!canvas.actionIsDisabled('mt', target, e), false, 'mt action is not disabled lockRotation');
|
||||
assert.equal(!!canvas.actionIsDisabled('mb', target, e), false, 'mb action is not disabled lockRotation');
|
||||
assert.equal(!!canvas.actionIsDisabled('ml', target, e), false, 'ml action is not disabled lockRotation');
|
||||
assert.equal(!!canvas.actionIsDisabled('mr', target, e), false, 'mr action is not disabled lockRotation');
|
||||
assert.equal(!!canvas.actionIsDisabled('tl', target, e), false, 'tl action is not disabled lockRotation');
|
||||
assert.equal(!!canvas.actionIsDisabled('tr', target, e), false, 'tr action is not disabled lockRotation');
|
||||
assert.equal(!!canvas.actionIsDisabled('bl', target, e), false, 'bl action is not disabled lockRotation');
|
||||
assert.equal(!!canvas.actionIsDisabled('br', target, e), false, 'br action is not disabled lockRotation');
|
||||
assert.equal(!!canvas.actionIsDisabled('mtr', target, e), true, 'mtr action is disabled lockRotation');
|
||||
target = new fabric.Object();
|
||||
target.lockSkewingX = true;
|
||||
target.lockSkewingY = true;
|
||||
assert.equal(!!canvas.actionIsDisabled('mt', target, e), false, 'mt action is not disabled lockSkewing');
|
||||
assert.equal(!!canvas.actionIsDisabled('mb', target, e), false, 'mb action is not disabled lockSkewing');
|
||||
assert.equal(!!canvas.actionIsDisabled('ml', target, e), false, 'ml action is not disabled lockSkewing');
|
||||
assert.equal(!!canvas.actionIsDisabled('mr', target, e), false, 'mr action is not disabled lockSkewing');
|
||||
assert.equal(!!canvas.actionIsDisabled('tl', target, e), false, 'tl action is not disabled lockSkewing');
|
||||
assert.equal(!!canvas.actionIsDisabled('tr', target, e), false, 'tr action is not disabled lockSkewing');
|
||||
assert.equal(!!canvas.actionIsDisabled('bl', target, e), false, 'bl action is not disabled lockSkewing');
|
||||
assert.equal(!!canvas.actionIsDisabled('br', target, e), false, 'br action is not disabled lockSkewing');
|
||||
assert.equal(!!canvas.actionIsDisabled('mtr', target, e), false, 'mtr action is not disabled lockSkewing');
|
||||
e[key] = true;
|
||||
target = new fabric.Object();
|
||||
target.lockSkewingY = true;
|
||||
assert.equal(!!canvas.actionIsDisabled('mt', target, e), false, 'mt action is not disabled lockSkewingY');
|
||||
assert.equal(!!canvas.actionIsDisabled('mb', target, e), false, 'mb action is not disabled lockSkewingY');
|
||||
assert.equal(!!canvas.actionIsDisabled('ml', target, e), true, 'ml action is disabled lockSkewingY');
|
||||
assert.equal(!!canvas.actionIsDisabled('mr', target, e), true, 'mr action is disabled lockSkewingY');
|
||||
assert.equal(!!canvas.actionIsDisabled('tl', target, e), false, 'tl action is not disabled lockSkewingY');
|
||||
assert.equal(!!canvas.actionIsDisabled('tr', target, e), false, 'tr action is not disabled lockSkewingY');
|
||||
assert.equal(!!canvas.actionIsDisabled('bl', target, e), false, 'bl action is not disabled lockSkewingY');
|
||||
assert.equal(!!canvas.actionIsDisabled('br', target, e), false, 'br action is not disabled lockSkewingY');
|
||||
assert.equal(!!canvas.actionIsDisabled('mtr', target, e), false, 'mtr action is not disabled lockSkewingY');
|
||||
|
||||
e[key] = true;
|
||||
target = new fabric.Object();
|
||||
target.lockSkewingX = true;
|
||||
assert.equal(!!canvas.actionIsDisabled('mt', target, e), true, 'mt action is disabled lockSkewingX');
|
||||
assert.equal(!!canvas.actionIsDisabled('mb', target, e), true, 'mb action is disabled lockSkewingX');
|
||||
assert.equal(!!canvas.actionIsDisabled('ml', target, e), false, 'ml action is not disabled lockSkewingX');
|
||||
assert.equal(!!canvas.actionIsDisabled('mr', target, e), false, 'mr action is not disabled lockSkewingX');
|
||||
assert.equal(!!canvas.actionIsDisabled('tl', target, e), false, 'tl action is not disabled lockSkewingX');
|
||||
assert.equal(!!canvas.actionIsDisabled('tr', target, e), false, 'tr action is not disabled lockSkewingX');
|
||||
assert.equal(!!canvas.actionIsDisabled('bl', target, e), false, 'bl action is not disabled lockSkewingX');
|
||||
assert.equal(!!canvas.actionIsDisabled('br', target, e), false, 'br action is not disabled lockSkewingX');
|
||||
assert.equal(!!canvas.actionIsDisabled('mtr', target, e), false, 'mtr action is not disabled lockSkewingX');
|
||||
});
|
||||
|
||||
QUnit.test('getCornerCursor ', function(assert) {
|
||||
assert.ok(typeof fabric.Canvas.prototype.getCornerCursor === 'function', 'actionIsDisabled is a function');
|
||||
var key = canvas.altActionKey;
|
||||
var key2 = canvas.uniScaleKey;
|
||||
var target = new fabric.Object();
|
||||
var e = { };
|
||||
e[key] = false;
|
||||
assert.equal(canvas.getCornerCursor('mt', target, e), 'n-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('mb', target, e), 's-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('ml', target, e), 'w-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('mr', target, e), 'e-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('tl', target, e), 'nw-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('tr', target, e), 'ne-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('bl', target, e), 'sw-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('br', target, e), 'se-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('mtr', target, e), 'crosshair', 'action is not disabled');
|
||||
|
||||
target = new fabric.Object();
|
||||
target.hasRotatingPoint = false;
|
||||
var e = { };
|
||||
e[key] = false;
|
||||
assert.equal(canvas.getCornerCursor('mtr', target, e), 'default', 'action is not disabled');
|
||||
|
||||
target = new fabric.Object();
|
||||
target.lockScalingX = true;
|
||||
assert.equal(canvas.getCornerCursor('mt', target, e), 'n-resize', 'action is not disabled lockScalingX');
|
||||
assert.equal(canvas.getCornerCursor('mb', target, e), 's-resize', 'action is not disabled lockScalingX');
|
||||
assert.equal(canvas.getCornerCursor('ml', target, e), 'not-allowed', 'action is disabled lockScalingX');
|
||||
assert.equal(canvas.getCornerCursor('mr', target, e), 'not-allowed', 'action is disabled lockScalingX');
|
||||
assert.equal(canvas.getCornerCursor('tl', target, e), 'not-allowed', 'action is disabled lockScalingX');
|
||||
assert.equal(canvas.getCornerCursor('tr', target, e), 'not-allowed', 'action is disabled lockScalingX');
|
||||
assert.equal(canvas.getCornerCursor('bl', target, e), 'not-allowed', 'action is disabled lockScalingX');
|
||||
assert.equal(canvas.getCornerCursor('br', target, e), 'not-allowed', 'action is disabled lockScalingX');
|
||||
assert.equal(canvas.getCornerCursor('mtr', target, e), 'crosshair', 'action is not disabled lockScalingX');
|
||||
e[key2] = true;
|
||||
assert.equal(canvas.getCornerCursor('tl', target, e), 'nw-resize', 'action is not disabled lockScalingX key2');
|
||||
assert.equal(canvas.getCornerCursor('tr', target, e), 'ne-resize', 'action is not disabled lockScalingX key2');
|
||||
assert.equal(canvas.getCornerCursor('bl', target, e), 'sw-resize', 'action is not disabled lockScalingX key2');
|
||||
assert.equal(canvas.getCornerCursor('br', target, e), 'se-resize', 'action is not disabled lockScalingX key2');
|
||||
|
||||
var e = { };
|
||||
target = new fabric.Object();
|
||||
target.lockScalingY = true;
|
||||
assert.equal(canvas.getCornerCursor('mt', target, e), 'not-allowed', 'action is disabled lockScalingY');
|
||||
assert.equal(canvas.getCornerCursor('mb', target, e), 'not-allowed', 'action is disabled lockScalingY');
|
||||
assert.equal(canvas.getCornerCursor('ml', target, e), 'w-resize', 'action is not disabled lockScalingY');
|
||||
assert.equal(canvas.getCornerCursor('mr', target, e), 'e-resize', 'action is not disabled lockScalingY');
|
||||
assert.equal(canvas.getCornerCursor('tl', target, e), 'not-allowed', 'action is disabled lockScalingY');
|
||||
assert.equal(canvas.getCornerCursor('tr', target, e), 'not-allowed', 'action is disabled lockScalingY');
|
||||
assert.equal(canvas.getCornerCursor('bl', target, e), 'not-allowed', 'action is disabled lockScalingY');
|
||||
assert.equal(canvas.getCornerCursor('br', target, e), 'not-allowed', 'action is disabled lockScalingY');
|
||||
assert.equal(canvas.getCornerCursor('mtr', target, e), 'crosshair', 'action is not disabled lockScalingY');
|
||||
e[key2] = true;
|
||||
assert.equal(canvas.getCornerCursor('tl', target, e), 'nw-resize', 'action is not disabled lockScalingY key2');
|
||||
assert.equal(canvas.getCornerCursor('tr', target, e), 'ne-resize', 'action is not disabled lockScalingY key2');
|
||||
assert.equal(canvas.getCornerCursor('bl', target, e), 'sw-resize', 'action is not disabled lockScalingY key2');
|
||||
assert.equal(canvas.getCornerCursor('br', target, e), 'se-resize', 'action is not disabled lockScalingY key2');
|
||||
|
||||
var e = { };
|
||||
target = new fabric.Object();
|
||||
target.lockScalingY = true;
|
||||
target.lockScalingX = true;
|
||||
assert.equal(canvas.getCornerCursor('mt', target, e), 'not-allowed', 'action is disabled lockScaling');
|
||||
assert.equal(canvas.getCornerCursor('mb', target, e), 'not-allowed', 'action is disabled lockScaling');
|
||||
assert.equal(canvas.getCornerCursor('ml', target, e), 'not-allowed', 'action is disabled lockScaling');
|
||||
assert.equal(canvas.getCornerCursor('mr', target, e), 'not-allowed', 'action is disabled lockScaling');
|
||||
assert.equal(canvas.getCornerCursor('tl', target, e), 'not-allowed', 'action is disabled lockScaling');
|
||||
assert.equal(canvas.getCornerCursor('tr', target, e), 'not-allowed', 'action is disabled lockScaling');
|
||||
assert.equal(canvas.getCornerCursor('bl', target, e), 'not-allowed', 'action is disabled lockScaling');
|
||||
assert.equal(canvas.getCornerCursor('br', target, e), 'not-allowed', 'action is disabled lockScaling');
|
||||
assert.equal(canvas.getCornerCursor('mtr', target, e), 'crosshair', 'action is not disabled lockScaling');
|
||||
e[key2] = true;
|
||||
assert.equal(canvas.getCornerCursor('tl', target, e), 'not-allowed', 'action is disabled lockScaling key2');
|
||||
assert.equal(canvas.getCornerCursor('tr', target, e), 'not-allowed', 'action is disabled lockScaling key2');
|
||||
assert.equal(canvas.getCornerCursor('bl', target, e), 'not-allowed', 'action is disabled lockScaling key2');
|
||||
assert.equal(canvas.getCornerCursor('br', target, e), 'not-allowed', 'action is disabled lockScaling key2');
|
||||
|
||||
var e = { };
|
||||
target = new fabric.Object();
|
||||
target.lockRotation = true;
|
||||
assert.equal(canvas.getCornerCursor('mt', target, e), 'n-resize', 'action is not disabled lockRotation');
|
||||
assert.equal(canvas.getCornerCursor('mb', target, e), 's-resize', 'action is not disabled lockRotation');
|
||||
assert.equal(canvas.getCornerCursor('ml', target, e), 'w-resize', 'action is not disabled lockRotation');
|
||||
assert.equal(canvas.getCornerCursor('mr', target, e), 'e-resize', 'action is not disabled lockRotation');
|
||||
assert.equal(canvas.getCornerCursor('tl', target, e), 'nw-resize', 'action is not disabled lockRotation');
|
||||
assert.equal(canvas.getCornerCursor('tr', target, e), 'ne-resize', 'action is not disabled lockRotation');
|
||||
assert.equal(canvas.getCornerCursor('bl', target, e), 'sw-resize', 'action is not disabled lockRotation');
|
||||
assert.equal(canvas.getCornerCursor('br', target, e), 'se-resize', 'action is not disabled lockRotation');
|
||||
assert.equal(canvas.getCornerCursor('mtr', target, e), 'not-allowed', 'action is disabled lockRotation');
|
||||
|
||||
target = new fabric.Object();
|
||||
target.lockSkewingX = true;
|
||||
target.lockSkewingY = true;
|
||||
assert.equal(canvas.getCornerCursor('mt', target, e), 'n-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('mb', target, e), 's-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('ml', target, e), 'w-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('mr', target, e), 'e-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('tl', target, e), 'nw-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('tr', target, e), 'ne-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('bl', target, e), 'sw-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('br', target, e), 'se-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('mtr', target, e), 'crosshair', 'action is not disabled');
|
||||
|
||||
e[key] = true;
|
||||
target = new fabric.Object();
|
||||
target.lockSkewingY = true;
|
||||
assert.equal(canvas.getCornerCursor('mt', target, e), 'e-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('mb', target, e), 'w-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('ml', target, e), 'not-allowed', 'action is disabled');
|
||||
assert.equal(canvas.getCornerCursor('mr', target, e), 'not-allowed', 'action is disabled');
|
||||
assert.equal(canvas.getCornerCursor('tl', target, e), 'nw-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('tr', target, e), 'ne-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('bl', target, e), 'sw-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('br', target, e), 'se-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('mtr', target, e), 'crosshair', 'action is not disabled');
|
||||
|
||||
e[key] = true;
|
||||
target = new fabric.Object();
|
||||
target.lockSkewingX = true;
|
||||
assert.equal(canvas.getCornerCursor('mt', target, e), 'not-allowed', 'action is disabled');
|
||||
assert.equal(canvas.getCornerCursor('mb', target, e), 'not-allowed', 'action is disabled');
|
||||
assert.equal(canvas.getCornerCursor('ml', target, e), 'n-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('mr', target, e), 's-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('tl', target, e), 'nw-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('tr', target, e), 'ne-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('bl', target, e), 'sw-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('br', target, e), 'se-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('mtr', target, e), 'crosshair', 'action is not disabled');
|
||||
});
|
||||
})();
|
||||
|
|
|
|||
616
test/unit/canvas_events.js
Normal file
616
test/unit/canvas_events.js
Normal file
|
|
@ -0,0 +1,616 @@
|
|||
(function() {
|
||||
|
||||
var canvas = this.canvas = new fabric.Canvas(null, {enableRetinaScaling: false, width: 600, height: 600});
|
||||
var upperCanvasEl = canvas.upperCanvasEl;
|
||||
|
||||
QUnit.module('fabric.Canvas events mixin', {
|
||||
beforeEach: function() {
|
||||
upperCanvasEl.style.display = '';
|
||||
canvas.controlsAboveOverlay = fabric.Canvas.prototype.controlsAboveOverlay;
|
||||
canvas.preserveObjectStacking = fabric.Canvas.prototype.preserveObjectStacking;
|
||||
},
|
||||
afterEach: function() {
|
||||
canvas.clear();
|
||||
canvas.backgroundColor = fabric.Canvas.prototype.backgroundColor;
|
||||
canvas.overlayColor = fabric.Canvas.prototype.overlayColor;
|
||||
canvas._collectObjects = fabric.Canvas.prototype._collectObjects;
|
||||
canvas.off();
|
||||
canvas.calcOffset();
|
||||
upperCanvasEl.style.display = 'none';
|
||||
}
|
||||
});
|
||||
|
||||
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;
|
||||
});
|
||||
|
||||
QUnit.test('mouse:down with different buttons', function(assert) {
|
||||
var clickCount = 0;
|
||||
function mouseHandler() {
|
||||
clickCount++;
|
||||
}
|
||||
canvas.on('mouse:down', mouseHandler);
|
||||
canvas.fireMiddleClick = false;
|
||||
canvas.fireRightClick = false;
|
||||
canvas._currentTransform = false;
|
||||
canvas.isDrawingMode = false;
|
||||
canvas.__onMouseDown({ which: 1 });
|
||||
assert.equal(clickCount, 1, 'mouse down fired');
|
||||
clickCount = 0;
|
||||
canvas.__onMouseDown({ which: 3 });
|
||||
assert.equal(clickCount, 0, 'rightclick did not fire a mouse:down event');
|
||||
canvas.fireRightClick = true;
|
||||
canvas.__onMouseDown({ which: 3 });
|
||||
assert.equal(clickCount, 1, 'rightclick did fire a mouse:down event');
|
||||
clickCount = 0;
|
||||
canvas.__onMouseDown({ which: 2 });
|
||||
assert.equal(clickCount, 0, 'middleClick did not fire a mouse:down event');
|
||||
canvas.fireMiddleClick = true;
|
||||
canvas.__onMouseDown({ which: 2 });
|
||||
assert.equal(clickCount, 1, 'middleClick did fire a mouse:down event');
|
||||
});
|
||||
|
||||
QUnit.test('mouse:down and group selector', function(assert) {
|
||||
var e = { clientX: 30, clientY: 30, which: 1 };
|
||||
var rect = new fabric.Rect({ width: 60, height: 60 });
|
||||
var expectedGroupSelector = { ex: 30, ey: 30, top: 0, left: 0 };
|
||||
canvas.__onMouseDown(e);
|
||||
assert.deepEqual(canvas._groupSelector, expectedGroupSelector, 'a new groupSelector is created');
|
||||
canvas.add(rect);
|
||||
canvas.__onMouseUp(e);
|
||||
canvas.__onMouseDown(e);
|
||||
assert.deepEqual(canvas._groupSelector, null, 'with object on target no groupSelector is started');
|
||||
rect.selectable = false;
|
||||
canvas.__onMouseUp(e);
|
||||
canvas.__onMouseDown(e);
|
||||
assert.deepEqual(canvas._groupSelector, null, 'with object non selectable but already selected groupSelector is not started');
|
||||
canvas.__onMouseUp(e);
|
||||
canvas.discardActiveObject();
|
||||
rect.isEditing = true;
|
||||
canvas.__onMouseDown(e);
|
||||
assert.deepEqual(canvas._groupSelector, null, 'with object editing, groupSelector is not started');
|
||||
canvas.__onMouseUp(e);
|
||||
canvas.discardActiveObject();
|
||||
rect.isEditing = false;
|
||||
canvas.__onMouseDown(e);
|
||||
assert.deepEqual(canvas._groupSelector, expectedGroupSelector, 'a new groupSelector is created');
|
||||
canvas.__onMouseUp(e);
|
||||
});
|
||||
|
||||
QUnit.test('mouse:up isClick = true', function(assert) {
|
||||
var e = { clientX: 30, clientY: 30, which: 1 };
|
||||
var isClick = false;
|
||||
canvas.on('mouse:up', function(opt) {
|
||||
isClick = opt.isClick;
|
||||
});
|
||||
canvas.__onMouseDown(e);
|
||||
canvas.__onMouseUp(e);
|
||||
assert.equal(isClick, true, 'without moving the pointer, the click is true');
|
||||
});
|
||||
|
||||
QUnit.test('setDimensions and active brush', function(assert) {
|
||||
var prepareFor = false;
|
||||
var rendered = false;
|
||||
var canva = new fabric.Canvas(null, { width: 500, height: 500 });
|
||||
var brush = new fabric.PencilBrush({ color: 'red', width: 4 });
|
||||
canva.isDrawingMode = true;
|
||||
canva.freeDrawingBrush = brush;
|
||||
canva._isCurrentlyDrawing = true;
|
||||
brush._render = function() { rendered = true; };
|
||||
brush._setBrushStyles = function() { prepareFor = true; };
|
||||
canva.setDimensions({ width: 200, height: 200 });
|
||||
canva.renderAll();
|
||||
assert.equal(rendered, true, 'the brush called the _render method');
|
||||
assert.equal(prepareFor, true, 'the brush called the _setBrushStyles method');
|
||||
});
|
||||
|
||||
QUnit.test('mouse:up isClick = false', function(assert) {
|
||||
var e = { clientX: 30, clientY: 30, which: 1 };
|
||||
var e2 = { clientX: 31, clientY: 31, which: 1 };
|
||||
var isClick = true;
|
||||
canvas.on('mouse:up', function(opt) {
|
||||
isClick = opt.isClick;
|
||||
});
|
||||
canvas.__onMouseDown(e);
|
||||
canvas.__onMouseMove(e2);
|
||||
canvas.__onMouseUp(e2);
|
||||
assert.equal(isClick, false, 'moving the pointer, the click is false');
|
||||
});
|
||||
|
||||
QUnit.test('avoid multiple bindings', function(assert) {
|
||||
var c = new fabric.Canvas();
|
||||
var eventsArray = [
|
||||
c._onMouseDown,
|
||||
c._onMouseMove,
|
||||
c._onMouseUp,
|
||||
c._onResize,
|
||||
c._onGesture,
|
||||
c._onDrag,
|
||||
c._onShake,
|
||||
c._onLongPress,
|
||||
c._onOrientationChange,
|
||||
c._onMouseWheel,
|
||||
c._onMouseOut,
|
||||
c._onMouseEnter,
|
||||
c._onContextMenu,
|
||||
c._onDragOver,
|
||||
c._onDragEnter,
|
||||
c._onDragLeave,
|
||||
c._onDrop,
|
||||
];
|
||||
// initialize canvas more than once
|
||||
c.initialize();
|
||||
c.initialize();
|
||||
var eventsArray2 = [
|
||||
c._onMouseDown,
|
||||
c._onMouseMove,
|
||||
c._onMouseUp,
|
||||
c._onResize,
|
||||
c._onGesture,
|
||||
c._onDrag,
|
||||
c._onShake,
|
||||
c._onLongPress,
|
||||
c._onOrientationChange,
|
||||
c._onMouseWheel,
|
||||
c._onMouseOut,
|
||||
c._onMouseEnter,
|
||||
c._onContextMenu,
|
||||
c._onDragOver,
|
||||
c._onDragEnter,
|
||||
c._onDragLeave,
|
||||
c._onDrop,
|
||||
];
|
||||
assert.deepEqual(eventsArray, eventsArray2, 'after first initialize, functions do not change.');
|
||||
});
|
||||
|
||||
['DragEnter', 'DragLeave', 'DragOver', 'Drop'].forEach(function(eventType) {
|
||||
QUnit.test('avoid multiple registration - ' + eventType, function(assert) {
|
||||
var funcName = '_on' + eventType;
|
||||
var eventName = eventType.toLowerCase();
|
||||
var counter = 0;
|
||||
var c = new fabric.Canvas();
|
||||
c[funcName] = function() {
|
||||
counter++;
|
||||
};
|
||||
// initialize canvas more than once
|
||||
c.initialize(c.lowerCanvasEl);
|
||||
c.initialize(c.lowerCanvasEl);
|
||||
var event = fabric.document.createEvent('HTMLEvents');
|
||||
event.initEvent(eventName, true, true);
|
||||
c.upperCanvasEl.dispatchEvent(event);
|
||||
assert.equal(counter, 1, eventName + ' listener executed once');
|
||||
});
|
||||
});
|
||||
|
||||
['DragEnter', 'DragLeave', 'DragOver', 'Drop'].forEach(function(eventType) {
|
||||
QUnit.test('Fabric event fired - ' + eventType, function(assert) {
|
||||
var eventName = eventType.toLowerCase();
|
||||
var counter = 0;
|
||||
var c = new fabric.Canvas();
|
||||
c.on(eventName, function() {
|
||||
counter++;
|
||||
});
|
||||
var event = fabric.document.createEvent('HTMLEvents');
|
||||
event.initEvent(eventName, true, true);
|
||||
c.upperCanvasEl.dispatchEvent(event);
|
||||
assert.equal(counter, 1, eventName + ' fabric event fired');
|
||||
});
|
||||
});
|
||||
|
||||
['DragEnter', 'DragLeave', 'DragOver', 'Drop'].forEach(function(eventType) {
|
||||
QUnit.test('_simpleEventHandler fires on object and canvas' + eventType, function(assert) {
|
||||
var eventName = eventType.toLowerCase();
|
||||
var counter = 0;
|
||||
var target;
|
||||
var c = new fabric.Canvas();
|
||||
var rect = new fabric.Rect({ width: 10, height: 10 });
|
||||
c.add(rect);
|
||||
rect.on(eventName, function() {
|
||||
counter++;
|
||||
});
|
||||
c.on(eventName, function(opt) {
|
||||
target = opt.target;
|
||||
});
|
||||
var event = fabric.document.createEvent('HTMLEvents');
|
||||
event.initEvent(eventName, true, true);
|
||||
event.clientX = 5;
|
||||
event.clientY = 5;
|
||||
c.upperCanvasEl.dispatchEvent(event);
|
||||
assert.equal(counter, 1, eventName + ' fabric event fired on rect');
|
||||
assert.equal(target, rect, eventName + ' on canvas has rect as a target');
|
||||
});
|
||||
});
|
||||
|
||||
['mousedown', 'mousemove', 'wheel', 'dblclick'].forEach(function(eventType) {
|
||||
QUnit.test('Fabric event fired - ' + eventType, function(assert) {
|
||||
var eventname = eventType.slice(0, 5) + ':' + eventType.slice(5);
|
||||
if (eventType === 'wheel' || eventType === 'dblclick') {
|
||||
eventname = 'mouse:' + eventType;
|
||||
}
|
||||
var target;
|
||||
if (eventType === 'mouseenter') {
|
||||
eventname = 'mouse:over';
|
||||
}
|
||||
var counter = 0;
|
||||
var c = new fabric.Canvas();
|
||||
var rect = new fabric.Rect({ top: -4, left: -4, width: 12, height: 12 });
|
||||
c.add(rect);
|
||||
c.on(eventname, function(opt) {
|
||||
counter++;
|
||||
target = opt.target;
|
||||
});
|
||||
var event = fabric.document.createEvent('HTMLEvents');
|
||||
event.initEvent(eventType, true, true);
|
||||
event.clientX = 5;
|
||||
event.clientY = 5;
|
||||
c.upperCanvasEl.dispatchEvent(event);
|
||||
assert.equal(counter, 1, eventname + ' fabric event fired');
|
||||
assert.equal(target, rect, eventname + ' on canvas has rect as a target');
|
||||
});
|
||||
});
|
||||
|
||||
['mouseout', 'mouseenter'].forEach(function(eventType) {
|
||||
QUnit.test('Fabric event fired - ' + eventType, function(assert) {
|
||||
var eventname = eventType.slice(0, 5) + ':' + eventType.slice(5);
|
||||
if (eventType === 'mouseenter') {
|
||||
eventname = 'mouse:over';
|
||||
}
|
||||
var counter = 0;
|
||||
var c = new fabric.Canvas();
|
||||
c.on(eventname, function() {
|
||||
counter++;
|
||||
});
|
||||
var event = fabric.document.createEvent('HTMLEvents');
|
||||
event.initEvent(eventType, true, true);
|
||||
c.upperCanvasEl.dispatchEvent(event);
|
||||
assert.equal(counter, 1, eventname + ' fabric event fired');
|
||||
});
|
||||
});
|
||||
|
||||
['MouseDown', 'MouseMove', 'MouseOut', 'MouseEnter', 'MouseWheel', 'DoubleClick'].forEach(function(eventType) {
|
||||
QUnit.test('avoid multiple registration - ' + eventType, function(assert) {
|
||||
var funcName = '_on' + eventType;
|
||||
var eventName = eventType.toLowerCase();
|
||||
if (eventType === 'DoubleClick') {
|
||||
eventName = 'dblclick';
|
||||
}
|
||||
if (eventType === 'MouseWheel') {
|
||||
eventName = 'wheel';
|
||||
}
|
||||
var counter = 0;
|
||||
var c = new fabric.Canvas();
|
||||
c[funcName] = function() {
|
||||
counter++;
|
||||
};
|
||||
// initialize canvas more than once
|
||||
c.initialize(c.lowerCanvasEl);
|
||||
c.initialize(c.lowerCanvasEl);
|
||||
var event = fabric.document.createEvent('MouseEvent');
|
||||
event.initEvent(eventName, true, true);
|
||||
c.upperCanvasEl.dispatchEvent(event);
|
||||
assert.equal(counter, 1, eventName + ' listener executed once');
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.test('avoid multiple registration - mouseup', function(assert) {
|
||||
var done = assert.async();
|
||||
var originalMouseUp = fabric.Canvas.prototype._onMouseUp;
|
||||
var counter = 0;
|
||||
fabric.Canvas.prototype._onMouseUp = function() {
|
||||
counter++;
|
||||
};
|
||||
var c = new fabric.Canvas();
|
||||
// initialize canvas more than once
|
||||
c.initialize(c.lowerCanvasEl);
|
||||
c.initialize(c.lowerCanvasEl);
|
||||
|
||||
// a mouse down is necessary to register mouse up.
|
||||
var _event = fabric.document.createEvent('MouseEvent');
|
||||
_event.initEvent('mousedown', true, true);
|
||||
c.upperCanvasEl.dispatchEvent(_event);
|
||||
setTimeout(function() {
|
||||
var event = fabric.document.createEvent('MouseEvent');
|
||||
event.initEvent('mouseup', true, true);
|
||||
fabric.document.dispatchEvent(event);
|
||||
assert.equal(counter, 1, 'listener executed once');
|
||||
fabric.Canvas.prototype._onMouseUp = originalMouseUp;
|
||||
done();
|
||||
}, 200);
|
||||
});
|
||||
|
||||
QUnit.test('avoid multiple events on window', function(assert) {
|
||||
var originalResize = fabric.Canvas.prototype._onResize;
|
||||
var counter = 0;
|
||||
fabric.Canvas.prototype._onResize = function() {
|
||||
counter++;
|
||||
};
|
||||
var c = new fabric.Canvas();
|
||||
// initialize canvas more than once
|
||||
c.initialize(c.lowerCanvasEl);
|
||||
c.initialize(c.lowerCanvasEl);
|
||||
var event = fabric.document.createEvent('UIEvents');
|
||||
event.initUIEvent('resize', true, false, fabric.window, 0);
|
||||
fabric.window.dispatchEvent(event);
|
||||
assert.equal(counter, 1, 'listener on window executed once');
|
||||
fabric.Canvas.prototype._onResize = originalResize;
|
||||
});
|
||||
|
||||
|
||||
QUnit.test('actionIsDisabled ', function(assert) {
|
||||
assert.ok(typeof fabric.Canvas.prototype.actionIsDisabled === 'function', 'actionIsDisabled is a function');
|
||||
var key = canvas.altActionKey;
|
||||
var target = new fabric.Object();
|
||||
var e = { };
|
||||
e[key] = false;
|
||||
assert.equal(!!canvas.actionIsDisabled('mt', target, e), false, 'action is not disabled');
|
||||
assert.equal(!!canvas.actionIsDisabled('mb', target, e), false, 'action is not disabled');
|
||||
assert.equal(!!canvas.actionIsDisabled('ml', target, e), false, 'action is not disabled');
|
||||
assert.equal(!!canvas.actionIsDisabled('mr', target, e), false, 'action is not disabled');
|
||||
assert.equal(!!canvas.actionIsDisabled('tl', target, e), false, 'action is not disabled');
|
||||
assert.equal(!!canvas.actionIsDisabled('tr', target, e), false, 'action is not disabled');
|
||||
assert.equal(!!canvas.actionIsDisabled('bl', target, e), false, 'action is not disabled');
|
||||
assert.equal(!!canvas.actionIsDisabled('br', target, e), false, 'action is not disabled');
|
||||
assert.equal(!!canvas.actionIsDisabled('mtr', target, e), false, 'action is not disabled');
|
||||
target = new fabric.Object();
|
||||
target.lockScalingX = true;
|
||||
|
||||
assert.equal(!!canvas.actionIsDisabled('mt', target, e), false, 'mt action is not disabled lockScalingX');
|
||||
assert.equal(!!canvas.actionIsDisabled('mb', target, e), false, 'mb action is not disabled lockScalingX');
|
||||
assert.equal(!!canvas.actionIsDisabled('ml', target, e), true, 'ml action is disabled lockScalingX');
|
||||
assert.equal(!!canvas.actionIsDisabled('mr', target, e), true, 'mr action is disabled lockScalingX');
|
||||
assert.equal(!!canvas.actionIsDisabled('tl', target, e), true, 'tl action is disabled lockScalingX');
|
||||
assert.equal(!!canvas.actionIsDisabled('tr', target, e), true, 'tr action is disabled lockScalingX');
|
||||
assert.equal(!!canvas.actionIsDisabled('bl', target, e), true, 'bl action is disabled lockScalingX');
|
||||
assert.equal(!!canvas.actionIsDisabled('br', target, e), true, 'br action is disabled lockScalingX');
|
||||
assert.equal(!!canvas.actionIsDisabled('mtr', target, e), false, 'mtr action is not disabled lockScalingX');
|
||||
target = new fabric.Object();
|
||||
target.lockScalingY = true;
|
||||
assert.equal(!!canvas.actionIsDisabled('mt', target, e), true, 'mt action is disabled lockScalingY');
|
||||
assert.equal(!!canvas.actionIsDisabled('mb', target, e), true, 'mb action is disabled lockScalingY');
|
||||
assert.equal(!!canvas.actionIsDisabled('ml', target, e), false, 'ml action is not disabled lockScalingY');
|
||||
assert.equal(!!canvas.actionIsDisabled('mr', target, e), false, 'mr action is not disabled lockScalingY');
|
||||
assert.equal(!!canvas.actionIsDisabled('tl', target, e), true, 'tl action is not disabled lockScalingY');
|
||||
assert.equal(!!canvas.actionIsDisabled('tr', target, e), true, 'tr action is not disabled lockScalingY');
|
||||
assert.equal(!!canvas.actionIsDisabled('bl', target, e), true, 'bl action is not disabled lockScalingY');
|
||||
assert.equal(!!canvas.actionIsDisabled('br', target, e), true, 'br action is not disabled lockScalingY');
|
||||
assert.equal(!!canvas.actionIsDisabled('mtr', target, e), false, 'mtr action is not disabledlockScalingY');
|
||||
target = new fabric.Object();
|
||||
target.lockScalingY = true;
|
||||
target.lockScalingX = true;
|
||||
assert.equal(!!canvas.actionIsDisabled('mt', target, e), true, 'mt action is disabled scaling locked');
|
||||
assert.equal(!!canvas.actionIsDisabled('mb', target, e), true, 'mb action is disabled scaling locked');
|
||||
assert.equal(!!canvas.actionIsDisabled('ml', target, e), true, 'ml action is disabled scaling locked');
|
||||
assert.equal(!!canvas.actionIsDisabled('mr', target, e), true, 'mr action is disabled scaling locked');
|
||||
assert.equal(!!canvas.actionIsDisabled('tl', target, e), true, 'tl action is disabled scaling locked');
|
||||
assert.equal(!!canvas.actionIsDisabled('tr', target, e), true, 'tr action is disabled scaling locked');
|
||||
assert.equal(!!canvas.actionIsDisabled('bl', target, e), true, 'bl action is disabled scaling locked');
|
||||
assert.equal(!!canvas.actionIsDisabled('br', target, e), true, 'br action is disabled scaling locked');
|
||||
assert.equal(!!canvas.actionIsDisabled('mtr', target, e), false, 'mtr action is not disabled scaling locked');
|
||||
target = new fabric.Object();
|
||||
target.lockRotation = true;
|
||||
assert.equal(!!canvas.actionIsDisabled('mt', target, e), false, 'mt action is not disabled lockRotation');
|
||||
assert.equal(!!canvas.actionIsDisabled('mb', target, e), false, 'mb action is not disabled lockRotation');
|
||||
assert.equal(!!canvas.actionIsDisabled('ml', target, e), false, 'ml action is not disabled lockRotation');
|
||||
assert.equal(!!canvas.actionIsDisabled('mr', target, e), false, 'mr action is not disabled lockRotation');
|
||||
assert.equal(!!canvas.actionIsDisabled('tl', target, e), false, 'tl action is not disabled lockRotation');
|
||||
assert.equal(!!canvas.actionIsDisabled('tr', target, e), false, 'tr action is not disabled lockRotation');
|
||||
assert.equal(!!canvas.actionIsDisabled('bl', target, e), false, 'bl action is not disabled lockRotation');
|
||||
assert.equal(!!canvas.actionIsDisabled('br', target, e), false, 'br action is not disabled lockRotation');
|
||||
assert.equal(!!canvas.actionIsDisabled('mtr', target, e), true, 'mtr action is disabled lockRotation');
|
||||
target = new fabric.Object();
|
||||
target.lockSkewingX = true;
|
||||
target.lockSkewingY = true;
|
||||
assert.equal(!!canvas.actionIsDisabled('mt', target, e), false, 'mt action is not disabled lockSkewing');
|
||||
assert.equal(!!canvas.actionIsDisabled('mb', target, e), false, 'mb action is not disabled lockSkewing');
|
||||
assert.equal(!!canvas.actionIsDisabled('ml', target, e), false, 'ml action is not disabled lockSkewing');
|
||||
assert.equal(!!canvas.actionIsDisabled('mr', target, e), false, 'mr action is not disabled lockSkewing');
|
||||
assert.equal(!!canvas.actionIsDisabled('tl', target, e), false, 'tl action is not disabled lockSkewing');
|
||||
assert.equal(!!canvas.actionIsDisabled('tr', target, e), false, 'tr action is not disabled lockSkewing');
|
||||
assert.equal(!!canvas.actionIsDisabled('bl', target, e), false, 'bl action is not disabled lockSkewing');
|
||||
assert.equal(!!canvas.actionIsDisabled('br', target, e), false, 'br action is not disabled lockSkewing');
|
||||
assert.equal(!!canvas.actionIsDisabled('mtr', target, e), false, 'mtr action is not disabled lockSkewing');
|
||||
e[key] = true;
|
||||
target = new fabric.Object();
|
||||
target.lockSkewingY = true;
|
||||
assert.equal(!!canvas.actionIsDisabled('mt', target, e), false, 'mt action is not disabled lockSkewingY');
|
||||
assert.equal(!!canvas.actionIsDisabled('mb', target, e), false, 'mb action is not disabled lockSkewingY');
|
||||
assert.equal(!!canvas.actionIsDisabled('ml', target, e), true, 'ml action is disabled lockSkewingY');
|
||||
assert.equal(!!canvas.actionIsDisabled('mr', target, e), true, 'mr action is disabled lockSkewingY');
|
||||
assert.equal(!!canvas.actionIsDisabled('tl', target, e), false, 'tl action is not disabled lockSkewingY');
|
||||
assert.equal(!!canvas.actionIsDisabled('tr', target, e), false, 'tr action is not disabled lockSkewingY');
|
||||
assert.equal(!!canvas.actionIsDisabled('bl', target, e), false, 'bl action is not disabled lockSkewingY');
|
||||
assert.equal(!!canvas.actionIsDisabled('br', target, e), false, 'br action is not disabled lockSkewingY');
|
||||
assert.equal(!!canvas.actionIsDisabled('mtr', target, e), false, 'mtr action is not disabled lockSkewingY');
|
||||
|
||||
e[key] = true;
|
||||
target = new fabric.Object();
|
||||
target.lockSkewingX = true;
|
||||
assert.equal(!!canvas.actionIsDisabled('mt', target, e), true, 'mt action is disabled lockSkewingX');
|
||||
assert.equal(!!canvas.actionIsDisabled('mb', target, e), true, 'mb action is disabled lockSkewingX');
|
||||
assert.equal(!!canvas.actionIsDisabled('ml', target, e), false, 'ml action is not disabled lockSkewingX');
|
||||
assert.equal(!!canvas.actionIsDisabled('mr', target, e), false, 'mr action is not disabled lockSkewingX');
|
||||
assert.equal(!!canvas.actionIsDisabled('tl', target, e), false, 'tl action is not disabled lockSkewingX');
|
||||
assert.equal(!!canvas.actionIsDisabled('tr', target, e), false, 'tr action is not disabled lockSkewingX');
|
||||
assert.equal(!!canvas.actionIsDisabled('bl', target, e), false, 'bl action is not disabled lockSkewingX');
|
||||
assert.equal(!!canvas.actionIsDisabled('br', target, e), false, 'br action is not disabled lockSkewingX');
|
||||
assert.equal(!!canvas.actionIsDisabled('mtr', target, e), false, 'mtr action is not disabled lockSkewingX');
|
||||
});
|
||||
|
||||
QUnit.test('getCornerCursor ', function(assert) {
|
||||
assert.ok(typeof fabric.Canvas.prototype.getCornerCursor === 'function', 'actionIsDisabled is a function');
|
||||
var key = canvas.altActionKey;
|
||||
var key2 = canvas.uniScaleKey;
|
||||
var target = new fabric.Object();
|
||||
var e = { };
|
||||
e[key] = false;
|
||||
assert.equal(canvas.getCornerCursor('mt', target, e), 'n-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('mb', target, e), 's-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('ml', target, e), 'w-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('mr', target, e), 'e-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('tl', target, e), 'nw-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('tr', target, e), 'ne-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('bl', target, e), 'sw-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('br', target, e), 'se-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('mtr', target, e), 'crosshair', 'action is not disabled');
|
||||
|
||||
target = new fabric.Object();
|
||||
target.hasRotatingPoint = false;
|
||||
var e = { };
|
||||
e[key] = false;
|
||||
assert.equal(canvas.getCornerCursor('mtr', target, e), 'default', 'action is not disabled');
|
||||
|
||||
target = new fabric.Object();
|
||||
target.lockScalingX = true;
|
||||
assert.equal(canvas.getCornerCursor('mt', target, e), 'n-resize', 'action is not disabled lockScalingX');
|
||||
assert.equal(canvas.getCornerCursor('mb', target, e), 's-resize', 'action is not disabled lockScalingX');
|
||||
assert.equal(canvas.getCornerCursor('ml', target, e), 'not-allowed', 'action is disabled lockScalingX');
|
||||
assert.equal(canvas.getCornerCursor('mr', target, e), 'not-allowed', 'action is disabled lockScalingX');
|
||||
assert.equal(canvas.getCornerCursor('tl', target, e), 'not-allowed', 'action is disabled lockScalingX');
|
||||
assert.equal(canvas.getCornerCursor('tr', target, e), 'not-allowed', 'action is disabled lockScalingX');
|
||||
assert.equal(canvas.getCornerCursor('bl', target, e), 'not-allowed', 'action is disabled lockScalingX');
|
||||
assert.equal(canvas.getCornerCursor('br', target, e), 'not-allowed', 'action is disabled lockScalingX');
|
||||
assert.equal(canvas.getCornerCursor('mtr', target, e), 'crosshair', 'action is not disabled lockScalingX');
|
||||
e[key2] = true;
|
||||
assert.equal(canvas.getCornerCursor('tl', target, e), 'nw-resize', 'action is not disabled lockScalingX key2');
|
||||
assert.equal(canvas.getCornerCursor('tr', target, e), 'ne-resize', 'action is not disabled lockScalingX key2');
|
||||
assert.equal(canvas.getCornerCursor('bl', target, e), 'sw-resize', 'action is not disabled lockScalingX key2');
|
||||
assert.equal(canvas.getCornerCursor('br', target, e), 'se-resize', 'action is not disabled lockScalingX key2');
|
||||
|
||||
var e = { };
|
||||
target = new fabric.Object();
|
||||
target.lockScalingY = true;
|
||||
assert.equal(canvas.getCornerCursor('mt', target, e), 'not-allowed', 'action is disabled lockScalingY');
|
||||
assert.equal(canvas.getCornerCursor('mb', target, e), 'not-allowed', 'action is disabled lockScalingY');
|
||||
assert.equal(canvas.getCornerCursor('ml', target, e), 'w-resize', 'action is not disabled lockScalingY');
|
||||
assert.equal(canvas.getCornerCursor('mr', target, e), 'e-resize', 'action is not disabled lockScalingY');
|
||||
assert.equal(canvas.getCornerCursor('tl', target, e), 'not-allowed', 'action is disabled lockScalingY');
|
||||
assert.equal(canvas.getCornerCursor('tr', target, e), 'not-allowed', 'action is disabled lockScalingY');
|
||||
assert.equal(canvas.getCornerCursor('bl', target, e), 'not-allowed', 'action is disabled lockScalingY');
|
||||
assert.equal(canvas.getCornerCursor('br', target, e), 'not-allowed', 'action is disabled lockScalingY');
|
||||
assert.equal(canvas.getCornerCursor('mtr', target, e), 'crosshair', 'action is not disabled lockScalingY');
|
||||
e[key2] = true;
|
||||
assert.equal(canvas.getCornerCursor('tl', target, e), 'nw-resize', 'action is not disabled lockScalingY key2');
|
||||
assert.equal(canvas.getCornerCursor('tr', target, e), 'ne-resize', 'action is not disabled lockScalingY key2');
|
||||
assert.equal(canvas.getCornerCursor('bl', target, e), 'sw-resize', 'action is not disabled lockScalingY key2');
|
||||
assert.equal(canvas.getCornerCursor('br', target, e), 'se-resize', 'action is not disabled lockScalingY key2');
|
||||
|
||||
var e = { };
|
||||
target = new fabric.Object();
|
||||
target.lockScalingY = true;
|
||||
target.lockScalingX = true;
|
||||
assert.equal(canvas.getCornerCursor('mt', target, e), 'not-allowed', 'action is disabled lockScaling');
|
||||
assert.equal(canvas.getCornerCursor('mb', target, e), 'not-allowed', 'action is disabled lockScaling');
|
||||
assert.equal(canvas.getCornerCursor('ml', target, e), 'not-allowed', 'action is disabled lockScaling');
|
||||
assert.equal(canvas.getCornerCursor('mr', target, e), 'not-allowed', 'action is disabled lockScaling');
|
||||
assert.equal(canvas.getCornerCursor('tl', target, e), 'not-allowed', 'action is disabled lockScaling');
|
||||
assert.equal(canvas.getCornerCursor('tr', target, e), 'not-allowed', 'action is disabled lockScaling');
|
||||
assert.equal(canvas.getCornerCursor('bl', target, e), 'not-allowed', 'action is disabled lockScaling');
|
||||
assert.equal(canvas.getCornerCursor('br', target, e), 'not-allowed', 'action is disabled lockScaling');
|
||||
assert.equal(canvas.getCornerCursor('mtr', target, e), 'crosshair', 'action is not disabled lockScaling');
|
||||
e[key2] = true;
|
||||
assert.equal(canvas.getCornerCursor('tl', target, e), 'not-allowed', 'action is disabled lockScaling key2');
|
||||
assert.equal(canvas.getCornerCursor('tr', target, e), 'not-allowed', 'action is disabled lockScaling key2');
|
||||
assert.equal(canvas.getCornerCursor('bl', target, e), 'not-allowed', 'action is disabled lockScaling key2');
|
||||
assert.equal(canvas.getCornerCursor('br', target, e), 'not-allowed', 'action is disabled lockScaling key2');
|
||||
|
||||
var e = { };
|
||||
target = new fabric.Object();
|
||||
target.lockRotation = true;
|
||||
assert.equal(canvas.getCornerCursor('mt', target, e), 'n-resize', 'action is not disabled lockRotation');
|
||||
assert.equal(canvas.getCornerCursor('mb', target, e), 's-resize', 'action is not disabled lockRotation');
|
||||
assert.equal(canvas.getCornerCursor('ml', target, e), 'w-resize', 'action is not disabled lockRotation');
|
||||
assert.equal(canvas.getCornerCursor('mr', target, e), 'e-resize', 'action is not disabled lockRotation');
|
||||
assert.equal(canvas.getCornerCursor('tl', target, e), 'nw-resize', 'action is not disabled lockRotation');
|
||||
assert.equal(canvas.getCornerCursor('tr', target, e), 'ne-resize', 'action is not disabled lockRotation');
|
||||
assert.equal(canvas.getCornerCursor('bl', target, e), 'sw-resize', 'action is not disabled lockRotation');
|
||||
assert.equal(canvas.getCornerCursor('br', target, e), 'se-resize', 'action is not disabled lockRotation');
|
||||
assert.equal(canvas.getCornerCursor('mtr', target, e), 'not-allowed', 'action is disabled lockRotation');
|
||||
|
||||
target = new fabric.Object();
|
||||
target.lockSkewingX = true;
|
||||
target.lockSkewingY = true;
|
||||
assert.equal(canvas.getCornerCursor('mt', target, e), 'n-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('mb', target, e), 's-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('ml', target, e), 'w-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('mr', target, e), 'e-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('tl', target, e), 'nw-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('tr', target, e), 'ne-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('bl', target, e), 'sw-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('br', target, e), 'se-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('mtr', target, e), 'crosshair', 'action is not disabled');
|
||||
|
||||
e[key] = true;
|
||||
target = new fabric.Object();
|
||||
target.lockSkewingY = true;
|
||||
assert.equal(canvas.getCornerCursor('mt', target, e), 'e-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('mb', target, e), 'w-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('ml', target, e), 'not-allowed', 'action is disabled');
|
||||
assert.equal(canvas.getCornerCursor('mr', target, e), 'not-allowed', 'action is disabled');
|
||||
assert.equal(canvas.getCornerCursor('tl', target, e), 'nw-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('tr', target, e), 'ne-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('bl', target, e), 'sw-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('br', target, e), 'se-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('mtr', target, e), 'crosshair', 'action is not disabled');
|
||||
|
||||
e[key] = true;
|
||||
target = new fabric.Object();
|
||||
target.lockSkewingX = true;
|
||||
assert.equal(canvas.getCornerCursor('mt', target, e), 'not-allowed', 'action is disabled');
|
||||
assert.equal(canvas.getCornerCursor('mb', target, e), 'not-allowed', 'action is disabled');
|
||||
assert.equal(canvas.getCornerCursor('ml', target, e), 'n-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('mr', target, e), 's-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('tl', target, e), 'nw-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('tr', target, e), 'ne-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('bl', target, e), 'sw-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('br', target, e), 'se-resize', 'action is not disabled');
|
||||
assert.equal(canvas.getCornerCursor('mtr', target, e), 'crosshair', 'action is not disabled');
|
||||
});
|
||||
|
||||
})();
|
||||
Loading…
Reference in a new issue