W3C home > Mailing lists > Public > public-webapps@w3.org > April to June 2014

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

From: Glenn Maynard <glenn@zewt.org>
Date: Mon, 19 May 2014 18:49:52 -0500
Message-ID: <CABirCh_8b8e1Afiq2ZujbV2Wsq43i75Uej_+MYe2A__LkVEm4Q@mail.gmail.com>
To: "Hallvord R. M. Steen" <hsteen@mozilla.com>
Cc: public-webapps <public-webapps@w3.org>
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

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 18:14:24 UTC