Title: [275297] trunk
Revision
275297
Author
[email protected]
Date
2021-03-31 11:33:39 -0700 (Wed, 31 Mar 2021)

Log Message

WKContentView should support UIKit protocol methods for becoming focused
https://bugs.webkit.org/show_bug.cgi?id=224003
<rdar://problem/75313658>

Reviewed by Megan Gardner.

Source/WebKit:

Implement a few protocol methods on `UIFocusEnvironment`. See below for more details.

Test: UIFocusTests.OverrideCanBecomeFocused

* UIProcess/API/ios/WKWebViewIOS.mm:
(-[WKWebView canBecomeFocused]):
* UIProcess/ios/WKContentView.h:
* UIProcess/ios/WKContentView.mm:
(-[WKContentView canBecomeFocused]):
(-[WKContentView canBecomeFocusedForWebView]):

Implement `-canBecomeFocused`, and return `YES` by default. If `-canBecomeFocused` is overridden on `WKWebView`,
then defer to that overridden method instead.

(-[WKContentView didUpdateFocusInContext:withAnimationCoordinator:]):

Handle the focus environment change by advancing to the next or previous focusable element, depending on the
focus context's heading direction.

* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _becomeFirstResponderWithSelectionMovingForward:completionHandler:]):

Add a null check so that callers that don't need to know when the focus change is complete are able to pass in a
`nil` completion handler.

Tools:

Add a test to verify that the vaue of `-[WKContentView canBecomeFocused]` can be overridden by subclassing
`-[WKWebView canBecomeFocused]`.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/ios/UIFocusTests.mm: Added.
(-[UIFocusTestWKWebView canBecomeFocused]):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (275296 => 275297)


--- trunk/Source/WebKit/ChangeLog	2021-03-31 18:29:23 UTC (rev 275296)
+++ trunk/Source/WebKit/ChangeLog	2021-03-31 18:33:39 UTC (rev 275297)
@@ -1,3 +1,36 @@
+2021-03-31  Wenson Hsieh  <[email protected]>
+
+        WKContentView should support UIKit protocol methods for becoming focused
+        https://bugs.webkit.org/show_bug.cgi?id=224003
+        <rdar://problem/75313658>
+
+        Reviewed by Megan Gardner.
+
+        Implement a few protocol methods on `UIFocusEnvironment`. See below for more details.
+
+        Test: UIFocusTests.OverrideCanBecomeFocused
+
+        * UIProcess/API/ios/WKWebViewIOS.mm:
+        (-[WKWebView canBecomeFocused]):
+        * UIProcess/ios/WKContentView.h:
+        * UIProcess/ios/WKContentView.mm:
+        (-[WKContentView canBecomeFocused]):
+        (-[WKContentView canBecomeFocusedForWebView]):
+
+        Implement `-canBecomeFocused`, and return `YES` by default. If `-canBecomeFocused` is overridden on `WKWebView`,
+        then defer to that overridden method instead.
+
+        (-[WKContentView didUpdateFocusInContext:withAnimationCoordinator:]):
+
+        Handle the focus environment change by advancing to the next or previous focusable element, depending on the
+        focus context's heading direction.
+
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView _becomeFirstResponderWithSelectionMovingForward:completionHandler:]):
+
+        Add a null check so that callers that don't need to know when the focus change is complete are able to pass in a
+        `nil` completion handler.
+
 2021-03-31  Youenn Fablet  <[email protected]>
 
         Make use of NSURLSessionWebSocket.sendCloseCode if available

Modified: trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm (275296 => 275297)


--- trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm	2021-03-31 18:29:23 UTC (rev 275296)
+++ trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm	2021-03-31 18:33:39 UTC (rev 275297)
@@ -2518,6 +2518,14 @@
         _page->setUserInterfaceLayoutDirection(toUserInterfaceLayoutDirection(contentAttribute));
 }
 
+- (BOOL)canBecomeFocused
+{
+    if (self.usesStandardContentView)
+        return [_contentView canBecomeFocusedForWebView];
+
+    return [_customContentView canBecomeFocused];
+}
+
 @end
 
 @implementation WKWebView (WKPrivateIOS)

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentView.h (275296 => 275297)


--- trunk/Source/WebKit/UIProcess/ios/WKContentView.h	2021-03-31 18:29:23 UTC (rev 275296)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentView.h	2021-03-31 18:33:39 UTC (rev 275297)
@@ -71,6 +71,7 @@
 @property (nonatomic, readonly, getter=isResigningFirstResponder) BOOL resigningFirstResponder;
 @property (nonatomic) BOOL sizeChangedSinceLastVisibleContentRectUpdate;
 @property (nonatomic, readonly) UIInterfaceOrientation interfaceOrientation;
+@property (nonatomic, readonly) BOOL canBecomeFocusedForWebView;
 
 - (instancetype)initWithFrame:(CGRect)frame processPool:(NakedRef<WebKit::WebProcessPool>)processPool configuration:(Ref<API::PageConfiguration>&&)configuration webView:(WKWebView *)webView;
 

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentView.mm (275296 => 275297)


--- trunk/Source/WebKit/UIProcess/ios/WKContentView.mm	2021-03-31 18:29:23 UTC (rev 275296)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentView.mm	2021-03-31 18:33:39 UTC (rev 275297)
@@ -531,6 +531,21 @@
     return self.window.windowScene.interfaceOrientation;
 }
 
+- (BOOL)canBecomeFocused
+{
+    return [_webView canBecomeFocused];
+}
+
+- (BOOL)canBecomeFocusedForWebView
+{
+    return YES;
+}
+
+- (void)didUpdateFocusInContext:(UIFocusUpdateContext *)context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator
+{
+    [self _becomeFirstResponderWithSelectionMovingForward:context.focusHeading == UIFocusHeadingNext completionHandler:nil];
+}
+
 #pragma mark Internal
 
 - (void)_windowDidMoveToScreenNotification:(NSNotification *)notification

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (275296 => 275297)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2021-03-31 18:29:23 UTC (rev 275296)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2021-03-31 18:33:39 UTC (rev 275297)
@@ -4548,7 +4548,8 @@
 {
     constexpr bool isKeyboardEventValid = false;
     _page->setInitialFocus(selectingForward, isKeyboardEventValid, { }, [protectedSelf = retainPtr(self), completionHandler = makeBlockPtr(completionHandler)] {
-        completionHandler([protectedSelf becomeFirstResponder]);
+        if (completionHandler)
+            completionHandler([protectedSelf becomeFirstResponder]);
     });
 }
 

Modified: trunk/Tools/ChangeLog (275296 => 275297)


--- trunk/Tools/ChangeLog	2021-03-31 18:29:23 UTC (rev 275296)
+++ trunk/Tools/ChangeLog	2021-03-31 18:33:39 UTC (rev 275297)
@@ -1,3 +1,18 @@
+2021-03-31  Wenson Hsieh  <[email protected]>
+
+        WKContentView should support UIKit protocol methods for becoming focused
+        https://bugs.webkit.org/show_bug.cgi?id=224003
+        <rdar://problem/75313658>
+
+        Reviewed by Megan Gardner.
+
+        Add a test to verify that the vaue of `-[WKContentView canBecomeFocused]` can be overridden by subclassing
+        `-[WKWebView canBecomeFocused]`.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/ios/UIFocusTests.mm: Added.
+        (-[UIFocusTestWKWebView canBecomeFocused]):
+
 2021-03-31  Alex Christensen  <[email protected]>
 
         Add test for SOCKS5 proxy SPI

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (275296 => 275297)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2021-03-31 18:29:23 UTC (rev 275296)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2021-03-31 18:33:39 UTC (rev 275297)
@@ -1187,6 +1187,7 @@
 		F460F657261116EA0064F2B6 /* InjectedBundleHitTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = F460F656261116EA0064F2B6 /* InjectedBundleHitTest.mm */; };
 		F460F65B261119580064F2B6 /* InjectedBundleHitTestPlugIn.mm in Sources */ = {isa = PBXBuildFile; fileRef = F460F659261117E70064F2B6 /* InjectedBundleHitTestPlugIn.mm */; };
 		F460F669261263370064F2B6 /* simple-responsive-page.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F460F668261262C70064F2B6 /* simple-responsive-page.html */; };
+		F460F6752614DE2F0064F2B6 /* UIFocusTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = F460F6742614DE2F0064F2B6 /* UIFocusTests.mm */; };
 		F46128B7211C8ED500D9FADB /* DragAndDropSimulatorMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = F46128B6211C8ED500D9FADB /* DragAndDropSimulatorMac.mm */; };
 		F46128CB211D475100D9FADB /* TestDraggingInfo.mm in Sources */ = {isa = PBXBuildFile; fileRef = F46128CA211D475100D9FADB /* TestDraggingInfo.mm */; };
 		F46128D4211E40FD00D9FADB /* link-in-iframe-and-input.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F46128D1211E2D2500D9FADB /* link-in-iframe-and-input.html */; };
@@ -2994,6 +2995,7 @@
 		F460F659261117E70064F2B6 /* InjectedBundleHitTestPlugIn.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = InjectedBundleHitTestPlugIn.mm; sourceTree = "<group>"; };
 		F460F65A2611183F0064F2B6 /* InjectedBundleHitTestProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = InjectedBundleHitTestProtocol.h; sourceTree = "<group>"; };
 		F460F668261262C70064F2B6 /* simple-responsive-page.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "simple-responsive-page.html"; sourceTree = "<group>"; };
+		F460F6742614DE2F0064F2B6 /* UIFocusTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = UIFocusTests.mm; sourceTree = "<group>"; };
 		F46128B4211C861A00D9FADB /* DragAndDropSimulator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DragAndDropSimulator.h; path = cocoa/DragAndDropSimulator.h; sourceTree = "<group>"; };
 		F46128B6211C8ED500D9FADB /* DragAndDropSimulatorMac.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = DragAndDropSimulatorMac.mm; sourceTree = "<group>"; };
 		F46128C9211D475100D9FADB /* TestDraggingInfo.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TestDraggingInfo.h; sourceTree = "<group>"; };
@@ -3774,6 +3776,7 @@
 				F45E15742112CE6200307E82 /* TestInputDelegate.h */,
 				F45E15752112CE6200307E82 /* TestInputDelegate.mm */,
 				F45033F4206BEC95009351CE /* TextAutosizingBoost.mm */,
+				F460F6742614DE2F0064F2B6 /* UIFocusTests.mm */,
 				F46849BD1EEF58E400B937FE /* UIPasteboardTests.mm */,
 				F402F56B23ECC2FB00865549 /* UIWKInteractionViewProtocol.mm */,
 				E5AA42F1259128AE00410A3D /* UserInterfaceIdiomUpdate.mm */,
@@ -5680,6 +5683,7 @@
 				7CCE7ED31A411A7E00447C4C /* TypingStyleCrash.mm in Sources */,
 				57152B7821DD4E8D000C37CA /* U2fCommandConstructorTest.cpp in Sources */,
 				5CB40B4E1F4B98D3007DC7B9 /* UIDelegate.mm in Sources */,
+				F460F6752614DE2F0064F2B6 /* UIFocusTests.mm in Sources */,
 				F46849BE1EEF58E400B937FE /* UIPasteboardTests.mm in Sources */,
 				F402F56C23ECC2FB00865549 /* UIWKInteractionViewProtocol.mm in Sources */,
 				5C9D922E22D7DE1C008E9266 /* UnifiedSource1.cpp in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/ios/UIFocusTests.mm (0 => 275297)


--- trunk/Tools/TestWebKitAPI/Tests/ios/UIFocusTests.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/ios/UIFocusTests.mm	2021-03-31 18:33:39 UTC (rev 275297)
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+
+#if PLATFORM(IOS_FAMILY)
+
+#import "TestWKWebView.h"
+#import <wtf/Optional.h>
+#import <wtf/RetainPtr.h>
+
+@interface UIFocusTestWKWebView : TestWKWebView
+@property (nonatomic) Optional<BOOL> overrideCanBecomeFocused;
+@end
+
+@implementation UIFocusTestWKWebView
+
+- (BOOL)canBecomeFocused
+{
+    return self.overrideCanBecomeFocused.valueOr([super canBecomeFocused]);
+}
+
+@end
+
+namespace TestWebKitAPI {
+
+TEST(UIFocusTests, OverrideCanBecomeFocused)
+{
+    auto webView = adoptNS([[UIFocusTestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+    [webView synchronouslyLoadTestPageNamed:@"simple-form"];
+    EXPECT_TRUE([webView textInputContentView].canBecomeFocused);
+
+    [webView setOverrideCanBecomeFocused:NO];
+    EXPECT_FALSE([webView textInputContentView].canBecomeFocused);
+
+    [webView setOverrideCanBecomeFocused:YES];
+    EXPECT_TRUE([webView textInputContentView].canBecomeFocused);
+}
+
+} // namespace TestWebKitAPI
+
+#endif // PLATFORM(IOS_FAMILY)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to