Re: [clipboard-apis] Should queryCommandEnabled(cut|copy|paste) trigger onbefore* events? (#4)

For some reason, I thought the beforecopy/beforecut/beforepaste events were used as signals for whether or not to enable the corresponding context menu items. However, in my experiments, Chrome never seems to fire beforecopy/beforecut/beforepaste events before showing a menu, even with a selected range. So this either changed at some point, or my memory is faulty.

What actually seems to happen in Chrome when you call queryCommandEnabled('copy') is this:
1. First, check if copy is supported. If copy is not supported, return false. Note that queryCommandSupported('copy') only returns true with an active user gesture (!!) so much of the time, queryCommandEnabled('copy') returns false immediately here.
2. If the current selection is in a password field, return false.
3. Fire a beforecopy event. The event target is determined the same way as the event target for firing a copy event: it's based on the current selection, or the <body> element if there is no selection. If preventDefault() is called, return true.
4. If there is a selected range, return true.
5. Otherwise, return false.

So it actually seems pretty close to what you're proposing. In Chrome, I'm planning on taking the user gesture check out of step 1 so it always returns true. Then the rest follows pretty closely to what you proposed. Two questions:
1. What do IE/FF do with the beforecopy/beforecut/beforepaste events today?
2. Is it OK for queryCommandEnabled('copy') to return true when execCommand('copy') might not work, due to lack of a user gesture?

---
Reply to this email directly or view it on GitHub:
https://github.com/w3c/clipboard-apis/issues/4#issuecomment-108738545

Received on Thursday, 4 June 2015 05:59:27 UTC