Remove active property from objects (#4200)

* removed active
* removed active property
* removed active property
This commit is contained in:
Andrea Bogazzi 2017-08-14 15:12:58 +02:00 committed by GitHub
parent b114d8d0ee
commit 6b4d215162
8 changed files with 19 additions and 26 deletions

View file

@ -477,9 +477,7 @@
* @return {Boolean}
*/
isTargetTransparent: function (target, x, y) {
var hasBorders = target.hasBorders,
transparentCorners = target.transparentCorners,
ctx = this.contextCache,
var ctx = this.contextCache,
originalColor = target.selectionBackgroundColor;
target.hasBorders = target.transparentCorners = false;
@ -490,10 +488,11 @@
target.render(ctx);
ctx.restore();
target.active && target._renderControls(ctx);
target === this._activeObject && target._renderControls(ctx, {
hasBorders: false,
transparentCorners: false
});
target.hasBorders = hasBorders;
target.transparentCorners = transparentCorners;
target.selectionBackgroundColor = originalColor;
var isTransparent = fabric.util.isTransparent(
@ -1454,7 +1453,6 @@
return false;
}
this._activeObject = object;
object.set('active', true);
return true;
},
@ -1468,7 +1466,6 @@
if (obj.onDeselect({ e: e, object: object })) {
return false;
}
obj.set('active', false);
this._activeObject = null;
}
return true;

View file

@ -98,9 +98,6 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
startValue: object.opacity,
endValue: 0,
duration: this.FX_DURATION,
onStart: function() {
object.set('active', false);
},
onChange: function(value) {
object.set('opacity', value);
_this.requestRenderAll();

View file

@ -19,7 +19,7 @@
_findTargetCorner: function(pointer) {
// objects in group, anykind, are not self modificable,
// must not return an hovered corner.
if (!this.hasControls || !this.active || this.group) {
if (!this.hasControls || this.group || (!this.canvas || this.canvas._activeObject !== this)) {
return false;
}
@ -117,8 +117,10 @@
* @chainable
*/
drawSelectionBackground: function(ctx) {
if (!this.selectionBackgroundColor || !this.active ||
(this.canvas && !this.canvas.interactive)) {
if (!this.selectionBackgroundColor ||
(this.canvas && !this.canvas.interactive) ||
(this.canvas && this.canvas._activeObject !== this)
) {
return this;
}
ctx.save();

View file

@ -50,9 +50,6 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
_this.setCoords();
onComplete();
},
onStart: function() {
_this.set('active', false);
}
});
return this;

View file

@ -306,7 +306,7 @@
* Prepare and clean the contextTop
*/
clearContextTop: function(skipRestore) {
if (!this.active || !this.isEditing) {
if (!this.isEditing) {
return;
}
if (this.canvas && this.canvas.contextTop) {
@ -324,7 +324,7 @@
* Renders cursor or selection (depending on what exists)
*/
renderCursorOrSelection: function() {
if (!this.active || !this.isEditing) {
if (!this.isEditing) {
return;
}
var boundaries = this._getCursorBoundaries(), ctx;

View file

@ -1385,12 +1385,10 @@
}
var origParams = {
active: this.active,
left: this.left,
top: this.top
};
this.set('active', false);
this.setPositionByOrigin(new fabric.Point(canvas.width / 2, canvas.height / 2), 'center', 'center');
var originalCanvas = this.canvas;

View file

@ -1239,10 +1239,10 @@
canvas.add(rect1, rect2);
canvas.setActiveObject(rect1);
ok(rect1.active);
ok(rect1 === canvas._activeObject);
canvas.setActiveObject(rect2);
ok(rect2.active);
ok(rect2 === canvas._activeObject);
});
test('getActiveObject', function() {
@ -1610,7 +1610,7 @@
clientY: canvasOffset.top + 100,
target: rect
};
rect.active = true;
canvas.setActiveObject(rect)
canvas._setupCurrentTransform(eventStub, rect);
var t = canvas._currentTransform;
equal(t.target, rect, 'should have rect as a target');

View file

@ -86,7 +86,7 @@
test('_setCornerCoords', function(){
var cObj = new fabric.Object({ top: 10, left: 10, width: 10, height: 10, strokeWidth: 0 });
ok(typeof cObj._setCornerCoords == 'function', '_setCornerCoords should exist');
ok(typeof cObj._setCornerCoords === 'function', '_setCornerCoords should exist');
cObj.setCoords();
equal(cObj.oCoords.tl.corner.tl.x.toFixed(2), 3.5);
@ -136,7 +136,9 @@
var cObj = new fabric.Object({ top: 10, left: 10, width: 30, height: 30, strokeWidth: 0 });
ok(typeof cObj._findTargetCorner == 'function', '_findTargetCorner should exist');
cObj.setCoords();
cObj.active = true;
cObj.canvas = {
_activeObject: cObj
};
equal(cObj._findTargetCorner(cObj.oCoords.br), 'br');
equal(cObj._findTargetCorner(cObj.oCoords.tl), 'tl');
equal(cObj._findTargetCorner(cObj.oCoords.tr), 'tr');