RESOLVED FIXED190621
[iOS] [Datalist] Can't pick datalist suggestions in a stock WKWebView
https://bugs.webkit.org/show_bug.cgi?id=190621
Summary [iOS] [Datalist] Can't pick datalist suggestions in a stock WKWebView
Wenson Hsieh
Reported 2018-10-16 09:19:59 PDT Comment hidden (obsolete)
Attachments
Patch (27.75 KB, patch)
2018-10-18 21:09 PDT, Wenson Hsieh
no flags
EWS run (30.21 KB, patch)
2018-10-19 10:56 PDT, Wenson Hsieh
no flags
Radar WebKit Bug Importer
Comment 1 2018-10-16 10:42:21 PDT
Wenson Hsieh
Comment 2 2018-10-18 16:52:29 PDT
As it turns out, the datalist suggestions dropdown doesn't quite work in a plain WKWebView unless the WKWebView has a _WKInputDelegate that responds to -_webView:(did|will)StartInputSession:, since it depends on WebKit creating a _WKFormInputSession that we can specify a customInputView with text suggestions. We should refactor this slightly to decouple datalists from _WKFormInputSession.
Wenson Hsieh
Comment 3 2018-10-18 20:37:05 PDT
Renaming to track the above issue (with a test fix for fast/forms/datalist/datalist-textinput-suggestions-order.html en route to fixing the bug).
Wenson Hsieh
Comment 4 2018-10-18 21:09:46 PDT
Tim Horton
Comment 5 2018-10-18 21:31:51 PDT
Comment on attachment 352762 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=352762&action=review > Source/WebKit/UIProcess/ios/WKContentViewInteraction.h:253 > + RetainPtr<UIView<WKFormControl>> _dataListTextSuggestionsInputView; > + RetainPtr<NSArray<UITextSuggestion *>> _dataListTextSuggestions; Sooooooo I don't know if WebKit style has a preference, but I usually go with "Class <ConformsToProtocol>" but "Class<GenericType>". AppKit public headers seem to agree. > Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:398 > + if (suggestions == _suggestions || [suggestions isEqualToArray:_suggestions.get()]) This reads humorously but I think it's right since you want nil to compare equal. > Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:4805 > + // Text suggestions vended from internal clients take precedence over text suggestions from a focused form control with a datalist. Why "internal" clients? What does that even mean? Aren't clients external by definition? > Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:4808 > + if ([_formInputSession suggestions].count) { > + [inputDelegate setSuggestions:[_formInputSession suggestions]]; If I'm reading this right, `suggestions` calls straight to the client, so you should definitely only call it once and store the result here; no need to be so chatty with the client! > Tools/WebKitTestRunner/UIScriptControllerCocoa.mm:48 > + [TestController::singleton().mainWebView()->platformView() resignFirstResponder]; Do we ... fix this ... when the next test starts?
Wenson Hsieh
Comment 6 2018-10-19 09:03:34 PDT
Comment on attachment 352762 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=352762&action=review >> Source/WebKit/UIProcess/ios/WKContentViewInteraction.h:253 >> + RetainPtr<NSArray<UITextSuggestion *>> _dataListTextSuggestions; > > Sooooooo I don't know if WebKit style has a preference, but I usually go with "Class <ConformsToProtocol>" but "Class<GenericType>". AppKit public headers seem to agree. Ah, ok. (If I understand correctly, you mean this should be `RetainPtr<UIView <WKFormControl>>` and `RetainPtr<NSArray<UITextSuggestion *>>`?) >> Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:398 >> + if (suggestions == _suggestions || [suggestions isEqualToArray:_suggestions.get()]) > > This reads humorously but I think it's right since you want nil to compare equal. Yep, that was the intention! >> Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:4805 >> + // Text suggestions vended from internal clients take precedence over text suggestions from a focused form control with a datalist. > > Why "internal" clients? What does that even mean? Aren't clients external by definition? Oops, I really meant clients of our SPI (here at Apple). Changed "internal clients" to just "clients". >> Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:4808 >> + [inputDelegate setSuggestions:[_formInputSession suggestions]]; > > If I'm reading this right, `suggestions` calls straight to the client, so you should definitely only call it once and store the result here; no need to be so chatty with the client! Hm...do you mean the call to `[_formInputSession suggestions]`? The concrete class (WKFormInputSession) implements -suggestions as a simple RetainPtr::get(), so I don't think we'll be double-calling our client here. But it's probably still a good idea to stash the result in a temporary though, so I changed this to only call -suggestions once. >> Tools/WebKitTestRunner/UIScriptControllerCocoa.mm:48 >> + [TestController::singleton().mainWebView()->platformView() resignFirstResponder]; > > Do we ... fix this ... when the next test starts? 🤔 good point. We should probably ensure that we're first responder when we reset the web view to a consistent state in WKTR. My understanding is that layout tests shouldn't actually care whether the web view is FR prior to running the test. The relatively few tests that do care (e.g. tests that insert text in a text field) would all do something to ensure that the web view is FR, if necessary (e.g. by tapping something on the web view).
Wenson Hsieh
Comment 7 2018-10-19 10:06:35 PDT
(In reply to Wenson Hsieh from comment #6) > (…) > >> Tools/WebKitTestRunner/UIScriptControllerCocoa.mm:48 > >> + [TestController::singleton().mainWebView()->platformView() resignFirstResponder]; > > > > Do we ... fix this ... when the next test starts? > > 🤔 good point. We should probably ensure that we're first responder when we > reset the web view to a consistent state in WKTR (…) So we do (in fact) try to become first responder on macOS when resetting to a consistent state, inside of TestController::resetStateToConsistentValues (see the call to `m_mainWebView->focus()`). However, this turns around and calls `PlatformWebView::makeWebViewFirstResponder()` which, on iOS, is just a stub. I think we just need to implement this stub (and fix one other edge case on iOS where we might continue onto the next test without being FR).
Wenson Hsieh
Comment 8 2018-10-19 10:56:07 PDT
WebKit Commit Bot
Comment 9 2018-10-19 15:00:40 PDT
Comment on attachment 352802 [details] EWS run Clearing flags on attachment: 352802 Committed r237305: <https://trac.webkit.org/changeset/237305>
WebKit Commit Bot
Comment 10 2018-10-19 15:00:42 PDT
All reviewed patches have been landed. Closing bug.
Note You need to log in before you can comment on or make changes to this bug.