Bug 190977 - '-webkit-user-select: all' is not respected in editable views
Summary: '-webkit-user-select: all' is not respected in editable views
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: HTML Editing (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Tim Horton
URL:
Keywords: InRadar
: 72019 (view as bug list)
Depends on:
Blocks:
 
Reported: 2018-10-26 16:18 PDT by Tim Horton
Modified: 2022-02-17 17:05 PST (History)
18 users (show)

See Also:


Attachments
Patch (20.60 KB, patch)
2018-10-26 16:19 PDT, Tim Horton
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews100 for mac-sierra (2.65 MB, application/zip)
2018-10-26 17:27 PDT, EWS Watchlist
no flags Details
Archive of layout-test-results from ews107 for mac-sierra-wk2 (3.23 MB, application/zip)
2018-10-26 17:38 PDT, EWS Watchlist
no flags Details
Archive of layout-test-results from ews200 for win-future (13.08 MB, application/zip)
2018-10-26 18:05 PDT, EWS Watchlist
no flags Details
Archive of layout-test-results from ews115 for mac-sierra (3.32 MB, application/zip)
2018-10-26 18:23 PDT, EWS Watchlist
no flags Details
Archive of layout-test-results from ews112 for mac-sierra (3.32 MB, application/zip)
2018-10-26 20:22 PDT, EWS Watchlist
no flags Details
Archive of layout-test-results from ews125 for ios-simulator-wk2 (2.88 MB, application/zip)
2018-10-26 21:43 PDT, EWS Watchlist
no flags Details
Archive of layout-test-results from ews122 for ios-simulator-wk2 (2.90 MB, application/zip)
2018-10-26 23:38 PDT, EWS Watchlist
no flags Details
Patch (20.30 KB, patch)
2018-10-29 13:11 PDT, Tim Horton
no flags Details | Formatted Diff | Diff
Updated for trunk (18.32 KB, patch)
2019-04-12 21:04 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews126 for ios-simulator-wk2 (17.13 MB, application/zip)
2019-04-12 23:11 PDT, EWS Watchlist
no flags Details
Patch (27.16 KB, patch)
2022-02-14 15:34 PST, Aditya Keerthi
no flags Details | Formatted Diff | Diff
Patch (27.17 KB, patch)
2022-02-14 16:08 PST, Aditya Keerthi
no flags Details | Formatted Diff | Diff
Patch (28.92 KB, patch)
2022-02-14 17:54 PST, Aditya Keerthi
no flags Details | Formatted Diff | Diff
Patch (35.38 KB, patch)
2022-02-14 20:53 PST, Aditya Keerthi
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (35.57 KB, patch)
2022-02-14 21:26 PST, Aditya Keerthi
wenson_hsieh: review+
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch for landing (35.98 KB, patch)
2022-02-15 15:17 PST, Aditya Keerthi
no flags Details | Formatted Diff | Diff
Patch for landing (37.10 KB, patch)
2022-02-15 20:46 PST, Aditya Keerthi
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tim Horton 2018-10-26 16:18:32 PDT
'-webkit-user-select: all' is not respected in editable views
Comment 1 Tim Horton 2018-10-26 16:19:00 PDT
Created attachment 353209 [details]
Patch
Comment 2 Tim Horton 2018-10-26 16:19:02 PDT
<rdar://problem/34945944>
Comment 3 EWS Watchlist 2018-10-26 17:27:49 PDT Comment hidden (obsolete)
Comment 4 EWS Watchlist 2018-10-26 17:27:55 PDT Comment hidden (obsolete)
Comment 5 EWS Watchlist 2018-10-26 17:38:01 PDT Comment hidden (obsolete)
Comment 6 EWS Watchlist 2018-10-26 17:38:04 PDT Comment hidden (obsolete)
Comment 7 EWS Watchlist 2018-10-26 18:05:20 PDT Comment hidden (obsolete)
Comment 8 EWS Watchlist 2018-10-26 18:05:31 PDT Comment hidden (obsolete)
Comment 9 Tim Horton 2018-10-26 18:22:13 PDT
I guess I'll undo the designmode bit
Comment 10 EWS Watchlist 2018-10-26 18:23:41 PDT Comment hidden (obsolete)
Comment 11 EWS Watchlist 2018-10-26 18:23:43 PDT Comment hidden (obsolete)
Comment 12 EWS Watchlist 2018-10-26 20:22:27 PDT Comment hidden (obsolete)
Comment 13 EWS Watchlist 2018-10-26 20:22:29 PDT Comment hidden (obsolete)
Comment 14 EWS Watchlist 2018-10-26 21:43:41 PDT Comment hidden (obsolete)
Comment 15 EWS Watchlist 2018-10-26 21:43:43 PDT Comment hidden (obsolete)
Comment 16 EWS Watchlist 2018-10-26 23:38:51 PDT Comment hidden (obsolete)
Comment 17 EWS Watchlist 2018-10-26 23:38:53 PDT Comment hidden (obsolete)
Comment 18 Darin Adler 2018-10-26 23:46:24 PDT
Comment on attachment 353209 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=353209&action=review

> Source/WebCore/dom/Node.cpp:778
> +    bool documentIsEditable = document.frame() && document.frame()->page() && document.frame()->page()->isEditable();
> +    if (is<HTMLDocument>(document))
> +        documentIsEditable |= downcast<HTMLDocument>(document).inDesignMode();

This (and the existing code that this was moved from) is peculiar. The inDesignMode function is in Document. Maybe at the original time the code was written it was specific to HTMLDocument. I think we should remove the is<HTMLDocument> check and the downcast as well.

> Tools/DumpRenderTree/mac/UIScriptControllerMac.mm:203
> +    WebView *webView = [mainFrame webView];
> +    [webView setEditable:editable];

Not sure we really need a local variable here.
Comment 19 Ryosuke Niwa 2018-10-28 11:07:15 PDT
Comment on attachment 353209 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=353209&action=review

> Source/WebCore/dom/Node.cpp:751
> +        if (documentIsEditable)
> +            return Node::Editability::CanEditRichly;
> +

This isn't right. It's totally possible to have -webkit-user-modify: read-only inside a design mode document.
As done in editabilityFromContentEditableAttr, we need to wait until we get out of this loop.
r- because of this and the test failures.
Comment 20 Tim Horton 2018-10-29 13:11:11 PDT
Created attachment 353313 [details]
Patch
Comment 21 Tim Horton 2018-10-29 13:16:57 PDT
(In reply to Ryosuke Niwa from comment #19)
> Comment on attachment 353209 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=353209&action=review
> 
> > Source/WebCore/dom/Node.cpp:751
> > +        if (documentIsEditable)
> > +            return Node::Editability::CanEditRichly;
> > +
> 
> This isn't right. It's totally possible to have -webkit-user-modify:
> read-only inside a design mode document.

But not inside an editable=YES web view. So like I promised in an earlier comment, I reverted the design-mode-related changes, which were unnecessary in the first place.

> As done in editabilityFromContentEditableAttr, we need to wait until we get
> out of this loop.

I don't think that works? We need to bail here in the editable web view case, or we'll respect user-modify there (which defaults to read-only, and thus breaks editable=YES). I made documentIsEditable just about editable=YES, so it should be OK. We're just moving the editable check downstream, past the user-select checks, instead of affecting user-modify at all.

> r- because of this and the test failures.
Comment 22 Ryosuke Niwa 2018-11-05 19:15:32 PST
Comment on attachment 353313 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=353313&action=review

r=me once the following amendments are made.

> Source/WebCore/html/HTMLElement.cpp:407
>      if (auto* startElement = is<Element>(node) ? &downcast<Element>(node) : node.parentElement()) {
>          for (auto& element : lineageOfType<HTMLElement>(*startElement)) {

This loop has the same issue as computeEditabilityFromComputedStyle.
You need to add a check for documentIsEditable before the switch.
Also, please add a test (add a test where the web view is editable & there is a contenteditable=false content.
Make sure that content is editable. We should also add a test for -webkit-user-modify at the same time too.

> Source/WebCore/html/HTMLElement.cpp:433
> -    return editabilityFromContentEditableAttr(*this) != Editability::ReadOnly;
> +    return editabilityFromContentEditableAttr(*this, false) != Editability::ReadOnly;

Please add an enum class instead of using a boolean like this.

> LayoutTests/ChangeLog:10
> +        * editing/selection/user-select-all-in-editable-view-expected.txt: Added.
> +        * editing/selection/user-select-all-in-editable-view.html: Added.

A better place to put more tests I'm asking you to add would be LayoutTests/editing/editability/
But I suppose these tests could stay here.

> LayoutTests/editing/selection/user-select-all-in-editable-view.html:4
> +<p id="description">This tests that moving the cursor inside a 'user-select: all' element expands the selection to the entire element. The cursor should not end up inside the 'user-select: all' element, but rather in the middle of "after".</p>

Please add an instruction on how to run this test manually in the browser.
e.g. you can execute setBaseAndExtent outside testRunner / UI helper check.
Otherwise, it's gonna be really hard to verify that it works in the browser later.
Comment 23 Ryosuke Niwa 2019-03-15 16:14:58 PDT
Can we land this patch??
Comment 24 Tim Horton 2019-03-15 16:32:30 PDT
(In reply to Ryosuke Niwa from comment #23)
> Can we land this patch??

Go for it!
Comment 25 Ryosuke Niwa 2019-04-12 21:04:03 PDT
Created attachment 367376 [details]
Updated for trunk
Comment 26 Ryosuke Niwa 2019-04-12 21:04:33 PDT
The new patch still has the issues I pointed out earlier.
Comment 27 EWS Watchlist 2019-04-12 23:11:21 PDT
Comment on attachment 367376 [details]
Updated for trunk

Attachment 367376 [details] did not pass ios-sim-ews (ios-simulator-wk2):
Output: https://webkit-queues.webkit.org/results/11860969

New failing tests:
editing/input/ios/rtl-keyboard-input-on-focus.html
Comment 28 EWS Watchlist 2019-04-12 23:11:24 PDT
Created attachment 367379 [details]
Archive of layout-test-results from ews126 for ios-simulator-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews126  Port: ios-simulator-wk2  Platform: Mac OS X 10.13.6
Comment 29 Tim Nguyen (:ntim) 2021-10-20 03:17:35 PDT
*** Bug 72019 has been marked as a duplicate of this bug. ***
Comment 30 Aditya Keerthi 2022-02-14 15:34:40 PST
Created attachment 451950 [details]
Patch
Comment 31 Aditya Keerthi 2022-02-14 15:35:02 PST
Comment on attachment 451950 [details]
Patch

Latest patch addresses review comments and adds additional tests.
Comment 32 Wenson Hsieh 2022-02-14 15:56:05 PST
Comment on attachment 451950 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=451950&action=review

> Source/WebCore/dom/Node.cpp:796
> +    auto& document = this->document();

This raw reference makes me a bit nervous, especially since we trigger a style update right below.

But maybe it's okay here because the caller presumably keeps this node alive, which then keeps its document alive?

> Tools/ChangeLog:11
> +        Remove TestRunner::setWebViewEditable as it is used.

Nit - do you mean "unused"?
Comment 33 Darin Adler 2022-02-14 15:57:23 PST
Comment on attachment 451950 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=451950&action=review

>> Source/WebCore/dom/Node.cpp:796
>> +    auto& document = this->document();
> 
> This raw reference makes me a bit nervous, especially since we trigger a style update right below.
> 
> But maybe it's okay here because the caller presumably keeps this node alive, which then keeps its document alive?

No, you are right to be worried. Nodes can be moved between documents.
Comment 34 Aditya Keerthi 2022-02-14 16:08:20 PST
Created attachment 451955 [details]
Patch
Comment 35 Aditya Keerthi 2022-02-14 16:09:18 PST
(In reply to Wenson Hsieh from comment #32)
> Comment on attachment 451950 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=451950&action=review
> 
> > Source/WebCore/dom/Node.cpp:796
> > +    auto& document = this->document();
> 
> This raw reference makes me a bit nervous, especially since we trigger a
> style update right below.
> 
> But maybe it's okay here because the caller presumably keeps this node
> alive, which then keeps its document alive?

Made this a `Ref`.
 
> > Tools/ChangeLog:11
> > +        Remove TestRunner::setWebViewEditable as it is used.
> 
> Nit - do you mean "unused"?

Fixed.
Comment 36 Aditya Keerthi 2022-02-14 17:54:34 PST
Created attachment 451973 [details]
Patch
Comment 37 Aditya Keerthi 2022-02-14 20:53:35 PST
Created attachment 451989 [details]
Patch
Comment 38 Aditya Keerthi 2022-02-14 20:54:10 PST
Comment on attachment 451989 [details]
Patch

Attempting to implement UIScriptController hooks on GTK.
Comment 39 Aditya Keerthi 2022-02-14 21:26:53 PST
Created attachment 451992 [details]
Patch
Comment 40 Wenson Hsieh 2022-02-15 12:09:28 PST
Comment on attachment 451992 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=451992&action=review

> Source/WebCore/dom/Node.cpp:797
> +    auto documentIsEditable = document->page() && document->page()->isEditable() ? DocumentIsEditable::Yes : DocumentIsEditable::No;

`DocumentIsEditable` seems okay to me, but I think a name like `PageIsEditable` would be a bit more explicit, since this concept of "full web view editability" is scoped to the entire Page/WebPage rather than Document. I think it might also help to disambiguate it from the case where `document.designMode` is "on".

> LayoutTests/editing/editability/user-select-all-in-editable-view.html:17
> +        var selection = window.getSelection();
> +        selection.setBaseAndExtent(container, 0, container, 0);

Nit - I think this comment should still be addressed:

> Please add an instruction on how to run this test manually in the browser.
> e.g. you can execute setBaseAndExtent outside testRunner / UI helper check.

While this test won't work in Safari due to requiring `-_setEditable:YES` on the web view, someone who's running the test manually could still run it manually using the Editable web view mode of MiniBrowser to exercise the behavior.
I think we can wrap this in an async function block and do something like:

…

if (window.testRunner && testRunner.runUIScript)
    await UIHelper.setWebViewEditable(true);

const selection = window.getSelection();
selection.setPosition(container, 0);

…

(with a note in the description paragraph above reminding the user to test in an editable web view if they're going to test manually).
Comment 41 Aditya Keerthi 2022-02-15 15:17:07 PST
Created attachment 452099 [details]
Patch for landing
Comment 42 Aditya Keerthi 2022-02-15 15:18:46 PST
(In reply to Wenson Hsieh from comment #40)
> Comment on attachment 451992 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=451992&action=review

Thanks for the review!
 
> > Source/WebCore/dom/Node.cpp:797
> > +    auto documentIsEditable = document->page() && document->page()->isEditable() ? DocumentIsEditable::Yes : DocumentIsEditable::No;
> 
> `DocumentIsEditable` seems okay to me, but I think a name like
> `PageIsEditable` would be a bit more explicit, since this concept of "full
> web view editability" is scoped to the entire Page/WebPage rather than
> Document. I think it might also help to disambiguate it from the case where
> `document.designMode` is "on".

Changed to `PageIsEditable`.
 
> > LayoutTests/editing/editability/user-select-all-in-editable-view.html:17
> > +        var selection = window.getSelection();
> > +        selection.setBaseAndExtent(container, 0, container, 0);
> 
> Nit - I think this comment should still be addressed:
> 
> > Please add an instruction on how to run this test manually in the browser.
> > e.g. you can execute setBaseAndExtent outside testRunner / UI helper check.
> 
> While this test won't work in Safari due to requiring `-_setEditable:YES` on
> the web view, someone who's running the test manually could still run it
> manually using the Editable web view mode of MiniBrowser to exercise the
> behavior.
> I think we can wrap this in an async function block and do something like:
> 
> …
> 
> if (window.testRunner && testRunner.runUIScript)
>     await UIHelper.setWebViewEditable(true);
> 
> const selection = window.getSelection();
> selection.setPosition(container, 0);
> 
> …
> 
> (with a note in the description paragraph above reminding the user to test
> in an editable web view if they're going to test manually).

Updated all tests.
Comment 43 Aditya Keerthi 2022-02-15 20:46:05 PST
Created attachment 452134 [details]
Patch for landing
Comment 44 EWS 2022-02-17 17:05:08 PST
Committed r290098 (247447@main): <https://commits.webkit.org/247447@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 452134 [details].