dnd: Centralize drag actor positioning code, use shellWorkspaceLaunch for workspaces

We had multiple copies of the code to position a drag actor given a particular
source.  Instead, just put it inside dnd.js.

Second, rather than test for GenericDisplay/WellDisplayItem etc.,
in various places, add a new method on each source "shellWorkspaceLaunch"
which both marks the item as being droppable on a workspace, and is
called by the workspaces code to launch the item.
This commit is contained in:
Colin Walters
2009-08-17 20:29:54 -04:00
parent 9563515e97
commit dd1a309cb6
5 changed files with 33 additions and 37 deletions

View File

@ -82,10 +82,21 @@ _Draggable.prototype = {
// Drag actor does not always have to be the same as actor. For example drag actor
// can be an image that's part of the actor. So to perform "snap back" correctly we need
// to know what was the drag actor source.
if (this.actor._delegate.getDragActorSource)
if (this.actor._delegate.getDragActorSource) {
this._dragActorSource = this.actor._delegate.getDragActorSource();
else
// If the user dragged from the source, then position
// the dragActor over it. Otherwise, center it
// around the pointer
let [sourceX, sourceY] = this._dragActorSource.get_transformed_position();
let [sourceWidth, sourceHeight] = this._dragActorSource.get_transformed_size();
if (stageX > sourceX && stageX <= sourceX + sourceWidth &&
stageY > sourceY && stageY <= sourceY + sourceHeight)
this._dragActor.set_position(sourceX, sourceY);
else
this._dragActor.set_position(stageX - this._dragActor.width / 2, stageY - this._dragActor.height / 2);
} else {
this._dragActorSource = this.actor;
}
this._dragOrigParent = undefined;
this._ungrabActor(actor);
this._grabActor(this._dragActor);