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

>> 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. 

Hm.. I didn't really know that was a "rule". I basically want

element.dispatchEvent(new ClipboardEvent('copy'))

to be pretty much equivalent to

document.execCommand('copy')

except that the ClipboardEvent syntax would also let you specify a data payload. So the intention currently is to make these script-generated events cause real copy / cut / paste actions if the relevant security checks pass.

> clipboard events (tested copy and paste) aren't in that category
> in Firefox, at least (Chrome doesn't have ClipboardEvent).  Can you clarify?

Yes, this is not implemented yet.

Do any implementors want to comment on whether it's Very Bad or Very Strange to make synthetic clipboard events behave this way?


>> 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 sounds like an excellent solution :)

Spec-wise, event.clipboardData is an instance of the DataTransfer interface in HTML5. Can/should I spec this flag in the Clipboard Events spec, or argue that it should be added to HTML5 (or HTML6 / HTML Living / whatever)?

> 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)?

Well, I guess it's always possible to have an event listener call dispatchEvent() on some other element, passing the same event object.. Not sure if that matters?
-Hallvord

Received on Tuesday, 20 May 2014 08:42:46 UTC