Repository navigation
Description
We would like to add a new boolean attribute in DataTransfer to prevent it from overwriting the page's cursor during drag-and-drop operations.
Before creating a pull request for this, we'd like to get some general feedback about the proposed solution and/or alternative approaches we may not have considered.
Background
When a page handles drag and drop events, the cursor is automatically set to one of the predefined drag cursors while the drag operation is happening. But this behavior is not always desirable. Web pages that explicitly set the cursor image are likely to want that image to remain in effect during the drag.
Use case
An app that needs to set the cursor based on criteria other than what the browser thinks is being dragged and dropped. In our specific case or a web-based remote access client, we need to set the cursor based on the remote machine's drag-n-drop operation, and ignore what the client thinks is going on. Imagine a web client connecting to Photoshop running on a remote machine - we need to preserve the remote cursor shapes when the user is clicking, dragging and drawing.
For the single window case, we can simply ignore the entire drag and drop API and just send the cursor events to the remote machine. However, we are now adding support for multiple local client windows (e.g., one local window per remote display) and these cursor events are only sent to the window where the mousedown/drag begins. In order to have a coherent drag from one window to another, we need to use the DataTransfer API (which as mentioned earlier, overwrites the cursor).
This API would work fine for this use case if only it didn't overwrite the current cursor. Hence this proposal.
Current DataTransfer interface
The current DataTransfer interface has two attributes that affect the cursor while dragging:
partial interface DataTransfer {
attribute DOMString dropEffect;
attribute DOMString effectAllowed;
};
The effectAllowed attribute controls which dropEffects are allowed. It can be set to "none", "copy", "copyLink", "copyMove", "link", "linkMove", "move", "all", or "uninitialized".
The dropEffect attribute controls the feedback that the user receives (i.e., the cursor shape). The possible values are "none", "copy", "link", and "move".
Proposed Solution
We think the most reasonable way to address this would be to add a new attribute to DataTransfer:
partial interface DataTransfer {
attribute boolean autoSetDragCursor = true;
};
This attribute would be set to true by default to match the current behavior of drag-n-drop, where the cursor is set automatically.
To use this attribute, it would need to be set in the dragstart event. If it is set to false, then the User Agent will not attempt to provide cursor feedback to the user during the drag.
Alternatives Considered
We considered adding a new value to effectAllowed, but felt that the current structure of this attribute is complex enough already that we shouldn't be adding more to it.
We also considered something analogous to setDragImage(), but for setting the cursor image. However, since there are existing methods for setting the cursor it seems reasonable to just rely on them.
Mitigating Abuse
This attribute would only be set in the dragstart event (when the drag data store's mode is read/write, just like the restriction for effectAllowed).
The custom cursor is applied only within the content region, so the user cannot be tricked into dropping content outside the browser when they think they're dropping inside.
Setting a very large custom cursor that overlaps browser UI and other windows is not specific to drag-and-drop and has been addressed in the general case (by restricting max cursor size: see https://bugs.chromium.org/p/chromium/issues/detail?id=1246188).
Activity
smaug---- commentedon Dec 8, 2022
I'm not yet sure if there abuse cases where this might be very problematic. Like you think you're juts moving move and end up dropping something to your desktop or so, just because the content area covers most of the screen.
Also the API would make the already weird API even weirder. One would have those old attributes affecting nothing.
annevk commentedon Dec 8, 2022
Since the cursor is controllable through CSS today I think it might make sense to explore a CSS-based solution to this. (At some point there was a proposal for drag & drop pseudo-classes, but I guess that still hasn't been standardized.)