[prev in list] [next in list] [prev in thread] [next in thread] 

List:       whatwg
Subject:    Re: [whatwg] Drag-and-drop feedback
From:       Daniel Cheng <dcheng () google ! com>
Date:       2010-03-29 22:26:32
Message-ID: cdc844f71003291526w7bb6b74en3f708f7597581e56 () mail ! gmail ! com
[Download RAW message or body]

I like the DataTransferItems proposal. I had a few questions, but no one
answered, so I'm going to propose some modifications:

DataTransferItems is a mapping of types to data like DataTransfer.
DataTransfer mirrors DataTransferItems, but DataTransfer.getData() will
throw an error if the data is a blob. Maybe a second getData method that can
provide conversion given a text encoding would be useful?

DataTransfer changes:
DataTransfer.addFile(fileData);

dataTransfer.items = DataTransferItems

DataTransferItems.length
  .getItem(type) = DataTransferItem
  .add(stringData, type)
  .add(blobData)
  .add(dataTransferItem)
  .clear()

DataTransferItem.kind = 'string', 'blob'
  .type = MIME type
  .getTextData(function callback (data)) - throws if binary is true
  .getBlob() - returns Blob

The binary property has been folded into the "kind" property.

When interacting with non-DOM apps or pages, some platforms can't easily
convert arbitrary MIME types to native data transfer types for copy/paste or
DnD. For this reason, I think the spec should explicitly list MIME types for
which UAs should handle the conversion to native data transfer types. A
couple that come to mind: text/plain, text/uri-list, text/rtf,
application/rtf, text/html, text/xml, image/png, and image/svg+xml.
UAs can make a best-effort attempt to convert the other types, but it won't
be guaranteed that they will be there for interaction with non-DOM
applications.

Daniel

On Tue, Mar 9, 2010 at 3:03 PM, Daniel Cheng <dcheng@google.com> wrote:

> On Fri, Feb 26, 2010 at 10:56 AM, Dmitry Titov <dimich@google.com> wrote:
>
>> On Mon, Feb 22, 2010 at 6:06 PM, Daniel Cheng <dcheng@google.com> wrote:
>>
>>> Several questions about the proposal:
>>> How does DataTransferItems interact with the original DataTransfer
>>> object? I'm assuming changes in one should be reflected in the other. If
>>> that's the case, what should happen if I do this:
>>> dataTransfer.items.add(fileData);
>>> dataTransfer.getData(mimeTypeForFile);
>>>
>>
>> Unless there is a specific reason to think different, there is only one
>> set of items backing DataTransfer object - today the files and 'other items'
>> are represented separtely, the proposed items list is simply a merged
>> version of the same. In your example you should be able to getData.
>>
>
> Does that mean getData() can return types besides DOMString?
>
>
>>
>>
>>> How come there's no DataTransferItems.get(type) method?
>>>
>>
>> There can be multiple items of that type (dragging several image files).
>> Would it return another items list? What is the use case for this? Also,
>> some items may have empty type (a file with unknown extension).
>>
>
> I think files have always been a special case and should continue to be
> handled that way. I don't think there's any platform pasteboard that
> supports multiple items of one non-file type, so it'd make the most sense to
> make it a 1:1 mapping from types to data.
>
>
>>
>> DataTransferItem provides richer metadata than is available through the
>>> native drag-and-drop interface on most platforms. When dragging data from a
>>> non-DOM application, how do you extrapolate the metadata to fill in the
>>> type/binary fields?
>>>
>>
>> 'type' can be inferred in many cases from file extension, native clipboard
>> format or other means. It can be done w/o content sniffing and disk IO.
>>
>
> Should there be some sort of standard list of mappings that all UAs should
> support wherever possible? What happens if the UA doesn't have a mapping for
> a type?
>
>
>>
>> I understand 'binary' as indicator of whether or not the item can be read
>> as a text string. I'm not sure why item.kind == "string" is not the same. If
>> the intent is to also cover some files that can be read as string and as
>> Blob, then it might be buggy because the only way to establish if the file
>> can be converted into JS string is to actually read the bytes and try to
>> convert to Unicode. There can be invalid character sequences or the encoding
>> info may be missing.
>>
>> Perhaps we should remove 'binary' and assume that items that item.kind ==
>> "string" can use getTextData(callback) to pull the string.
>>
>> On a separate note, I think items.add(dataTransferItem) is not useful w/o
>> a way to create a new DataTransferItem separately from the DataTransferItems
>> list.
>>
>>
>>>
>>> Daniel
>>>
>>>
>>> On Mon, Feb 22, 2010 at 3:51 PM, Ian Hickson <ian@hixie.ch> wrote:
>>>
>>>> On Thu, 4 Feb 2010, Ian Hickson wrote:
>>>> > On Sat, 23 Jan 2010, Eduard Pascual wrote:
>>>> > >
>>>> > > Would it be possible to provide a list of "drag items" (to call them
>>>> > > somehow) instead of, or in addition to, the current info provided by
>>>> > > the DataTransfer object?
>>>> >
>>>> > That's a pretty good idea. I think we should probably do this when we
>>>> > add more types to the DataTransfer object.
>>>>
>>>> Some engineers at Google discussed this a bit and came up with the
>>>> following proposal:
>>>>
>>>>   dataTransfer.items = DataTransferItems
>>>>
>>>>    DataTransferItems.length
>>>>                     .getItem(n) = DataTransferItem
>>>>                     .add(stringData, type)
>>>>                     .add(blobData)
>>>>                     .add(fileData)
>>>>                     .add(dataTransferItem)
>>>>                     .clear()
>>>>
>>>>    DataTransferItem.kind = 'string', 'file', 'blob', ...
>>>>                    .type = MIME type
>>>>                    .binary = boolean
>>>>                    .getTextData(function callback (data)) - throws if
>>>> binary is true
>>>>                    .getBlob() - returns File or Blob
>>>>
>>>> When we add promises later, this can easily be extended to support that
>>>> as
>>>> well (basically, just by adding a new add() method for the promise
>>>> case).
>>>>
>>>> I've put this into the comment in the spec, but haven't specced it. If
>>>> any
>>>> browser vendors want to try implementing this or something like it, any
>>>> reports of implementation experience would be very useful. Please prefix
>>>> the "items" attribute with some unique string like "webkitItems" or
>>>> "geckoItems" so that it doesn't clash with the spec when we do add
>>>> something like this!
>>>>
>>>> Cheers,
>>>> --
>>>> Ian Hickson               U+1047E                )\._.,--....,'``.    fL
>>>> http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._
>>>> ,.
>>>> Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'
>>>>
>>>
>>>
>>
>

[Attachment #3 (text/html)]

I like the DataTransferItems proposal. I had a few questions, but no one answered, so \
I&#39;m going to propose some modifications:<div><br></div><div>DataTransferItems is \
a mapping of types to data like DataTransfer. DataTransfer mirrors DataTransferItems, \
but DataTransfer.getData() will throw an error if the data is a blob. Maybe a second \
getData method that can provide conversion given a text encoding would be \
useful?</div> <div><br></div><div>DataTransfer \
changes:</div><div>DataTransfer.addFile(fileData);<br><br></div><div>dataTransfer.items \
= DataTransferItems</div><div><div><br></div><div>DataTransferItems.length</div><div> \
.getItem(type) = DataTransferItem</div> <div>    .add(stringData, type)</div><div>    \
.add(blobData)</div><div>    .add(dataTransferItem)</div><div>    \
.clear()</div><div><br></div><div>DataTransferItem.kind = &#39;string&#39;, \
&#39;blob&#39;</div><div>    .type = MIME type</div> <div>    .getTextData(function \
callback (data)) - throws if binary is true</div><div>    .getBlob() - returns \
Blob</div><div><br></div><div>The binary property has been folded into the \
&quot;kind&quot; property.</div><div><br> </div><div>When interacting with non-DOM \
apps or pages, some platforms can&#39;t easily convert arbitrary MIME types to native \
data transfer types for copy/paste or DnD. For this reason, I think the spec should \
explicitly list MIME types for which UAs should handle the conversion to native data \
transfer types. A couple that come to mind:  text/plain, text/uri-list, text/rtf, \
application/rtf, text/html, text/xml, image/png, and image/svg+xml.</div> <div>UAs \
can make a best-effort attempt to convert the other types, but it won&#39;t be \
guaranteed that they will be there for interaction with non-DOM \
applications.</div><div><div>  </div></div><div>Daniel</div><div><br></div> <div \
class="gmail_quote">On Tue, Mar 9, 2010 at 3:03 PM, Daniel Cheng <span \
dir="ltr">&lt;<a href="mailto:dcheng@google.com">dcheng@google.com</a>&gt;</span> \
wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px \
#ccc solid;padding-left:1ex;"> <div class="im">On Fri, Feb 26, 2010 at 10:56 AM, \
Dmitry Titov <span dir="ltr">&lt;<a href="mailto:dimich@google.com" \
target="_blank">dimich@google.com</a>&gt;</span> wrote:<br></div><div \
class="gmail_quote"><div class="im"> <blockquote class="gmail_quote" style="margin:0 \
0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div class="gmail_quote"><div>On Mon, Feb 22, 2010 at 6:06 PM, Daniel Cheng <span \
dir="ltr">&lt;<a href="mailto:dcheng@google.com" \
target="_blank">dcheng@google.com</a>&gt;</span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex">




<div>Several questions about the proposal:</div>How does DataTransferItems interact \
with the original DataTransfer object? I&#39;m assuming changes in one should be \
reflected in the other. If that&#39;s the case, what should happen if I do this:<div>






dataTransfer.items.add(fileData);</div><div>dataTransfer.getData(mimeTypeForFile);</div></blockquote><div><br></div></div><div>Unless \
there is a specific reason to think different, there is only one set of items backing \
DataTransfer object - today the files and &#39;other items&#39; are represented \
separtely, the proposed items list is simply a merged version of the same. In your \
example you should be able to getData.</div>


</div></blockquote><div><br></div></div><div>Does that mean getData() can return \
types besides DOMString?</div><div class="im"><div>  </div><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex">

<div class="gmail_quote"><div>

<div>  </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px \
#ccc solid;padding-left:1ex"><div><div><div><div><div>How come there&#39;s no \
DataTransferItems.get(type) method?</div></div></div></div>




</div></blockquote><div><br></div></div><div>There can be multiple items of that type \
(dragging several image files). Would it return another items list? What is the use \
case for this? Also, some items may have empty type (a file with unknown \
extension).</div>


</div></blockquote><div><br></div></div><div>I think files have always been a special \
case and should continue to be handled that way. I don&#39;t think there&#39;s any \
platform pasteboard that supports multiple items of one non-file type, so it&#39;d \
make the most sense to make it a 1:1 mapping from types to data.</div> <div \
class="im"> <div>  </div><blockquote class="gmail_quote" style="margin:0 0 0 \
.8ex;border-left:1px #ccc solid;padding-left:1ex"> <div class="gmail_quote"><div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 \
.8ex;border-left:1px #ccc solid;padding-left:1ex"> \
<div><div><div><div><div>DataTransferItem provides richer metadata than is available \
through the native drag-and-drop interface on most platforms. When dragging data from \
a non-DOM application, how do you extrapolate the metadata to fill in the type/binary \
fields?</div>



</div></div></div></div></blockquote><div><br></div></div><div>&#39;type&#39; can be \
inferred in many cases from file extension, native clipboard format or other means. \
It can be done w/o content sniffing and disk IO.</div>


</div></blockquote><div><br></div></div><div>Should there be some sort of standard \
list of mappings that all UAs should support wherever possible?  What happens if the \
UA doesn&#39;t have a mapping for a type?</div><div><div> </div><div class="h5"><div> \
</div> <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"> <div class="gmail_quote"><div>
<br></div><div>I understand &#39;binary&#39; as indicator of whether or not the item \
can be read as a text string. I&#39;m not sure why item.kind == &quot;string&quot; is \
not the same. If the intent is to also cover some files that can be read as string \
and as Blob, then it might be buggy because the only way to establish if the file can \
be converted into JS string is to actually read the bytes and try to convert to \
Unicode. There can be invalid character sequences or the encoding info may be \
missing.</div>



<div><br></div><div>Perhaps we should remove &#39;binary&#39; and assume that items \
that item.kind == &quot;string&quot; can use getTextData(callback) to pull the \
string.</div><div><br></div><div>On a  separate  note, I think \
items.add(dataTransferItem) is not useful w/o a way to create a new DataTransferItem \
separately from the DataTransferItems list.</div>


<div><div></div><div>
<div>  </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px \
#ccc solid;padding-left:1ex"><div><div><div><div>


<div><br></div><div><font \
color="#888888">Daniel</font><div><div></div><div><br><br><div class="gmail_quote">On \
Mon, Feb 22, 2010 at 3:51 PM, Ian Hickson <span dir="ltr">&lt;<a \
href="mailto:ian@hixie.ch" target="_blank">ian@hixie.ch</a>&gt;</span> wrote:<br>




<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex">

<div>On Thu, 4 Feb 2010, Ian Hickson wrote:<br>
&gt; On Sat, 23 Jan 2010, Eduard Pascual wrote:<br>
&gt; &gt;<br>
&gt; &gt; Would it be possible to provide a list of &quot;drag items&quot; (to call \
them<br> &gt; &gt; somehow) instead of, or in addition to, the current info provided \
by<br> &gt; &gt; the DataTransfer object?<br>
&gt;<br>
&gt; That&#39;s a pretty good idea. I think we should probably do this when we<br>
&gt; add more types to the DataTransfer object.<br>
<br>
</div>Some engineers at Google discussed this a bit and came up with the<br>
following proposal:<br>
<br>
    dataTransfer.items = DataTransferItems<br>
<br>
      DataTransferItems.length<br>
                               .getItem(n) = DataTransferItem<br>
                               .add(stringData, type)<br>
                               .add(blobData)<br>
                               .add(fileData)<br>
                               .add(dataTransferItem)<br>
                               .clear()<br>
<br>
      DataTransferItem.kind = &#39;string&#39;, &#39;file&#39;, &#39;blob&#39;, \
                ...<br>
                              .type = MIME type<br>
                              .binary = boolean<br>
                              .getTextData(function callback (data)) - throws if \
                binary is true<br>
                              .getBlob() - returns File or Blob<br>
<br>
When we add promises later, this can easily be extended to support that as<br>
well (basically, just by adding a new add() method for the promise case).<br>
<br>
I&#39;ve put this into the comment in the spec, but haven&#39;t specced it. If \
any<br> browser vendors want to try implementing this or something like it, any<br>
reports of implementation experience would be very useful. Please prefix<br>
the &quot;items&quot; attribute with some unique string like &quot;webkitItems&quot; \
or<br> &quot;geckoItems&quot; so that it doesn&#39;t clash with the spec when we do \
add<br> something like this!<br>
<br>
Cheers,<br>
<div><div></div><div>--<br>
Ian Hickson                      U+1047E                        )\._.,--....,&#39;``. \
fL<br> <a href="http://ln.hixie.ch/" target="_blank">http://ln.hixie.ch/</a>          \
U+263A                        /,    _.. \    _\   ;`._ ,.<br> Things that are \
impossible just take longer.    `._.-(,_..&#39;--(,_..&#39;`-.;.&#39;<br> \
</div></div></blockquote></div><br></div></div></div></div></div></div></div> \
</blockquote></div></div></div><br> </blockquote></div></div></div><br>
</blockquote></div><br></div>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic