Bug 80159

Summary: Content with -webkit-user-select: none should be skipped during copy
Product: WebKit Reporter: ultr
Component: HTML EditingAssignee: Ryosuke Niwa <rniwa>
Status: RESOLVED FIXED    
Severity: Normal CC: 234234234x24dfgdfg, aandrey, aidan.feldman, benjaminkindle, bn, clopez, cory, cpeterson, desamo, dougalg, ehsan, enrica, eoconnor, laughinghan, ntim, rniwa, sanjaylgb, shanestephens, shezbaig.wk, simon.fraser, tellowkrinkle
Priority: P2 Keywords: BrowserCompat, InRadar
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 208677, 128236, 216325    
Attachments:
Description Flags
testcase
none
Test case none

Description ultr 2012-03-02 06:55:12 PST
Created attachment 129896 [details]
testcase

"-webkit-user-select:none" CSS property is not respected when copying content.


Testcase:

<span>one</span>
<span style="-webkit-user-select:none; -moz-user-select:none;">two</span>
<span>three</span>

When you select the above text and copy it, your clipboard will contain "one two three" instead of "one three".


It works OK in Mozilla Firefox - only elements with no -webkit-user-select:none set are copied.
Comment 1 Shane Stephens 2012-03-21 20:54:33 PDT
Firefox has the same behavior, and even documents this ( https://developer.mozilla.org/en/CSS/user-select). In the absence of an explicit specification suggesting the correct behavior is to respect the property when copying content, this doesn't seem to be a bug.
Comment 2 ultr 2012-05-26 03:52:23 PDT
> Firefox has the same behavior

This is not true.
I have just tested it and it does NOT copy -moz-user-select:none fragments into the clipboard.
Tested on:
- Iceweasel 10.0.4 on Debian
- Firefox 12.0 on Windows (there seems to be a bug: -moz-user-select:none fragment can be selected, but it is still NOT copied into the clipboard)

There should at least be an option to change this behavior in Qt Webkit, so that this feature can be used in programs.
Comment 3 Alexey Proskuryakov 2012-07-01 10:57:57 PDT
*** Bug 90348 has been marked as a duplicate of this bug. ***
Comment 4 Ryosuke Niwa 2012-07-02 11:27:51 PDT
(In reply to comment #1)
> Firefox has the same behavior, and even documents this ( https://developer.mozilla.org/en/CSS/user-select). In the absence of an explicit specification suggesting the correct behavior is to respect the property when copying content, this doesn't seem to be a bug.

This is not true at all.
Comment 5 Mr Maier 2013-01-16 06:23:03 PST
My system does not copy the text which is effected by "-webkit-user-select:none", too. Tested with Chrome 24.0.1312.52, Firefox 16.0.1 & WebKit r139829 on Mac OS
Comment 6 Mr Maier 2013-01-16 06:26:04 PST
(In reply to comment #5)
> My system does not copy the text which is effected by "-webkit-user-select:none", too. Tested with Chrome 24.0.1312.52, Firefox 16.0.1 & WebKit r139829 on Mac OS


Sorry I wanted to say it DOES COPY
Comment 7 Chris Peterson 2013-01-17 18:31:49 PST
Two interesting differences between -webkit-user-select:none and -moz-user-select:none (and the related -moz-user-select:-moz-none) is the highlighting and copying of text:

* WebKit: CMD+A (or dragging a selection) will highlight the text surrounding a `none` span, but NOT the `none` text.
* Gecko: CMD+A (or dragging a selection) will highlight all text, INCLUDING the `none` text.

* WebKit: CMD+C will copy all text, INCLUDING the `none` text.
* Gecko: CMD+C will copy the text surrounding a `none` span, but NOT the `none` text.
Comment 8 Ryosuke Niwa 2013-01-18 12:11:14 PST
(In reply to comment #7)
> Two interesting differences between -webkit-user-select:none and -moz-user-select:none (and the related -moz-user-select:-moz-none) is the highlighting and copying of text:
> 
> * WebKit: CMD+A (or dragging a selection) will highlight the text surrounding a `none` span, but NOT the `none` text.
> * Gecko: CMD+A (or dragging a selection) will highlight all text, INCLUDING the `none` text.

Gecko's behavior is counter-intuitive here. Isn't the whole point of user-select: none so that the text is never selected/highlighted?

> * WebKit: CMD+C will copy all text, INCLUDING the `none` text.
> * Gecko: CMD+C will copy the text surrounding a `none` span, but NOT the `none` text.

Gecko's behavior makes sense here. I previously said that I'm afraid there might be a compat. issue but I think it makes sense to match Gecko's behavior on the basis that the user wouldn't expect unhighlighted text to be included when they hit cmd/ctl+c.
Comment 9 Chris Peterson 2013-01-18 12:47:40 PST
(In reply to comment #8)
> > * WebKit: CMD+A (or dragging a selection) will highlight the text surrounding a `none` span, but NOT the `none` text.
> > * Gecko: CMD+A (or dragging a selection) will highlight all text, INCLUDING the `none` text.
> 
> Gecko's behavior is counter-intuitive here. Isn't the whole point of user-select: none so that the text is never selected/highlighted?

I agree; I feel that highlighting text that is not going to copied is misleading.


> > * WebKit: CMD+C will copy all text, INCLUDING the `none` text.
> > * Gecko: CMD+C will copy the text surrounding a `none` span, but NOT the `none` text.
> 
> Gecko's behavior makes sense here. I previously said that I'm afraid there might be a compat. issue but I think it makes sense to match Gecko's behavior on the basis that the user wouldn't expect unhighlighted text to be included when they hit cmd/ctl+c.

I think part of the confusion is whether -*-user-select:none (which is not standard CSS) intends "selection" to means text highlight or copying. I think the user-select:none use case is to prevent users from highlighting and copying elements of a web page that are "not content", such as header or footer text. Unfortunately, I can imagine news websites marking their articles' text as user-select:none as weak "copy protection" (like websites that use JS to prevent right-clicking on images).
Comment 10 ultr 2013-01-18 13:28:10 PST
> * Gecko: CMD+A (or dragging a selection) will highlight all text, INCLUDING the `none` text.

That was working fine (-moz-user-select:none text was not highlighted nor copied) in Mozilla Firefox when I submitted this bug. But I confirm this is broken now (Iceweasel 18.0).
Comment 11 Ryosuke Niwa 2013-01-18 13:32:45 PST
(In reply to comment #9)
> > > * WebKit: CMD+C will copy all text, INCLUDING the `none` text.
> > > * Gecko: CMD+C will copy the text surrounding a `none` span, but NOT the `none` text.
> > 
> > Gecko's behavior makes sense here. I previously said that I'm afraid there might be a compat. issue but I think it makes sense to match Gecko's behavior on the basis that the user wouldn't expect unhighlighted text to be included when they hit cmd/ctl+c.
> 
> I think part of the confusion is whether -*-user-select:none (which is not standard CSS) intends "selection" to means text highlight or copying. I think the user-select:none use case is to prevent users from highlighting and copying elements of a web page that are "not content", such as header or footer text. Unfortunately, I can imagine news websites marking their articles' text as user-select:none as weak "copy protection" (like websites that use JS to prevent right-clicking on images).

Yeah, that'll be very annoying for users.
Comment 12 Chris Peterson 2013-01-18 14:17:51 PST
(In reply to comment #10)
> That was working fine (-moz-user-select:none text was not highlighted nor copied) in Mozilla Firefox when I submitted this bug. But I confirm this is broken now (Iceweasel 18.0).

ultr, in comment #2, you said that I that Iceweasel 10 on Debian did NOT highlight the "none" text, but Firefox 12 on Windows did.

I just tested Firefox 10 and 12 on Mac OS X. Firefox 12 does highlight the "none" text, but Firefox 10 does NOT! So the text highlight bug is a Gecko regression in Firefox 11 or 12.

Thanks for pointing this regression. I'm going to file a Firefox bug now. :)
Comment 13 Deirdre Saoirse Moen 2013-04-18 18:06:54 PDT
<rdar://problem/13689646>
Comment 14 Han 2015-01-02 08:44:15 PST
FYI Firefox's misleading behavior of highlighting text that is not going to copied has been fixed in Firefox 35 (currently in beta): https://bugzilla.mozilla.org/show_bug.cgi?id=739396

So -moz-user-select:none is pretty much perfect now in Firefox.

Also, just to link this stuff together, the corresponding Chromium issue: https://code.google.com/p/chromium/issues/detail?id=147490
Comment 15 Cory Duncan 2019-07-25 11:54:50 PDT
I'm seeing this working as expected in Chrome, Firefox and Edge. Is there any hope this might get fixed for Safari at some point?
Comment 16 Dougal Graham 2020-02-25 22:03:43 PST
It would be nice for this to be consistent across all browsers. It is even mentioned in the spec now:

https://drafts.csswg.org/css-ui-4/#content-selection

"UAs are encouraged to keep the visual selection consistent with what would get copied to the clipboard when copying. Copying text that does not appear to be selected, or vice versa, is highly confusing to users."
Comment 17 Tim Nguyen (:ntim) 2022-04-20 01:28:57 PDT Comment hidden (obsolete)
Comment 18 Tim Nguyen (:ntim) 2022-04-20 02:20:07 PDT
(In reply to Tim Nguyen (:ntim) from comment #17)
> getSelection() seems to return the correct selection without the
> user-select: none content. Not sure what the manual copy process uses, but
> it should use something similar.

I stand corrected, getSelection() is wrong, it returns one range instead of two!
Comment 19 Tim Nguyen (:ntim) 2022-04-20 02:22:45 PDT
Chrome returns the one range (like WebKit) for getSelection() as well, and getSelection().toString() is "one two three" like WebKit. Gecko returns "one three"...
Comment 20 Ryosuke Niwa 2022-04-20 09:53:39 PDT
WebKit doesn't support multi-range selection. We need to adjust the behavior of StyledMarkupAccumulator in Markup.cpp. We probably also need to add a mode of TextIterator which skips content with this style applied as well, and use that in copy operation.
Comment 21 Ryosuke Niwa 2022-12-08 21:17:11 PST
Created attachment 463953 [details]
Test case

Based on this test case, Chrome includes the content with -webkit-user-select: none in the clipboard content.
Comment 22 tellowkrinkle 2022-12-10 12:45:49 PST
It seems to only include it in the html clipboard content, if you paste with "paste and match formatting" (shift-cmd-option-v) it pastes without the unselectable text.

This happens to match my specific use case (marking <rp> and <rt> tags as unselectable), where I would want the tags copied in html but not in plain text, but I don't think that's what user-select was really meant for.
Comment 23 Ryosuke Niwa 2022-12-11 23:21:24 PST
Pull request: https://github.com/WebKit/WebKit/pull/7467
Comment 24 EWS 2022-12-12 11:40:58 PST
Committed 257749@main (166aef896770): <https://commits.webkit.org/257749@main>

Reviewed commits have been landed. Closing PR #7467 and removing active labels.