Bug 215647

Summary: Programmatic selection of text in a text field causes the highlight overlay to spill out
Product: WebKit Reporter: Simon Fraser (smfr) <simon.fraser>
Component: HTML EditingAssignee: Wenson Hsieh <wenson_hsieh>
Status: RESOLVED FIXED    
Severity: Normal CC: cdumez, changseok, darin, esprehn+autocc, ews-watchlist, gyuyoung.kim, megan_gardner, mifenton, simon.fraser, thorton, webkit-bug-importer, wenson_hsieh
Priority: P2 Keywords: InRadar
Version: Safari Technology Preview   
Hardware: Unspecified   
OS: Unspecified   
URL: https://codepen.io/ShaneHudson/pen/bGpeVPG
Attachments:
Description Flags
Patch
darin: review+
Patch none

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