Bug 215647 - Programmatic selection of text in a text field causes the highlight overlay to spill out
Summary: Programmatic selection of text in a text field causes the highlight overlay t...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: HTML Editing (show other bugs)
Version: Safari Technology Preview
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Wenson Hsieh
URL: https://codepen.io/ShaneHudson/pen/bG...
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-08-19 08:31 PDT by Simon Fraser (smfr)
Modified: 2020-08-23 18:52 PDT (History)
12 users (show)

See Also:


Attachments
Patch (29.53 KB, patch)
2020-08-23 13:31 PDT, Wenson Hsieh
darin: review+
Details | Formatted Diff | Diff
Patch (29.73 KB, patch)
2020-08-23 15:19 PDT, Wenson Hsieh
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Fraser (smfr) 2020-08-19 08:31:54 PDT
Testcase at <https://codepen.io/ShaneHudson/pen/bGpeVPG> shows an issue where the selection is not clipped to the bounds of the text input.
Comment 1 Radar WebKit Bug Importer 2020-08-19 08:32:16 PDT
<rdar://problem/67404979>
Comment 2 Simon Fraser (smfr) 2020-08-19 08:32:25 PDT
Noted at https://twitter.com/ShaneHudson/status/1296078597652914177
Comment 3 Wenson Hsieh 2020-08-19 08:35:32 PDT
This is likely because -[WKContentView _selectionClipRect] returns the null rect, since we're not showing any input view for a focused element.
Comment 4 Wenson Hsieh 2020-08-21 16:49:11 PDT
(Note: one way to work around this is to programmatically focus() the readonly input before calling select() on it)
Comment 5 Wenson Hsieh 2020-08-23 13:31:09 PDT
Created attachment 407080 [details]
Patch
Comment 6 Darin Adler 2020-08-23 13:46:58 PDT
Comment on attachment 407080 [details]
Patch

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

> Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm:796
> +    auto selectionClipRect = [(UIView <UITextInputPrivate> *)contentView _selectionClipRect];

Casting to a type with a protocol without checking if the view implements the protocol seems peculiar. Normally we’d call respondsToProtocol in a case like this. Alternatively we could assert that and comment why we know it’s true. Or could leave it just like this if you prefer.
Comment 7 Wenson Hsieh 2020-08-23 14:49:36 PDT
Comment on attachment 407080 [details]
Patch

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

Thanks for the review!

>> Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm:796
>> +    auto selectionClipRect = [(UIView <UITextInputPrivate> *)contentView _selectionClipRect];
> 
> Casting to a type with a protocol without checking if the view implements the protocol seems peculiar. Normally we’d call respondsToProtocol in a case like this. Alternatively we could assert that and comment why we know it’s true. Or could leave it just like this if you prefer.

Sounds good — I'll add an assertion and comment here.
Comment 8 Wenson Hsieh 2020-08-23 15:19:59 PDT
Created attachment 407082 [details]
Patch
Comment 9 EWS 2020-08-23 18:52:01 PDT
Committed r266051: <https://trac.webkit.org/changeset/266051>

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