nsIDragService

Implements the Drag Service for handling drag and drop operations.
Inherits from: nsISupports Last changed in Gecko 43 (Firefox 43 / Thunderbird 43 / SeaMonkey 2.40)

Note: Using this interface directly from add-on code is deprecated. Add-ons should use the standard dataTransfer drag and drop API instead. The only exception is getCurrentSession(), since there's currently no way to check for a drag in progress using standard DOM methods or properties.

Method overview

void endDragSession( in PRBool aDoneDrag ) ;
void dragMoved(in long aX, in long aY); Native code only!
void fireDragEventAtSource(in unsigned long aMsg); Obsolete since Gecko 43
void fireDragEventAtSource(in mozilla::EventMessage aEventMessage); Requires Gecko 43 Native code only!
nsIDragSession getCurrentSession( ) ;
void invokeDragSession( in nsIDOMNode aDOMNode, in nsISupportsArray aTransferables, in nsIScriptableRegion aRegion, in unsigned long aActionType );
void invokeDragSessionWithImage(in nsIDOMNode aDOMNode, in nsISupportsArray aTransferableArray, in nsIScriptableRegion aRegion, in unsigned long aActionType, in nsIDOMNode aImage, in long aImageX, in long aImageY, in nsIDOMDragEvent aDragEvent, in nsIDOMDataTransfer aDataTransfer);
void invokeDragSessionWithSelection(in nsISelection aSelection, in nsISupportsArray aTransferableArray, in unsigned long aActionType, in nsIDOMDragEvent aDragEvent, in nsIDOMDataTransfer aDataTransfer);
void startDragSession( ) ;
void suppress();
void unsuppress();

Constants

Constant Value Description
DRAGDROP_ACTION_NONE 0 No action.
DRAGDROP_ACTION_COPY 1 The drag and drop operation should copy the object.
DRAGDROP_ACTION_MOVE 2 The drag and drop operation should move the object.
DRAGDROP_ACTION_LINK 4 The drag and drop operation should link the object.
DRAGDROP_ACTION_UNINITIALIZED 64 The action is not initialized.

Methods

Native code only!

dragMoved

Programmatically changes the drag position of the drag session. This is used on Mac and Windows to update the position of a popup being used as a drag image during the drag operation. It's not used on GTK, which handles the drag popup itself.

[noscript] void dragMoved(
  in long aX,
  in long aY
);
Parameters
aX
The X coordinate to which to move the popup being dragged.
aY
The Y coordinate to which to move the popup being dragged.

endDragSession()

Tells the Drag Service to end a drag session. This is called when an external drag occurs.

void endDragSession(
  in PRBool aDoneDrag  
);
Parameters
aDoneDrag
If aDoneDrag is true, the drag has finished, otherwise the drag has just left the window.

fireDragEventAtSource()

Obsolete since Gecko 43 (Firefox 43 / Thunderbird 43 / SeaMonkey 2.40)
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

Fire a drag event at the source of the drag. This was changed in Gecko 43, see the following section.

void fireDragEventAtSource(
  in unsigned long aMsg 
); Obsolete since Gecko 43
Parameters
aMsg
One of the NS_DRAGDROP_* contants which was defined in widget/BasicEvents.h

Fire a drag event at the fource of the drag. This is available only from native code since Gecko 43.

[noscript] void fireDragEventAtSource(
  in mozilla::EventMessage aEventMessage
);
Parameters
aEventMessage
One of the event messages between eDragDropEventFirst and eDragDropEventLast defined in widget/EventMessageList.h

getCurrentSession()

Returns the current nsIDragSession.

nsIDragSession getCurrentSession();
Parameters

None.

Return value

The current drag session, or null if no drag is in progress.

invokeDragSession()

Starts a modal drag session with an array of transferables

void invokeDragSession(
  in nsIDOMNode aDOMNode,
  in nsISupportsArray aTransferables,
  in nsIScriptableRegion aRegion,
  in unsigned long aActionType 
);
Parameters
aDOMNode
The source node on which the drag gesture was started.
aTransferables
An array of transferables to be dragged.
aRegion
A region containing rectangles for cursor feedback, in window coordinates.
aActionType
Specified which of copy/move/link are allowed.

invokeDragSessionWithImage()

Starts a modal drag session using an image.

A custom image may be specified using the aImage argument. If this is supplied, the aImageX and aImageY arguments specify the offset within the image where the cursor would be positioned. That is, when the image is drawn, it is offset up and left the amount so that the cursor appears at that location within the image. If aImage is null, aImageX and aImageY are not used and the image is instead determined from the source node aDOMNode, and the offset calculated so that the initial location for the image appears in the same screen position as where the element is located. The node must be within a document.

Currently, supported images are all DOM nodes. If this is an HTML <image> or <canvas> element, the drag image is taken from the image data. If the element is in a document, it will be rendered at its displayed size, otherwise, it will be rendered at its real size. For other types of elements, the element is rendered into an offscreen buffer in the same manner as it is currently displayed. The document selection is hidden while drawing. The aDragEvent must be supplied as the current screen coordinates of the event are needed to calculate the image location.

void invokeDragSessionWithImage(
  in nsIDOMNode aDOMNode,
  in nsISupportsArray aTransferableArray,
  in nsIScriptableRegion aRegion,
  in unsigned long aActionType,
  in nsIDOMNode aImage,
  in long aImageX,
  in long aImageY,
  in nsIDOMDragEvent aDragEvent,
  in nsIDOMDataTransfer aDataTransfer 
);
Parameters
aDOMNode
The source node on which the drag gesture was started.
aTransferables
An array of transferables to be dragged.
aRegion
A region containing rectangles for cursor feedback, in window coordinates.
aActionType
Specified which of copy/move/link are allowed.
aImage
Image object.
aImageX
X position of image.
aImageY
Y position of image.
aDragEvent
The drag gesture event that initiated the drag.
aDataTransfer
A data transfer object that is available on the current drag session.

invokeDragSessionWithSelection()

Start a modal drag session using the selection as the drag image. The aDragEvent must be supplied as the current screen coordinates of the event are needed to calculate the image location.

void invokeDragSessionWithSelection(
  in nsISelection aSelection,
  in nsISupportsArray aTransferableArray,
  in unsigned long aActionType,
  in nsIDOMDragEvent aDragEvent,
  in nsIDOMDataTransfer aDataTransfer 
);
Parameters
aSelection
The selection that is to be dragged.
aTransferableArray
An array of transferables to be dragged.
aActionType
Specified which of copy/move/link are allowed
aDragEvent
The drag gesture event that initiated the drag.
aDataTransfer
A data transfer object that is available on the current drag session.

startDragSession()

Tells the Drag Service to start a drag session. This is called when an external drag occurs

void startDragSession();
Parameters

None.

suppress()

Increase dragging suppress level by one. This disables dragging if it is not already disabled.

void suppress();
Parameters

None.

unsuppress()

Decrease dragging suppress level by one. If level is zero, dragging is re-enabled.

void unsuppress();
Parameters

None.

Document Tags and Contributors

 Contributors to this page: V@no, Masayuki, Sheppy, kscarfone, Neil, trevorh, Jürgen Jeka, LJR, Kohei, Wrongloop, Dadatis, Kglee, Enn
 Last updated by: V@no,