Re: [w3c/clipboard-apis] The "focused node" when determining event target needs to be defined (#70)

No, it should **not** be `document.activeElement`.  It should be `Selection.focusNode`. The reason is that you can have an activeElement without a selection, and these commands (Copy etc) _operates on the selection_ by [definition](https://w3c.github.io/clipboard-apis/#clipboard-event-copy).  [Here's a simple testcase](https://bug1541572.bmoattachments.org/attachment.cgi?id=9055632) to demonstrate this.  Firefox and Chrome both prints:

```
Current selection is 
Selection { anchorNode: null, anchorOffset: 0, focusNode: null, focusOffset: 0, isCollapsed: true, rangeCount: 0, type: "None", caretBidiLevel: 0 }
Current activeElement is 
<div id="playground1" class="playground" tabindex="0">
Got copy event, target is 
<body>
```

That said, `document.activeElement` and `Selection.focusNode` are usually the same node, but there are cases when they are not, e.g. when the Selection has been modified by JS or when activeElement was set by a user gesture and CSS `user-select:none` prevented it from being selected (as intended).

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/clipboard-apis/issues/70#issuecomment-479682878

Received on Wednesday, 3 April 2019 22:33:46 UTC