Skip to content

Commit

Permalink
Remove active property from objects (#4200)
Browse files Browse the repository at this point in the history
* removed active
* removed active property
* removed active property
  • Loading branch information
asturur authored Aug 14, 2017
1 parent b114d8d commit 6b4d215
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 26 deletions.
13 changes: 5 additions & 8 deletions src/canvas.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(
Expand Down Expand Up @@ -1454,7 +1453,6 @@
return false;
}
this._activeObject = object;
object.set('active', true);
return true;
},

Expand All @@ -1468,7 +1466,6 @@
if (obj.onDeselect({ e: e, object: object })) {
return false;
}
obj.set('active', false);
this._activeObject = null;
}
return true;
Expand Down
3 changes: 0 additions & 3 deletions src/mixins/animation.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 5 additions & 3 deletions src/mixins/object_interactivity.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();
Expand Down
3 changes: 0 additions & 3 deletions src/mixins/object_straightening.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/shapes/itext.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions src/shapes/object.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions test/unit/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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');
Expand Down
6 changes: 4 additions & 2 deletions test/unit/object_interactivity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 6b4d215

Please sign in to comment.