-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1437126 - Support imgIContainer as a file type in DataTransfer. r…
…=nika When using images with drag & drop (or the clipboard) we use two or more different types: - When dragging an image we put it into the DataTransfer object using the type kNativeImageMime and the data as an imgIContainer object. - When dropping an image we want to have some kind of image/ type, but the data is already supposed to be a File or nsIInputStream when it comes from the OS. This weird split usually works fine, because in our GTK, Windows and macOS code we first convert imgIContainer to whatever native image format is required when dragging something and then convert back to a file (or stream) when dropping. What however doesn't work is when we never actually round-trip through the OS. In that case we have the imgIContainer that we can't drop in a meaningful way. (I actually already ran into this issue in bug 1396587 with the clipboard, but we kind of resolved this by always doing the roundtrip through the OS's clipboard) Differential Revision: https://phabricator.services.mozilla.com/D162493
- Loading branch information
Showing
4 changed files
with
87 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Test that dragging an image produces a File</title> | ||
<script src="/tests/SimpleTest/SimpleTest.js"></script> | ||
<script src="/tests/SimpleTest/EventUtils.js"></script> | ||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> | ||
</head> | ||
<body> | ||
|
||
<img id="green-png" src="green.png"> | ||
|
||
<script> | ||
async function runTest() { | ||
let dt = await synthesizePlainDragAndCancel({ | ||
srcElement: document.getElementById('green-png'), | ||
finalY: 20, | ||
}, null); | ||
|
||
ok(dt.types.includes("Files"), "types should contains 'Files'"); | ||
is(dt.files.length, 1, "files contains one File"); | ||
|
||
let fileItem = null; | ||
for (let item of dt.items) { | ||
if (item.kind === "file") { | ||
fileItem = item; | ||
break; | ||
} | ||
} | ||
|
||
is(fileItem.kind, "file", "Is a file"); | ||
is(fileItem.type, "image/png", "Is a PNG file"); | ||
|
||
let file = fileItem.getAsFile(); | ||
is(file.name, "image.png", "Has generic image name") | ||
ok(file.size > 100, "Is not empty"); | ||
|
||
SimpleTest.finish(); | ||
} | ||
|
||
SimpleTest.waitForExplicitFinish(); | ||
SimpleTest.waitForFocus(runTest); | ||
</script> | ||
</body> | ||
</html> |