[Webkit-unassigned] [Bug 265857] Drag and drop is broken on Linux
bugzilla-daemon at webkit.org
bugzilla-daemon at webkit.org
Thu Dec 7 08:32:30 PST 2023
https://bugs.webkit.org/show_bug.cgi?id=265857
--- Comment #1 from toterddd at gmail.com ---
I believe I may have found the culprit.
In the DropTargetGtk3 implementation it says:
```c++
// WebCore needs the selection data to decide, so we need to preload the
// data of targets we support. Once all data requests are done we start
// notifying the web process about the DND events.
auto* list = gdk_drag_context_list_targets(m_drop.get());
static const char* const supportedTargets[] = {
"text/plain;charset=utf-8",
"text/html",
"_NETSCAPE_URL",
"text/uri-list",
"application/vnd.webkitgtk.smartpaste",
"org.webkitgtk.WebKit.custom-pasteboard-data"
};
```
I have tried modifying Mozillas provided example and added a line like
```js
event.dataTransfer.setData("text/plain", "vier");
```
and the drop worked afterwards.
Full code:
```html
<div class="dropzone">
<div id="draggable" draggable="true">This div is draggable</div>
</div>
<div class="dropzone" id="droptarget"></div>
```
```css
body {
/* Prevent the user from selecting text in the example */
user-select: none;
}
#draggable {
text-align: center;
background: white;
}
.dropzone {
width: 200px;
height: 20px;
background: blueviolet;
margin: 10px;
padding: 10px;
}
```
```js
let dragged = null;
const source = document.getElementById("draggable");
source.addEventListener("dragstart", (event) => {
// store a ref. on the dragged elem
dragged = event.target;
event.dataTransfer.setData("text/plain", "vier");
});
const target = document.getElementById("droptarget");
target.addEventListener("dragover", (event) => {
// prevent default to allow drop
event.preventDefault();
});
target.addEventListener("drop", (event) => {
// prevent default action (open as a link for some elements)
event.preventDefault();
console.log(event.dataTransfer.getData("text/plain"));
// move dragged element to the selected drop target
if (event.target.className === "dropzone") {
dragged.parentNode.removeChild(dragged);
event.target.appendChild(dragged);
}
});
```
Disclaimer: I have absolutely no knowledge of WebKit and just looked at the code for the first time so I have no idea if this will cause issues.
I think a default target should be set for those events that do not explicitly set it since the html specification does not mention requiring this property to be set.
--
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20231207/9f33ad7d/attachment.htm>
More information about the webkit-unassigned
mailing list