Title: [243963] trunk
Revision
243963
Author
[email protected]
Date
2019-04-06 19:25:36 -0700 (Sat, 06 Apr 2019)

Log Message

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:

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (243962 => 243963)


--- 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)
@@ -1,3 +1,24 @@
+2019-04-06  Wenson Hsieh  <[email protected]>
+
+        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]):
+
 2019-04-06  Antti Koivisto  <[email protected]>
 
         Combine event and touch action regions into a single class

Modified: trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h (243962 => 243963)


--- 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)
@@ -1170,6 +1170,10 @@
 #endif
 }
 
+@interface UIWebFormAccessory (Staging_49666643)
+- (void)setNextPreviousItemsVisible:(BOOL)visible;
+@end
+
 WTF_EXTERN_C_BEGIN
 
 BOOL UIKeyboardEnabledInputModesAllowOneToManyShortcuts(void);

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (243962 => 243963)


--- 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)
@@ -4605,11 +4605,19 @@
 
 - (void)_setEditable:(BOOL)editable
 {
+    bool wasEditable = _page->isEditable();
     _page->setEditable(editable);
 #if PLATFORM(MAC)
     if (editable)
         _impl->didBecomeEditable();
 #endif
+
+    if (wasEditable == editable)
+        return;
+
+#if PLATFORM(IOS_FAMILY)
+    [_contentView _didChangeWebViewEditability];
+#endif
 }
 
 - (void)_takeFindStringFromSelection:(id)sender

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h (243962 => 243963)


--- 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)
@@ -447,6 +447,7 @@
 - (void)_accessibilityStoreSelection;
 - (void)_accessibilityClearSelection;
 - (WKFormInputSession *)_formInputSession;
+- (void)_didChangeWebViewEditability;
 
 - (void)_requestDOMPasteAccessWithElementRect:(const WebCore::IntRect&)elementRect originIdentifier:(const String&)originIdentifier completionHandler:(CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&&)completionHandler;
 

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (243962 => 243963)


--- 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)
@@ -3811,6 +3811,9 @@
 {
     auto* accessoryView = self.formAccessoryView; // Creates one, if needed.
 
+    if ([accessoryView respondsToSelector:@selector(setNextPreviousItemsVisible:)])
+        [accessoryView setNextPreviousItemsVisible:!_webView._editable];
+
     [accessoryView setNextEnabled:_focusedElementInformation.hasNextNode];
     [accessoryView setPreviousEnabled:_focusedElementInformation.hasPreviousNode];
 
@@ -3850,6 +3853,12 @@
     [self.inputDelegate selectionDidChange:self];
 }
 
+- (void)_didChangeWebViewEditability
+{
+    if ([_formAccessoryView respondsToSelector:@selector(setNextPreviousItemsVisible:)])
+        [_formAccessoryView setNextPreviousItemsVisible:!_webView._editable];
+}
+
 - (void)insertTextSuggestion:(UITextSuggestion *)textSuggestion
 {
     // FIXME: Replace NSClassFromString with actual class as soon as UIKit submitted the new class into the iOS SDK.

Modified: trunk/Tools/ChangeLog (243962 => 243963)


--- trunk/Tools/ChangeLog	2019-04-06 16:48:58 UTC (rev 243962)
+++ trunk/Tools/ChangeLog	2019-04-07 02:25:36 UTC (rev 243963)
@@ -1,3 +1,18 @@
+2019-04-06  Wenson Hsieh  <[email protected]>
+
+        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:
+
 2019-04-05  Yongjun Zhang  <[email protected]>
 
         We should pass minimumEffectiveDeviceWidth to web process on new page creation.

Modified: trunk/Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm (243962 => 243963)


--- 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)
@@ -27,6 +27,7 @@
 
 #if PLATFORM(IOS_FAMILY)
 
+#import "IPadUserInterfaceSwizzler.h"
 #import "PlatformUtilities.h"
 #import "TestInputDelegate.h"
 #import "TestWKWebView.h"
@@ -140,6 +141,11 @@
     }
 }
 
+- (UIBarButtonItemGroup *)lastTrailingBarButtonGroup
+{
+    return self.firstResponder.inputAssistantItem.trailingBarButtonGroups.lastObject;
+}
+
 @end
 
 static RetainPtr<TestWKWebView> webViewWithAutofocusedInput(const RetainPtr<TestInputDelegate>& inputDelegate)
@@ -167,6 +173,34 @@
 
 namespace TestWebKitAPI {
 
+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);
+}
+
 TEST(KeyboardInputTests, ModifyInputAssistantItemBarButtonGroups)
 {
     auto inputDelegate = adoptNS([TestInputDelegate new]);

Modified: trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h (243962 => 243963)


--- 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)
@@ -30,6 +30,7 @@
 #if USE(APPLE_INTERNAL_SDK)
 
 #import <UIKit/UIApplication_Private.h>
+#import <UIKit/UIBarButtonItemGroup_Private.h>
 #import <UIKit/UICalloutBar.h>
 #import <UIKit/UIKeyboard_Private.h>
 #import <UIKit/UIResponder_Private.h>
@@ -38,6 +39,7 @@
 #import <UIKit/UITextInput_Private.h>
 #import <UIKit/UIViewController_Private.h>
 #import <UIKit/UIWKTextInteractionAssistant.h>
+#import <UIKit/UIWebFormAccessory.h>
 
 #if PLATFORM(IOS)
 @protocol UIDragSession;
@@ -83,6 +85,13 @@
 - (NSDictionary *)_autofillContext;
 @end
 
+@interface UIWebFormAccessory : UIInputView
+@end
+
+@interface UIBarButtonItemGroup ()
+@property (nonatomic, readwrite, assign, getter=_isHidden, setter=_setHidden:) BOOL hidden;
+@end
+
 @protocol UITextInputMultiDocument <NSObject>
 @optional
 - (void)_preserveFocusWithToken:(id <NSCopying, NSSecureCoding>)token destructively:(BOOL)destructively;
@@ -170,4 +179,8 @@
 - (void)pasteWithCompletionHandler:(void (^)(void))completionHandler;
 @end
 
+@interface UIWebFormAccessory (Staging_49666643)
+- (void)setNextPreviousItemsVisible:(BOOL)visible;
+@end
+
 #endif // PLATFORM(IOS_FAMILY)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to