clipboard event target in JS engine

124 views
Skip to first unread message

Marcin

unread,
Feb 8, 2017, 10:11:18 AM2/8/17
to Chromium-discuss
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:

  1. If the context is editable, then

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

  2. Else, if the context is not editable, then

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

PhistucK

unread,
Feb 8, 2017, 10:12:52 AM2/8/17
to mwr...@opera.com, Chromium-discuss
You can submit a patch! :)

Start first by making sure an issue is filed.
You can search crbug.com for an existing issue and star it. If you cannot find one, file a new issue using the "New issue" link on the same page.
Please, do not add a "+1" or "Me too" or "Confirmed" (or similar) comment. It just wastes the time of Chrome engineers and sends unnecessary e-mails to all of the people who starred the issue.

You can reply with a link to the found or created issue and might get triaged (and fixed) faster.

Thank you.




PhistucK

--
--
Chromium Discussion mailing list: chromium...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-discuss

---
You received this message because you are subscribed to the Google Groups "Chromium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-discuss+unsubscribe@chromium.org.

Reply all
Reply to author
Forward
0 new messages