<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[243963] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/243963">243963</a></dd>
<dt>Author</dt> <dd>wenson_hsieh@apple.com</dd>
<dt>Date</dt> <dd>2019-04-06 19:25:36 -0700 (Sat, 06 Apr 2019)</dd>
</dl>

<h3>Log Message</h3>
<pre>Hide next and previous form control buttons when WKWebView is editable
https://bugs.webkit.org/show_bug.cgi?id=196672
<rdar://problem/35625321>

Reviewed by Tim Horton.

Source/WebKit:

Adopt new UIKit SPI to hide or show next and previous controls in the form accessory view when changing
editability.

Test: KeyboardInputTests.FormNavigationAssistantBarButtonItems

* Platform/spi/ios/UIKitSPI.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _setEditable:]):
* UIProcess/ios/WKContentViewInteraction.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _updateAccessory]):
(-[WKContentView _didChangeWebViewEditability]):

Tools:

Add a new API test.

* TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm:
(-[TestWKWebView lastTrailingBarButtonGroup]):
(TestWebKitAPI::TEST):
* TestWebKitAPI/ios/UIKitSPI.h:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitPlatformspiiosUIKitSPIh">trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h</a></li>
<li><a href="#trunkSourceWebKitUIProcessAPICocoaWKWebViewmm">trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm</a></li>
<li><a href="#trunkSourceWebKitUIProcessiosWKContentViewInteractionh">trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h</a></li>
<li><a href="#trunkSourceWebKitUIProcessiosWKContentViewInteractionmm">trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsiosKeyboardInputTestsIOSmm">trunk/Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm</a></li>
<li><a href="#trunkToolsTestWebKitAPIiosUIKitSPIh">trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (243962 => 243963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ChangeLog    2019-04-06 16:48:58 UTC (rev 243962)
+++ trunk/Source/WebKit/ChangeLog       2019-04-07 02:25:36 UTC (rev 243963)
</span><span class="lines">@@ -1,3 +1,24 @@
</span><ins>+2019-04-06  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Hide next and previous form control buttons when WKWebView is editable
+        https://bugs.webkit.org/show_bug.cgi?id=196672
+        <rdar://problem/35625321>
+
+        Reviewed by Tim Horton.
+
+        Adopt new UIKit SPI to hide or show next and previous controls in the form accessory view when changing
+        editability.
+
+        Test: KeyboardInputTests.FormNavigationAssistantBarButtonItems
+
+        * Platform/spi/ios/UIKitSPI.h:
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _setEditable:]):
+        * UIProcess/ios/WKContentViewInteraction.h:
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView _updateAccessory]):
+        (-[WKContentView _didChangeWebViewEditability]):
+
</ins><span class="cx"> 2019-04-06  Antti Koivisto  <antti@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Combine event and touch action regions into a single class
</span></span></pre></div>
<a id="trunkSourceWebKitPlatformspiiosUIKitSPIh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h (243962 => 243963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h  2019-04-06 16:48:58 UTC (rev 243962)
+++ trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h     2019-04-07 02:25:36 UTC (rev 243963)
</span><span class="lines">@@ -1170,6 +1170,10 @@
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+@interface UIWebFormAccessory (Staging_49666643)
+- (void)setNextPreviousItemsVisible:(BOOL)visible;
+@end
+
</ins><span class="cx"> WTF_EXTERN_C_BEGIN
</span><span class="cx"> 
</span><span class="cx"> BOOL UIKeyboardEnabledInputModesAllowOneToManyShortcuts(void);
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessAPICocoaWKWebViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (243962 => 243963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm     2019-04-06 16:48:58 UTC (rev 243962)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm        2019-04-07 02:25:36 UTC (rev 243963)
</span><span class="lines">@@ -4605,11 +4605,19 @@
</span><span class="cx"> 
</span><span class="cx"> - (void)_setEditable:(BOOL)editable
</span><span class="cx"> {
</span><ins>+    bool wasEditable = _page->isEditable();
</ins><span class="cx">     _page->setEditable(editable);
</span><span class="cx"> #if PLATFORM(MAC)
</span><span class="cx">     if (editable)
</span><span class="cx">         _impl->didBecomeEditable();
</span><span class="cx"> #endif
</span><ins>+
+    if (wasEditable == editable)
+        return;
+
+#if PLATFORM(IOS_FAMILY)
+    [_contentView _didChangeWebViewEditability];
+#endif
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (void)_takeFindStringFromSelection:(id)sender
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessiosWKContentViewInteractionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h (243962 => 243963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h     2019-04-06 16:48:58 UTC (rev 243962)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h        2019-04-07 02:25:36 UTC (rev 243963)
</span><span class="lines">@@ -447,6 +447,7 @@
</span><span class="cx"> - (void)_accessibilityStoreSelection;
</span><span class="cx"> - (void)_accessibilityClearSelection;
</span><span class="cx"> - (WKFormInputSession *)_formInputSession;
</span><ins>+- (void)_didChangeWebViewEditability;
</ins><span class="cx"> 
</span><span class="cx"> - (void)_requestDOMPasteAccessWithElementRect:(const WebCore::IntRect&)elementRect originIdentifier:(const String&)originIdentifier completionHandler:(CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&&)completionHandler;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessiosWKContentViewInteractionmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (243962 => 243963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm    2019-04-06 16:48:58 UTC (rev 243962)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm       2019-04-07 02:25:36 UTC (rev 243963)
</span><span class="lines">@@ -3811,6 +3811,9 @@
</span><span class="cx"> {
</span><span class="cx">     auto* accessoryView = self.formAccessoryView; // Creates one, if needed.
</span><span class="cx"> 
</span><ins>+    if ([accessoryView respondsToSelector:@selector(setNextPreviousItemsVisible:)])
+        [accessoryView setNextPreviousItemsVisible:!_webView._editable];
+
</ins><span class="cx">     [accessoryView setNextEnabled:_focusedElementInformation.hasNextNode];
</span><span class="cx">     [accessoryView setPreviousEnabled:_focusedElementInformation.hasPreviousNode];
</span><span class="cx"> 
</span><span class="lines">@@ -3850,6 +3853,12 @@
</span><span class="cx">     [self.inputDelegate selectionDidChange:self];
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (void)_didChangeWebViewEditability
+{
+    if ([_formAccessoryView respondsToSelector:@selector(setNextPreviousItemsVisible:)])
+        [_formAccessoryView setNextPreviousItemsVisible:!_webView._editable];
+}
+
</ins><span class="cx"> - (void)insertTextSuggestion:(UITextSuggestion *)textSuggestion
</span><span class="cx"> {
</span><span class="cx">     // FIXME: Replace NSClassFromString with actual class as soon as UIKit submitted the new class into the iOS SDK.
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (243962 => 243963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog    2019-04-06 16:48:58 UTC (rev 243962)
+++ trunk/Tools/ChangeLog       2019-04-07 02:25:36 UTC (rev 243963)
</span><span class="lines">@@ -1,3 +1,18 @@
</span><ins>+2019-04-06  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Hide next and previous form control buttons when WKWebView is editable
+        https://bugs.webkit.org/show_bug.cgi?id=196672
+        <rdar://problem/35625321>
+
+        Reviewed by Tim Horton.
+
+        Add a new API test.
+
+        * TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm:
+        (-[TestWKWebView lastTrailingBarButtonGroup]):
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/ios/UIKitSPI.h:
+
</ins><span class="cx"> 2019-04-05  Yongjun Zhang  <yongjun_zhang@apple.com>
</span><span class="cx"> 
</span><span class="cx">         We should pass minimumEffectiveDeviceWidth to web process on new page creation.
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsiosKeyboardInputTestsIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm (243962 => 243963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm     2019-04-06 16:48:58 UTC (rev 243962)
+++ trunk/Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm        2019-04-07 02:25:36 UTC (rev 243963)
</span><span class="lines">@@ -27,6 +27,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(IOS_FAMILY)
</span><span class="cx"> 
</span><ins>+#import "IPadUserInterfaceSwizzler.h"
</ins><span class="cx"> #import "PlatformUtilities.h"
</span><span class="cx"> #import "TestInputDelegate.h"
</span><span class="cx"> #import "TestWKWebView.h"
</span><span class="lines">@@ -140,6 +141,11 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (UIBarButtonItemGroup *)lastTrailingBarButtonGroup
+{
+    return self.firstResponder.inputAssistantItem.trailingBarButtonGroups.lastObject;
+}
+
</ins><span class="cx"> @end
</span><span class="cx"> 
</span><span class="cx"> static RetainPtr<TestWKWebView> webViewWithAutofocusedInput(const RetainPtr<TestInputDelegate>& inputDelegate)
</span><span class="lines">@@ -167,6 +173,34 @@
</span><span class="cx"> 
</span><span class="cx"> namespace TestWebKitAPI {
</span><span class="cx"> 
</span><ins>+TEST(KeyboardInputTests, FormNavigationAssistantBarButtonItems)
+{
+    IPadUserInterfaceSwizzler iPadUserInterface;
+
+    auto inputDelegate = adoptNS([TestInputDelegate new]);
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+    [webView _setInputDelegate:inputDelegate.get()];
+    [inputDelegate setFocusStartsInputSessionPolicyHandler:[&] (WKWebView *, id <_WKFocusedElementInfo>) -> _WKFocusStartsInputSessionPolicy {
+        return _WKFocusStartsInputSessionPolicyAllow;
+    }];
+    [webView synchronouslyLoadHTMLString:@"<body contenteditable>"];
+    [webView evaluateJavaScriptAndWaitForInputSessionToChange:@"document.body.focus()"];
+
+    EXPECT_EQ(2U, [webView lastTrailingBarButtonGroup].barButtonItems.count);
+    EXPECT_FALSE([webView lastTrailingBarButtonGroup].hidden);
+
+    if (![UIWebFormAccessory instancesRespondToSelector:@selector(setNextPreviousItemsVisible:)]) {
+        // The rest of this test requires UIWebFormAccessory to be able to show or hide its next and previous items.
+        return;
+    }
+
+    [webView _setEditable:YES];
+    EXPECT_TRUE([webView lastTrailingBarButtonGroup].hidden);
+
+    [webView _setEditable:NO];
+    EXPECT_FALSE([webView lastTrailingBarButtonGroup].hidden);
+}
+
</ins><span class="cx"> TEST(KeyboardInputTests, ModifyInputAssistantItemBarButtonGroups)
</span><span class="cx"> {
</span><span class="cx">     auto inputDelegate = adoptNS([TestInputDelegate new]);
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPIiosUIKitSPIh"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h (243962 => 243963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h 2019-04-06 16:48:58 UTC (rev 243962)
+++ trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h    2019-04-07 02:25:36 UTC (rev 243963)
</span><span class="lines">@@ -30,6 +30,7 @@
</span><span class="cx"> #if USE(APPLE_INTERNAL_SDK)
</span><span class="cx"> 
</span><span class="cx"> #import <UIKit/UIApplication_Private.h>
</span><ins>+#import <UIKit/UIBarButtonItemGroup_Private.h>
</ins><span class="cx"> #import <UIKit/UICalloutBar.h>
</span><span class="cx"> #import <UIKit/UIKeyboard_Private.h>
</span><span class="cx"> #import <UIKit/UIResponder_Private.h>
</span><span class="lines">@@ -38,6 +39,7 @@
</span><span class="cx"> #import <UIKit/UITextInput_Private.h>
</span><span class="cx"> #import <UIKit/UIViewController_Private.h>
</span><span class="cx"> #import <UIKit/UIWKTextInteractionAssistant.h>
</span><ins>+#import <UIKit/UIWebFormAccessory.h>
</ins><span class="cx"> 
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx"> @protocol UIDragSession;
</span><span class="lines">@@ -83,6 +85,13 @@
</span><span class="cx"> - (NSDictionary *)_autofillContext;
</span><span class="cx"> @end
</span><span class="cx"> 
</span><ins>+@interface UIWebFormAccessory : UIInputView
+@end
+
+@interface UIBarButtonItemGroup ()
+@property (nonatomic, readwrite, assign, getter=_isHidden, setter=_setHidden:) BOOL hidden;
+@end
+
</ins><span class="cx"> @protocol UITextInputMultiDocument <NSObject>
</span><span class="cx"> @optional
</span><span class="cx"> - (void)_preserveFocusWithToken:(id <NSCopying, NSSecureCoding>)token destructively:(BOOL)destructively;
</span><span class="lines">@@ -170,4 +179,8 @@
</span><span class="cx"> - (void)pasteWithCompletionHandler:(void (^)(void))completionHandler;
</span><span class="cx"> @end
</span><span class="cx"> 
</span><ins>+@interface UIWebFormAccessory (Staging_49666643)
+- (void)setNextPreviousItemsVisible:(BOOL)visible;
+@end
+
</ins><span class="cx"> #endif // PLATFORM(IOS_FAMILY)
</span></span></pre>
</div>
</div>

</body>
</html>