Bug 184844 - Clients implementing _webView:focusShouldStartInputSession: can't easily express the "default" behavior
Summary: Clients implementing _webView:focusShouldStartInputSession: can't easily expr...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Forms (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Paul Knight
URL:
Keywords: InRadar
Depends on:
Blocks: 184867
  Show dependency treegraph
 
Reported: 2018-04-20 15:13 PDT by Paul Knight
Modified: 2018-04-22 14:39 PDT (History)
7 users (show)

See Also:


Attachments
Patch (5.75 KB, patch)
2018-04-21 14:17 PDT, Paul Knight
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Knight 2018-04-20 15:13:58 PDT
If a client doesn't implement -[_WKInputDelegate's _webView:focusShouldStartInputSession:], there's a sophisticated default behavior that reads something like "Assist the form node if the gesture was user driven or they keyboard is already active or drag and drop is performing a drop action".

This rule can't really be reimplemented by the client, so a client can't allow programmatic focus in some circumstances but use the default behavior otherwise.
Comment 1 Radar WebKit Bug Importer 2018-04-20 15:14:48 PDT
<rdar://problem/39610958>
Comment 2 Paul Knight 2018-04-21 14:17:17 PDT
Created attachment 338539 [details]
Patch
Comment 3 Paul Knight 2018-04-21 14:19:00 PDT
One thing I'm not sure about is how to go about marking -_webView:focusShouldStartInputSession: as deprecated. Should we do it now, or only once _webView:decidePolicyForFocusedElement: ships?
Comment 4 Wenson Hsieh 2018-04-21 14:44:35 PDT
(In reply to Paul Knight from comment #3)
> One thing I'm not sure about is how to go about marking
> -_webView:focusShouldStartInputSession: as deprecated. Should we do it now,
> or only once _webView:decidePolicyForFocusedElement: ships?

I think we could do it as a followup, before new SPI ships. Luckily, there only appears to be one other internal client aside from Safari that uses -_webView:focusShouldStartInputSession:, so it should be simple to reach out to them and get them to adopt the new SPI before we mark the old one as deprecated.

This looks reasonable to me! Perhaps the names could be tweaked a bit (I considered -decidePolicyForStartingInputSessionWithFocusedElement:, but that seemed a bit verbose). Adding a couple more WK2 owners to get more opinions...
Comment 5 mitz 2018-04-22 11:52:41 PDT
Comment on attachment 338539 [details]
Patch

For something where there’s a default behavior and a way to customize it, subclassing is usually nicer than delegation—you can just call super, if you want, see “what would have happened”, and then customize the behavior.
Comment 6 Paul Knight 2018-04-22 11:58:54 PDT
What would you subclass in this case?
Comment 7 mitz 2018-04-22 13:33:47 PDT
(In reply to Paul Knight from comment #6)
> What would you subclass in this case?

WKWebView. Specifically in this case, one can envision

@interface WKWebView
- (BOOL)focusShouldStartInputSession:(id <_WKFocusedElementInfo>)info;
@end

with a client’s WKWebView subclass override doing something like

- (BOOL)focusShouldStartInputSession:(id <_WKFocusedElementInfo>)info
{
    if ([super focusShouldStartInputSession:info])
        return YES;
    if (/* something special is going on */)
        return YES;
    return NO;
}
Comment 8 Paul Knight 2018-04-22 14:09:30 PDT
Th(In reply to mitz from comment #7)
> (In reply to Paul Knight from comment #6)
> > What would you subclass in this case?
> 
> WKWebView. Specifically in this case, one can envision
> 
> @interface WKWebView
> - (BOOL)focusShouldStartInputSession:(id <_WKFocusedElementInfo>)info;
> @end

This is a really good thought, and I'm not sure how to square it with some of the other existing _WKInputDelegate methods. A client that overrides focusShouldStartInputSession may also be interested in the input session that then starts, possibly splitting its logic into different places.

Maybe we can pursue the subclass hook as this transitions to API, for example as part of bug 142757?
Comment 9 Wenson Hsieh 2018-04-22 14:11:13 PDT
(In reply to mitz from comment #7)
> (In reply to Paul Knight from comment #6)
> > What would you subclass in this case?
> 
> WKWebView. Specifically in this case, one can envision
> 
> @interface WKWebView
> - (BOOL)focusShouldStartInputSession:(id <_WKFocusedElementInfo>)info;
> @end
> 
> with a client’s WKWebView subclass override doing something like
> 
> - (BOOL)focusShouldStartInputSession:(id <_WKFocusedElementInfo>)info
> {
>     if ([super focusShouldStartInputSession:info])
>         return YES;
>     if (/* something special is going on */)
>         return YES;
>     return NO;
> }

Good point! I think this is definitely something to consider when we address <rdar://problem/17355265>. Paul brought up the point that for the client adopting this SPI, it makes the input session customization story less cohesive if some of the input delegate hooks are on the WKWebView, and others are on the _WKInputDelegate.

Perhaps the line in the sand is whether or not we have an input session yet? So we have a subclass-able hook on WKWebView prior to starting the input session, and then _WKInputDelegate would then handle logic related to input sessions (maybe we should then rename it to WKInputSessionDelegate).
Comment 10 WebKit Commit Bot 2018-04-22 14:39:35 PDT
Comment on attachment 338539 [details]
Patch

Clearing flags on attachment: 338539

Committed r230902: <https://trac.webkit.org/changeset/230902>
Comment 11 WebKit Commit Bot 2018-04-22 14:39:36 PDT
All reviewed patches have been landed.  Closing bug.