Bug 210230

Summary: Popovers are dismissed immediately when they try and bring up the keyboard.
Product: WebKit Reporter: Megan Gardner <megan_gardner>
Component: New BugsAssignee: Megan Gardner <megan_gardner>
Status: RESOLVED FIXED    
Severity: Normal CC: darin, thorton, webkit-bug-importer, wenson_hsieh
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch for landing none

Description Megan Gardner 2020-04-08 17:32:02 PDT
Correctly retain focus when popovers employ keyboard
Comment 1 Megan Gardner 2020-04-08 17:36:58 PDT
Created attachment 395890 [details]
Patch
Comment 2 Megan Gardner 2020-04-08 17:37:20 PDT
<rdar://problem/60385504>
Comment 3 Darin Adler 2020-04-09 12:56:51 PDT
Comment on attachment 395890 [details]
Patch

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

Any way to make a test for this?

> Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:6669
> +- (void)preserveFocus
> +{
> +    [_webView _incrementFocusPreservationCount];
> +}
> +
> +- (void)releaseFocus
> +{
> +    [_webView _decrementFocusPreservationCount];
> +}

Is there any risk that a WKContentView could be deallocated before releaseFocus is called, or have _webView set to null or any new value before this is called?

Often, designs like this one can be dangerous if a stale count can be left behind. There are techniques to make them more resilient, like using objects and weak pointers, that are most costly but more foolproof.

> Source/WebKit/UIProcess/ios/forms/WKFormInputControl.mm:341
> +        if (_view.focusedElementInformation.elementType == InputType::Time || _view.focusedElementInformation.elementType == InputType::DateTimeLocal)
> +            [_view releaseFocus];

Maybe we could use a boolean _preservingFocus rather than repeating this check here. That way there’s no risk of the check in controlBeginEditing being out of sync with this one.
Comment 4 Megan Gardner 2020-04-09 16:17:45 PDT
Created attachment 396022 [details]
Patch for landing
Comment 5 Darin Adler 2020-04-09 16:34:23 PDT
Comment on attachment 396022 [details]
Patch for landing

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

> Source/WebKit/UIProcess/ios/forms/WKFormInputControl.mm:393
> +            _preservingFocus = YES;
> +            [_view preserveFocus];

Could harden this slightly by wrapping this in:

    if (!_preservingFocus) {
    }
Comment 6 EWS 2020-04-09 16:58:55 PDT
Committed r259840: <https://trac.webkit.org/changeset/259840>

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