dnd: when snapping back, deal with moved/rescaled parents

Previously, when snapping back a drag actor, we moved it back to its
original stage-relative position and scale. This worked fine if its
parent was still in the same place it was when the drag started, but
failed in cases like the linear workspace layout window drag-and-drop,
where dragging a window would "zoom out" its parent workspace, causing
the snapback to send it to the wrong place.

Fix this by instead snapping the actor back to "where the actor would
have been right now if it were still at its original scale and
position within its original parent actor" rather than "where it was
before the drag started"

https://bugzilla.gnome.org/show_bug.cgi?id=635272
This commit is contained in:
Dan Winship 2010-11-19 10:18:14 -05:00
parent bfc850a94d
commit b956c6f093

View File

@ -440,21 +440,39 @@ _Draggable.prototype = {
return true; return true;
}, },
// Get position of the drag actor's source if the source is still around,
// or return the original location if the actor itself was being dragged
// or the source is no longer around.
_getRestoreLocation: function() { _getRestoreLocation: function() {
let locX = this._snapBackX; let x, y, scale;
let locY = this._snapBackY;
if (this._dragActorSource && this._dragActorSource.visible) if (this._dragActorSource && this._dragActorSource.visible) {
[locX, locY] = this._dragActorSource.get_transformed_position(); // Snap the clone back to its source
return [locX, locY]; [x, y] = this._dragActorSource.get_transformed_position();
let [sourceScaledWidth, sourceScaledHeight] = this._dragActorSource.get_transformed_size();
scale = this._dragActor.width / sourceScaledWidth;
} else if (this._dragOrigParent) {
// Snap the actor back to its original position within
// its parent, adjusting for the fact that the parent
// may have been moved or scaled
let [parentX, parentY] = this._dragOrigParent.get_transformed_position();
x = parentX + this._dragOrigParent.scale_x * this._dragOrigX;
y = parentY + this._dragOrigParent.scale_y * this._dragOrigY;
let [parentWidth, parentHeight] = this._dragOrigParent.get_size();
let [parentScaledWidth, parentScaledHeight] = this._dragOrigParent.get_transformed_size();
let parentScale = parentScaledWidth / parentWidth;
scale = this._dragOrigScale * parentScale;
} else {
// Snap back actor to its original stage position
x = this._snapBackX;
y = this._snapBackY;
scale = this._snapBackScale;
}
return [x, y, scale];
}, },
_cancelDrag: function(eventTime) { _cancelDrag: function(eventTime) {
this._dragInProgress = false; this._dragInProgress = false;
let [snapBackX, snapBackY] = this._getRestoreLocation(); let [snapBackX, snapBackY, snapBackScale] = this._getRestoreLocation();
if (this._actorDestroyed) { if (this._actorDestroyed) {
global.unset_cursor(); global.unset_cursor();
@ -467,8 +485,8 @@ _Draggable.prototype = {
Tweener.addTween(this._dragActor, Tweener.addTween(this._dragActor,
{ x: snapBackX, { x: snapBackX,
y: snapBackY, y: snapBackY,
scale_x: this._snapBackScale, scale_x: snapBackScale,
scale_y: this._snapBackScale, scale_y: snapBackScale,
opacity: this._dragOrigOpacity, opacity: this._dragOrigOpacity,
time: SNAP_BACK_ANIMATION_TIME, time: SNAP_BACK_ANIMATION_TIME,
transition: 'easeOutQuad', transition: 'easeOutQuad',
@ -480,11 +498,11 @@ _Draggable.prototype = {
_restoreDragActor: function(eventTime) { _restoreDragActor: function(eventTime) {
this._dragInProgress = false; this._dragInProgress = false;
[restoreX, restoreY] = this._getRestoreLocation(); [restoreX, restoreY, restoreScale] = this._getRestoreLocation();
// fade the actor back in at its original location // fade the actor back in at its original location
this._dragActor.set_position(restoreX, restoreY); this._dragActor.set_position(restoreX, restoreY);
this._dragActor.set_scale(this._snapBackScale, this._snapBackScale); this._dragActor.set_scale(restoreScale, restoreScale);
this._dragActor.opacity = 0; this._dragActor.opacity = 0;
this._animationInProgress = true; this._animationInProgress = true;