DragAndDropOperation Class

A drag-and-drop operation (https://html.spec.whatwg.org/multipage/dnd.html#drag-and-drop-processing-model), driven by the user interactions of a host (e.g. the test driver of the web-platform-tests): DragAndDropOperation.TryStart when the pointer moves with a pressed button (or DragAndDropOperation.StartFromOutside for a drag from outside the user agent, such as files dragged from the file manager), DragAndDropOperation.Update each time it moves, and DragAndDropOperation.End when the button is released. The iterations of the processing model run on each move instead of every 350 ms.

public sealed class DragAndDropOperation

Remarks

As in the browsers, the element under the pointer (the immediate user selection) is the current target element whether or not its dragenter event is canceled: dragenter and dragleave are fired when the pointer enters and leaves elements, dragover is fired at the element under the pointer, and the drop is accepted when the dragover event is canceled (the specification instead makes the body element the current target element when the dragenter event is not canceled). A drop event that is not canceled keeps the current drag operation (the dropEffect of the dragend event), instead of resetting it to "none". There is no feedback (drag image).

A drag from outside the user agent has no source node: there is no dragstart, drag or dragend event, and the drag data store holds the files, the directories and the strings of the DragData. A drop on a file input that does not cancel the event selects the files (the files of the directories when the input has the webkitdirectory attribute). As in the browsers, the page reads the directories with webkitGetAsEntry() or getAsFileSystemHandle(). A drop elsewhere does nothing (a browser would open the file).

Properties

NameDescription
IsEndedWhether the operation ended (the button was released, or the drag event was canceled).
SourceNodeThe source node: the dragged element, the first Text node of the dragged selection (the text control of a selection of its value), or null for a drag from outside the user agent.

Whether the operation ended (the button was released, or the drag event was canceled).

public bool IsEnded { get; }

Property value

bool

The source node: the dragged element, the first Text node of the dragged selection (the text control of a selection of its value), or null for a drag from outside the user agent.

public Node? SourceNode { get; }

Property value

Node?

Methods

NameDescription
End(DragPointerState, bool)The last iteration, when the user releases the button (or cancels the operation, e.g. with the Escape key).
StartFromOutside(DragData, Document)Starts a drag from outside the user agent (e.g. files dragged from the file manager of the operating system) over the viewport of document: nothing is fired until the first DragAndDropOperation.Update, the dragenter event of the element under the pointer.
TryStart(Node, DragPointerState, bool)The steps run when the user attempts to begin a drag operation on node (the node under the pointer when the button was pressed). Returns null when nothing is dragged or when the dragstart event is canceled.
Update(Element?, DragPointerState)An iteration of the drag-and-drop operation while the pointer is over immediateUserSelection.

End(DragPointerState, bool)

DragAndDropOperation.cs

The last iteration, when the user releases the button (or cancels the operation, e.g. with the Escape key).

public void End(DragPointerState pointerState, bool canceled = false)

Parameters

pointerState DragPointerState
canceled bool

StartFromOutside(DragData, Document)

DragAndDropOperation.cs

Starts a drag from outside the user agent (e.g. files dragged from the file manager of the operating system) over the viewport of document: nothing is fired until the first DragAndDropOperation.Update, the dragenter event of the element under the pointer.

public static DragAndDropOperation StartFromOutside(DragData data, Document document)

Parameters

data DragData
The files, the directories and the strings that are dragged.
document Document
The document of the viewport (the top-level document): its clock dates the files that have no last modification date.

Returns

DragAndDropOperation

TryStart(Node, DragPointerState, bool)

DragAndDropOperation.cs

The steps run when the user attempts to begin a drag operation on node (the node under the pointer when the button was pressed). Returns null when nothing is dragged or when the dragstart event is canceled.

public static DragAndDropOperation? TryStart(Node node, DragPointerState pointerState, bool dragSelection = true)

Parameters

node Node
pointerState DragPointerState
dragSelection bool
Whether the selection can be dragged: the press was in the selection (the selection that the moves of the pointer are making is not dragged).

Returns

DragAndDropOperation?

Update(Element?, DragPointerState)

DragAndDropOperation.cs

An iteration of the drag-and-drop operation while the pointer is over immediateUserSelection.

public void Update(Element? immediateUserSelection, DragPointerState pointerState)

Parameters

immediateUserSelection Element?
pointerState DragPointerState