Bug 218585 - autofocus of text input should not select text
Summary: autofocus of text input should not select text
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Forms (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Devin Rousso
URL: data:text/html,<input type=text value...
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-11-04 14:31 PST by Devin Rousso
Modified: 2020-11-09 11:08 PST (History)
13 users (show)

See Also:


Attachments
Patch (34.41 KB, patch)
2020-11-04 16:42 PST, Devin Rousso
no flags Details | Formatted Diff | Diff
Patch (15.66 KB, patch)
2020-11-05 13:38 PST, Devin Rousso
no flags Details | Formatted Diff | Diff
Patch (19.14 KB, patch)
2020-11-05 16:43 PST, Devin Rousso
no flags Details | Formatted Diff | Diff
Patch (20.03 KB, patch)
2020-11-06 10:11 PST, Devin Rousso
no flags Details | Formatted Diff | Diff
Patch (23.01 KB, patch)
2020-11-06 14:23 PST, Devin Rousso
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Devin Rousso 2020-11-04 14:31:53 PST
this appears to be longstanding behavior of WebKit (`HTMLInputElement::updateFocusAppearance` calls `select` or something with an equivalent effect), but I'm not really sure why

both Chrome and Firefox do not have this behavior
Comment 1 Devin Rousso 2020-11-04 14:32:11 PST
<rdar://problem/60130704>
Comment 2 Devin Rousso 2020-11-04 16:42:18 PST
Created attachment 413223 [details]
Patch
Comment 3 Devin Rousso 2020-11-05 13:38:06 PST
Created attachment 413351 [details]
Patch

my initial attempt had more behavior change "ripples" than i'd anticipated, so here's another approach that's (hopefully) far more targeted in behavior change

putting this up before writing tests to see if EWS still has issues with this approach
Comment 4 Devin Rousso 2020-11-05 16:43:39 PST
Created attachment 413371 [details]
Patch
Comment 5 Devin Rousso 2020-11-06 10:11:04 PST
Created attachment 413442 [details]
Patch
Comment 6 Wenson Hsieh 2020-11-06 12:44:53 PST
Comment on attachment 413442 [details]
Patch

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

> Source/WebCore/dom/Document.h:292
> +    Restore, // If there is no previous selection, this behaves like SelectAll.

Nit - it's a little more verbose, but maybe `RestoreOrSelectAll`? (and remove the comment)

> Source/WebCore/dom/Document.h:293
> +    PlaceCursorAtStart,

Also, this should be (selection) Caret, not (mouse) Cursor :P

> LayoutTests/fast/forms/input-text-autofocus.html:27
> +    shouldBe("input.selectionStart", UIHelper.isIOSFamily() ? "3" : "0");
> +    shouldBe("input.selectionEnd", UIHelper.isIOSFamily() ? "3" : "0");

We generally try to avoid platform-specific logic like this in tests, if possible. Can we just override the editing behavior instead, and make all platforms yield the same results?
Comment 7 Devin Rousso 2020-11-06 14:23:08 PST
Created attachment 413483 [details]
Patch
Comment 8 EWS 2020-11-09 11:08:54 PST
Committed r269587: <https://trac.webkit.org/changeset/269587>

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