Title: [230902] trunk/Source/WebKit
Revision
230902
Author
commit-qu...@webkit.org
Date
2018-04-22 14:39:30 -0700 (Sun, 22 Apr 2018)

Log Message

Add -[WKInputDelegate _webView:decidePolicyForFocusedElement:] so clients can request default focusing behavior
https://bugs.webkit.org/show_bug.cgi?id=184844

Patch by Paul Knight <pkni...@apple.com> on 2018-04-22
Reviewed by Dan Bernstein.

If a client doesn't implement -[_WKInputDelegate _webView:focusShouldStartInputSession:] the default
focus behavior only brings up the keyboard if it's already onscreen, the interaction is user driven,
and other factors that even depend on what feature flags are enabled.

If a client implements _webView:focusShouldStartInputSession:, they don't have a good way to specifiy
they'd like to fall back to the default behavior. This makes it difficult for a client to use the
default in most cases, but sometimes allow programmatic focus from the page, for example.

Add a new delegate method -_webView:decidePolicyForFocusedElement: that returns a new enum type
_WKFocusStartsInputSessionPolicy. Clients can return _WKFocusStartsInputSessionPolicyAuto to request
the default behavior, or _WKFocusStartsInputSessionPolicyAllow / Disallow to directly control whether
the keyboard appears to assist the focused node.

* UIProcess/API/Cocoa/_WKInputDelegate.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _startAssistingNode:userIsInteracting:blurPreviousNode:changingActivityState:userObject:]):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (230901 => 230902)


--- trunk/Source/WebKit/ChangeLog	2018-04-22 21:23:16 UTC (rev 230901)
+++ trunk/Source/WebKit/ChangeLog	2018-04-22 21:39:30 UTC (rev 230902)
@@ -1,3 +1,27 @@
+2018-04-22  Paul Knight  <pkni...@apple.com>
+
+        Add -[WKInputDelegate _webView:decidePolicyForFocusedElement:] so clients can request default focusing behavior
+        https://bugs.webkit.org/show_bug.cgi?id=184844
+
+        Reviewed by Dan Bernstein.
+
+        If a client doesn't implement -[_WKInputDelegate _webView:focusShouldStartInputSession:] the default
+        focus behavior only brings up the keyboard if it's already onscreen, the interaction is user driven,
+        and other factors that even depend on what feature flags are enabled.
+
+        If a client implements _webView:focusShouldStartInputSession:, they don't have a good way to specifiy
+        they'd like to fall back to the default behavior. This makes it difficult for a client to use the
+        default in most cases, but sometimes allow programmatic focus from the page, for example.
+
+        Add a new delegate method -_webView:decidePolicyForFocusedElement: that returns a new enum type
+        _WKFocusStartsInputSessionPolicy. Clients can return _WKFocusStartsInputSessionPolicyAuto to request
+        the default behavior, or _WKFocusStartsInputSessionPolicyAllow / Disallow to directly control whether
+        the keyboard appears to assist the focused node.
+
+        * UIProcess/API/Cocoa/_WKInputDelegate.h:
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView _startAssistingNode:userIsInteracting:blurPreviousNode:changingActivityState:userObject:]):
+
 2018-04-21  Jeremy Jones  <jere...@apple.com>
 
         Disable backward and forward navigation swipes while in fullscreen.

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKInputDelegate.h (230901 => 230902)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKInputDelegate.h	2018-04-22 21:23:16 UTC (rev 230901)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKInputDelegate.h	2018-04-22 21:39:30 UTC (rev 230902)
@@ -34,6 +34,14 @@
 @protocol _WKFocusedElementInfo;
 @protocol _WKFormInputSession;
 
+#if TARGET_OS_IPHONE
+typedef NS_ENUM(NSInteger, _WKFocusStartsInputSessionPolicy) {
+    _WKFocusStartsInputSessionPolicyAuto,
+    _WKFocusStartsInputSessionPolicyAllow,
+    _WKFocusStartsInputSessionPolicyDisallow,
+} WK_API_AVAILABLE(ios(WK_IOS_TBA));
+#endif
+
 @protocol _WKInputDelegate <NSObject>
 
 @optional
@@ -43,6 +51,7 @@
 
 #if TARGET_OS_IPHONE
 - (BOOL)_webView:(WKWebView *)webView focusShouldStartInputSession:(id <_WKFocusedElementInfo>)info;
+- (_WKFocusStartsInputSessionPolicy)_webView:(WKWebView *)webView decidePolicyForFocusedElement:(id <_WKFocusedElementInfo>)info WK_API_AVAILABLE(ios(WK_IOS_TBA));
 - (void)_webView:(WKWebView *)webView accessoryViewCustomButtonTappedInFormInputSession:(id <_WKFormInputSession>)inputSession;
 - (void)_webView:(WKWebView *)webView insertTextSuggestion:(UITextSuggestion *)suggestion inInputSession:(id <_WKFormInputSession>)inputSession WK_API_AVAILABLE(ios(10.0));
 - (void)_webView:(WKWebView *)webView willStartInputSession:(id <_WKFormInputSession>)inputSession WK_API_AVAILABLE(ios(WK_IOS_TBA));

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (230901 => 230902)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2018-04-22 21:23:16 UTC (rev 230901)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2018-04-22 21:39:30 UTC (rev 230902)
@@ -4034,11 +4034,22 @@
 
     id <_WKInputDelegate> inputDelegate = [_webView _inputDelegate];
     RetainPtr<WKFocusedElementInfo> focusedElementInfo = adoptNS([[WKFocusedElementInfo alloc] initWithAssistedNodeInformation:information isUserInitiated:userIsInteracting userObject:userObject]);
-    BOOL shouldShowKeyboard;
 
-    if ([inputDelegate respondsToSelector:@selector(_webView:focusShouldStartInputSession:)])
-        shouldShowKeyboard = [inputDelegate _webView:_webView focusShouldStartInputSession:focusedElementInfo.get()];
-    else {
+    BOOL shouldShowKeyboard = NO;
+    _WKFocusStartsInputSessionPolicy startInputSessionPolicy = _WKFocusStartsInputSessionPolicyAuto;
+
+    if ([inputDelegate respondsToSelector:@selector(_webView:focusShouldStartInputSession:)]) {
+        if ([inputDelegate _webView:_webView focusShouldStartInputSession:focusedElementInfo.get()])
+            startInputSessionPolicy = _WKFocusStartsInputSessionPolicyAllow;
+        else
+            startInputSessionPolicy = _WKFocusStartsInputSessionPolicyDisallow;
+    }
+
+    if ([inputDelegate respondsToSelector:@selector(_webView:decidePolicyForFocusedElement:)])
+        startInputSessionPolicy = [inputDelegate _webView:_webView decidePolicyForFocusedElement:focusedElementInfo.get()];
+
+    switch (startInputSessionPolicy) {
+    case _WKFocusStartsInputSessionPolicyAuto:
         // The default behavior is to allow node assistance if the user is interacting.
         // We also allow node assistance if the keyboard already is showing, unless we're in extra zoom mode.
         shouldShowKeyboard = userIsInteracting
@@ -4051,6 +4062,15 @@
             || _dragDropInteractionState.isPerformingDrop()
 #endif
             || changingActivityState;
+        break;
+    case _WKFocusStartsInputSessionPolicyAllow:
+        shouldShowKeyboard = YES;
+        break;
+    case _WKFocusStartsInputSessionPolicyDisallow:
+        shouldShowKeyboard = NO;
+        break;
+    default:
+        ASSERT_NOT_REACHED();
     }
 
     if (blurPreviousNode)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to