зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1737041 - DataTransfer.types should include 'Files'. r=masayuki
It almost feels like we should just use mItems for this, because AppendNewItem right above this function already seems to handle adding files correctly. However that would break GetTypes system callers that expect additional types. I am not sure if I should try updating HasFile to follow GetTypes, because https://bugzilla.mozilla.org/show_bug.cgi?id=1623239 already ran into issues with a similar change. Differential Revision: https://phabricator.services.mozilla.com/D130491
This commit is contained in:
Родитель
3c994f8afd
Коммит
6357cf7a44
|
@ -459,6 +459,20 @@ void DataTransferItemList::GetTypes(nsTArray<nsString>& aTypes,
|
|||
}
|
||||
}
|
||||
|
||||
// Additional files will be added at a non-zero index.
|
||||
if (!foundFile) {
|
||||
for (uint32_t i = 1; i < mIndexedItems.Length(); i++) {
|
||||
for (const RefPtr<DataTransferItem>& item : mIndexedItems[i]) {
|
||||
MOZ_ASSERT(item);
|
||||
|
||||
foundFile = item->Kind() == DataTransferItem::KIND_FILE;
|
||||
if (foundFile) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (foundFile) {
|
||||
aTypes.AppendElement(u"Files"_ns);
|
||||
}
|
||||
|
|
|
@ -112,4 +112,25 @@ test(() => {
|
|||
dt.types = 42;
|
||||
assert_equals(dt.types, types);
|
||||
}, "Verify type is a read-only attribute");
|
||||
|
||||
test(() => {
|
||||
const dt = new DataTransfer();
|
||||
assert_array_equals(dt.types, []);
|
||||
|
||||
// The added File is respected
|
||||
dt.items.add(new File(["abc"], "test.txt"));
|
||||
assert_array_equals(dt.types, ["Files"]);
|
||||
|
||||
// "Files" is always last even after setting data
|
||||
dt.setData("text/plain", "test");
|
||||
assert_array_equals(dt.types, ["text/plain", "Files"]);
|
||||
|
||||
// Removing the File changes types
|
||||
dt.items.remove(0);
|
||||
assert_array_equals(dt.types, ["text/plain"]);
|
||||
|
||||
// Adding back a File as the second item works correctly.
|
||||
dt.items.add(new File(["abc"], "test.txt"));
|
||||
assert_array_equals(dt.types, ["text/plain", "Files"]);
|
||||
}, "DataTransfer containing files");
|
||||
</script>
|
||||
|
|
Загрузка…
Ссылка в новой задаче