Expose a WKWebView API for allowing programmatic focus to trigger node assistance
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 28 Sep 2015 13:53:40 +0000 (13:53 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 28 Sep 2015 13:53:40 +0000 (13:53 +0000)
commitcd5a6a566bab14ac54a49ef4cc94e7497f0565bb
tree50f408f7fbc6c913b1487d07f020b1551d4f60da
parenta9bf2f2a60076cb6b98d91856ef1510643bf4095
Expose a WKWebView API for allowing programmatic focus to trigger node assistance
https://bugs.webkit.org/show_bug.cgi?id=149567

Reviewed by Darin Adler.

Adds an API method to WKWebView that allows clients to override the default iOS behavior of not
starting node assistance when programmatically focusing. Also fixes a bug caused by naively
introducing the flag where the autofocus attribute could trigger node assistance before layout
occurs, causing an ASSERT to fail in EditorState::postLayoutData.

I fixed this issue by not assisting the node if the editor state is missing post layout data,
instead deferring node assistance until layout has occurred.

* UIProcess/API/Cocoa/WKWebView.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView initWithFrame:configuration:]): Initializes the new node assistance flag to NO, which
    is the current default behavior.
(-[WKWebView canAssistOnProgrammaticFocus]):
(-[WKWebView setCanAssistOnProgrammaticFocus:]): New API method that allows clients to set node
    assistance behavior upon programmatic focus.
* UIProcess/API/Cocoa/WKWebViewConfiguration.h:
* UIProcess/API/Cocoa/WKWebViewConfiguration.mm:
(-[WKWebViewConfiguration init]): Added new node assistance flag to configuration.
(-[WKWebViewConfiguration _canAssistOnProgrammaticFocus]):
(-[WKWebViewConfiguration _setCanAssistOnProgrammaticFocus:]):
* UIProcess/WebPageProxy.h: Added NodeAssistanceArguments struct.
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _startAssistingNode:userIsInteracting:blurPreviousNode:userObject:]): Do not return
    early if the node assistance flag is set to allow programmatic focus.
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::didCommitLayerTree): After committing the layer tree, if we have deferred
    starting node assistance, immediately trigger node assistance.
(WebKit::WebPageProxy::startAssistingNode): Defer starting node assistance if we have not yet repainted.
(WebKit::WebPageProxy::stopAssistingNode): Also cancel any deferred node assistance.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@190278 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/Cocoa/WKWebView.h
Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfiguration.h
Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfiguration.mm
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm
Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm