Re: [clipboard events] click-to-copy support could be hasFeature discoverable?

Hallvord: By the way, please add the editor of the HTML spec to the
beginning of the list in your references.  It's strange to list a bunch of
author names, but not the person who actually writes the spec.


On Fri, May 23, 2014 at 8:21 AM, James Greene <james.m.greene@gmail.com>wrote:

> This kind of copy does not implicitly have anything to do with Selection,
> unless we continue to have its default action be copying the currently
> selected text.  It is substantially more likely to be used for custom text
> insertion.
>

I'd assume something like:

// Copy text:
window.copyToClipboard("hello");
// Copy HTML text:
span = document.createElement("span");
span.innerHTML = "<b>hello</b>";
window.copyToClipboard(span);
// Copy an image from a CanvasImageSource:
window.copyToClipboard(canvas);
window.copyToClipboard(img);
// Copy the selection:
window.copyToClipboard(window.getSelection());
// Copy HTML text with plaintext alternative:
dt = new DataTransferItemList();
dt.add("hello", "text/plain");
dt.add(span.innerHTML, "text/html");
window.copyToClipboard(dt);

This avoids the busywork of creating a DataTransfer in common cases, but
allows using DataTransfer when you want to do something more advanced, like
provide alternatives or explicitly specify a MIME type.  Note
that DataTransferItemList isn't actually constructable right now.  Note
that I used DataTransferItemList in the example and not DataTransfer, since
DataTransfer is only relevant to drag-and-drop.

I wonder what the right way to handle images is.  Native Windows
applications can copy pixel data to the clipboard, then paste it back out.
 DataTransferItem wants things to act like strings, though, so you'd have
to encode the image to a file format.  If that's PNG, that's an expensive
conversion.  Maybe DataTransferItem should be able to return an ImageSource.

(As an aside, why is the paste event's .clipboardData not set to the text
being pasted?  I wanted to see what pasting images did in current browsers,
but at least in Chrome there's nothing in there, even if I just paste plain
text.)

-- 
Glenn Maynard

Received on Friday, 23 May 2014 15:14:18 UTC