hi,
please consider 'copy to clipboard' pattern below (js code):
// listener in document should catch clipboard event
document.addEventListener('copy', copyHandler, false)
// command will fire clipboard event which should be handled in document
document.execCommand('copy');
The problem with pattern above is when it is executed when clipboard event target is 'hidden' by shadow root element (then clipboard event path during bubling phase is set up to shadow root element), and never reaches document.
To avoid this issue I tried to add event handler to document.activeElement, but this also didn't help much.
Further analysis of this issue led me into WebKit
function responsible for establishing clipboard event target.
I think that clipboard event target element is established in wrong way:
it does not take into account if selection is editable and it should according to
specification (point 6):
Let target be set as follows:
If the context is editable, then
Set target to be the element that contains the start of the selection in document order, or the body element if there is no selection or cursor.
Else, if the context is not editable, then
Set target to be the focused node, or the body element if no node has focus.
So I believe the target should be established in the following way (piece of
function responsible for establishing clipboard event target):
Element* target = selection.hasEditableStyle() ?
associatedElementOf(selection.start()) :
frame().document()->activeElement();
rather then:
Element* target = associatedElementOf(selection.start());
Please let me know if my proposal could be integrated into chromium source code.
thanks