- From: Glenn Maynard <glenn@zewt.org>
- Date: Thu, 17 Nov 2011 18:51:37 -0500
On Thu, Nov 17, 2011 at 5:33 PM, Daniel Cheng <dcheng at google.com> wrote: > Can you give an example of how you envision the write portion working? > Something along these lines, for example: elem.addEventListener("drop", function(e) { e.dataTransfer.onwritegranted = function(e) { // Write access to the dropped files was granted. } e.dataTransfer.onwritedenied = function(e) { // Write access was denied; the files remain read-only. }); e.dataTransfer.requestWriteAccess(); }, false); Calling requestWriteAccess would (in general) trigger a UA interface, like a Firefox doorhanger, asking whether write access would be granted for the drop, firing writegranted or writedenied. The files would be accessible but read-only until writegranted is fired; attempting to create a FileWriter would fail. That's a rough sketch, of course (there are lots of permutations you could make on how to request permission, eg. callbacks instead of events, and there are plenty of other details), but the important part is that the basic infrastructure is exactly the same for read and write access. You receive File (or FileEntry) and DirectoryEntry objects from dataTransfer.items. (The question of File vs. FileEntry is still an open one--you need FileEntry to create a Writer, but DataTransferItem specs File. Neither Chrome 16 nor Firefox 8 seem to implement files with DataTransferItem yet, so maybe that could still be changed to FileEntry.) That being said, the user shouldn't have to hold down their mouse though. > The files attribute isn't available until the drop event fires anyway. > However, this is why the items attribute (which is available in > dragenter/dragover events as well) was added; some authors wanted to be > able to use the file's MIME type to determine how to handle the drag. I > guess directory support there would almost certainly be out of question. > I tested this in Chrome 15, and the files attribute is already available during dragover. However, there's something strange: it's available during dragover with file://, but not with HTTP. http://zewt.org/~glenn/test-dragdrop-simple.html Anyhow, there's no need for DataTransfer inconsistency between drop and drag events with the DirectoryEntry approach (at least not for this reason). -- Glenn Maynard
Received on Thursday, 17 November 2011 15:51:37 UTC