Re: [clipboard events] implicitly prevent default event action?

On Mon, May 19, 2014 at 8:50 AM, Hallvord R. M. Steen <hsteen@mozilla.com>wrote:

> a) The event is script-generated and has a data payload (new
> ClipboardEvent('copy', {dataType:'text/plain', data:'Hi World'}))
>

I'm a little confused.  Script-generated events never have a "default
action", except for a couple isolated web-compatibility hacks where
dispatching an event in script has side-effects, like click.  As far as I
can tell, clipboard events (tested copy and paste) aren't in that category
in Firefox, at least (Chrome doesn't have ClipboardEvent).  Can you clarify?

(Unless we're talking about events like click, I don't think we should use
the term "default action" at all, since it leads to a lot of confusion
about how the event model works.  The "canceled flag" makes this clearer:
http://dom.spec.whatwg.org/#canceled-flag)

b) Any event listener calls setData() or modifies the DataTransfer payload
> some other way
>

Put a "changed" flag on clipboardData, which is set to true by
setData.  (This flag doesn't have to be visible to script.)  When the event
handler returns, copy the selected text if both preventDefault was not
called and the "changed" flag on clipboardData isn't set.  That is, the UA
behavior looks like this:

var dataTransfer = new DataTransfer(selectedText);
var clipboardEvent = new ClipboardEvent("copy", { clipboardData:
dataTransfer });
if(element.dispatchEvent(clipboardEvent) || dataTransfer.changed)
    copyTextToClipboard(dataTransfer);

This avoids having any weird interactions between DataTransfer and the
event system, and it's trivial to explain in terms of JS.

Is there any way for the .clipboardData object to get reused (eg. where the
.changed flag would be set to true from a previous event)?

-- 
Glenn Maynard

Received on Monday, 19 May 2014 23:50:19 UTC