dnd: Cancel the animation on drag actor destruction

If the drag actor is destroyed before the animation
callback is called, the callback is never called and
we're sticked with dnd grabing the events after we
dropped the target.

https://bugzilla.gnome.org/show_bug.cgi?id=757676
This commit is contained in:
Marek Chalupa 2016-03-31 14:26:06 +02:00 committed by Florian Müllner
parent 3274f270e3
commit 1883df2927

View File

@ -571,20 +571,13 @@ const _Draggable = new Lang.Class({
return; return;
} }
this._animationInProgress = true; this._animateDragEnd(eventTime,
// No target, so snap back { x: snapBackX,
Tweener.addTween(this._dragActor, y: snapBackY,
{ x: snapBackX, scale_x: snapBackScale,
y: snapBackY, scale_y: snapBackScale,
scale_x: snapBackScale, time: SNAP_BACK_ANIMATION_TIME,
scale_y: snapBackScale, });
opacity: this._dragOrigOpacity,
time: SNAP_BACK_ANIMATION_TIME,
transition: 'easeOutQuad',
onComplete: this._onAnimationComplete,
onCompleteScope: this,
onCompleteParams: [this._dragActor, eventTime]
});
}, },
_restoreDragActor: function(eventTime) { _restoreDragActor: function(eventTime) {
@ -596,18 +589,44 @@ const _Draggable = new Lang.Class({
this._dragActor.set_scale(restoreScale, restoreScale); this._dragActor.set_scale(restoreScale, restoreScale);
this._dragActor.opacity = 0; this._dragActor.opacity = 0;
this._animateDragEnd(eventTime,
{ time: REVERT_ANIMATION_TIME });
},
_animateDragEnd: function (eventTime, params) {
this._animationInProgress = true; this._animationInProgress = true;
Tweener.addTween(this._dragActor,
{ opacity: this._dragOrigOpacity, // finish animation if the actor gets destroyed
time: REVERT_ANIMATION_TIME, // during it
transition: 'easeOutQuad', this._dragActorDestroyId =
onComplete: this._onAnimationComplete, this._dragActor.connect('destroy',
onCompleteScope: this, Lang.bind(this, this._finishAnimation));
onCompleteParams: [this._dragActor, eventTime]
}); params['opacity'] = this._dragOrigOpacity;
params['transition'] = 'easeOutQuad';
params['onComplete'] = this._onAnimationComplete;
params['onCompleteScope'] = this;
params['onCompleteParams'] = [this._dragActor, eventTime];
// start the animation
Tweener.addTween(this._dragActor, params)
},
_finishAnimation : function () {
if (!this._animationInProgress)
return
this._animationInProgress = false;
if (!this._buttonDown)
this._dragComplete();
global.screen.set_cursor(Meta.Cursor.DEFAULT);
}, },
_onAnimationComplete : function (dragActor, eventTime) { _onAnimationComplete : function (dragActor, eventTime) {
dragActor.disconnect(this._dragActorDestroyId);
this._dragActorDestroyId = 0;
if (this._dragOrigParent) { if (this._dragOrigParent) {
Main.uiGroup.remove_child(this._dragActor); Main.uiGroup.remove_child(this._dragActor);
this._dragOrigParent.add_actor(this._dragActor); this._dragOrigParent.add_actor(this._dragActor);
@ -616,12 +635,9 @@ const _Draggable = new Lang.Class({
} else { } else {
dragActor.destroy(); dragActor.destroy();
} }
global.screen.set_cursor(Meta.Cursor.DEFAULT);
this.emit('drag-end', eventTime, false);
this._animationInProgress = false; this.emit('drag-end', eventTime, false);
if (!this._buttonDown) this._finishAnimation();
this._dragComplete();
}, },
_dragComplete: function() { _dragComplete: function() {