Title: [265284] trunk
Revision
265284
Author
[email protected]
Date
2020-08-05 07:43:49 -0700 (Wed, 05 Aug 2020)

Log Message

[iOS] Keyboard shortcuts and arrow key scrolling stop working after navigating via swipe gesture
https://bugs.webkit.org/show_bug.cgi?id=215137
<rdar://problem/65082979>

Reviewed by Tim Horton.

Source/WebKit:

The process of starting a navigation swipe gesture causes the first responder (in this case, WKContentView) to
resign. Subsequently, nothing makes the content view first responder again once the navigation gesture ends,
even if the gesture is cancelled and we don't end up navigating. This results in several symptoms, two of which
are that keyboard shortcuts stop working, and pressing arrow keys does not scroll the web view after ending the
swipe gesture.

To mitigate this, add a mechanism to have the web view remember that our content view was first responder before
calling `-startInteractiveTransition:`; after ending the interactive transition (i.e. swipe gesture), we then
restore the web view's content view as first responder if it is not already first responder (and it is also
parented, which is not the case when swiping back to close a newly opened tab in Safari).

Test:   NavigationSwipeTests.RestoreFirstResponderAfterNavigationSwipe
        NavigationSwipeTests.DoNotBecomeFirstResponderAfterNavigationSwipeIfWebViewIsUnparented

* UIProcess/API/Cocoa/WKWebViewInternal.h:
* UIProcess/API/ios/WKWebViewIOS.mm:
(-[WKWebView _navigationGestureDidBegin]):
(-[WKWebView _navigationGestureDidEnd]):

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/ios/NavigationSwipeTests.mm: Added.
(-[TestNavigationInteractiveTransition startInteractiveTransition:]):

Add an API test that exercises the bug by resigning first responder underneath `-startInteractiveTransition:`,
and checking that we have become first responder once again after completing the transition.

* TestWebKitAPI/ios/UIKitSPI.h:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (265283 => 265284)


--- trunk/Source/WebKit/ChangeLog	2020-08-05 11:03:08 UTC (rev 265283)
+++ trunk/Source/WebKit/ChangeLog	2020-08-05 14:43:49 UTC (rev 265284)
@@ -1,3 +1,30 @@
+2020-08-05  Wenson Hsieh  <[email protected]>
+
+        [iOS] Keyboard shortcuts and arrow key scrolling stop working after navigating via swipe gesture
+        https://bugs.webkit.org/show_bug.cgi?id=215137
+        <rdar://problem/65082979>
+
+        Reviewed by Tim Horton.
+
+        The process of starting a navigation swipe gesture causes the first responder (in this case, WKContentView) to
+        resign. Subsequently, nothing makes the content view first responder again once the navigation gesture ends,
+        even if the gesture is cancelled and we don't end up navigating. This results in several symptoms, two of which
+        are that keyboard shortcuts stop working, and pressing arrow keys does not scroll the web view after ending the
+        swipe gesture.
+
+        To mitigate this, add a mechanism to have the web view remember that our content view was first responder before
+        calling `-startInteractiveTransition:`; after ending the interactive transition (i.e. swipe gesture), we then
+        restore the web view's content view as first responder if it is not already first responder (and it is also
+        parented, which is not the case when swiping back to close a newly opened tab in Safari).
+
+        Test:   NavigationSwipeTests.RestoreFirstResponderAfterNavigationSwipe
+                NavigationSwipeTests.DoNotBecomeFirstResponderAfterNavigationSwipeIfWebViewIsUnparented
+
+        * UIProcess/API/Cocoa/WKWebViewInternal.h:
+        * UIProcess/API/ios/WKWebViewIOS.mm:
+        (-[WKWebView _navigationGestureDidBegin]):
+        (-[WKWebView _navigationGestureDidEnd]):
+
 2020-08-04  Brent Fulgham  <[email protected]>
 
         Unreviewed build fix after r265263

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h (265283 => 265284)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h	2020-08-05 11:03:08 UTC (rev 265283)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h	2020-08-05 14:43:49 UTC (rev 265284)
@@ -218,6 +218,7 @@
     BOOL _didDeferUpdateVisibleContentRectsForAnyReason;
     BOOL _didDeferUpdateVisibleContentRectsForUnstableScrollView;
     BOOL _alwaysSendNextVisibleContentRectUpdate;
+    BOOL _contentViewShouldBecomeFirstResponderAfterNavigationGesture;
 
     BOOL _waitingForEndAnimatedResize;
     BOOL _waitingForCommitAfterAnimatedResize;

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


--- trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm	2020-08-05 11:03:08 UTC (rev 265283)
+++ trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm	2020-08-05 14:43:49 UTC (rev 265284)
@@ -2291,6 +2291,7 @@
 
     _frozenVisibleContentRect = [self convertRect:fullViewRect toView:_contentView.get()];
     _frozenUnobscuredContentRect = [self convertRect:unobscuredRect toView:_contentView.get()];
+    _contentViewShouldBecomeFirstResponderAfterNavigationGesture = [_contentView isFirstResponder];
 
     LOG_WITH_STREAM(VisibleRects, stream << "_navigationGestureDidBegin: freezing visibleContentRect " << WebCore::FloatRect(_frozenVisibleContentRect.value()) << " UnobscuredContentRect " << WebCore::FloatRect(_frozenUnobscuredContentRect.value()));
 }
@@ -2299,6 +2300,12 @@
 {
     _frozenVisibleContentRect = WTF::nullopt;
     _frozenUnobscuredContentRect = WTF::nullopt;
+
+    if (_contentViewShouldBecomeFirstResponderAfterNavigationGesture) {
+        if (self.window && ![_contentView isFirstResponder])
+            [_contentView becomeFirstResponder];
+        _contentViewShouldBecomeFirstResponderAfterNavigationGesture = NO;
+    }
 }
 
 - (void)_showPasswordViewWithDocumentName:(NSString *)documentName passwordHandler:(void (^)(NSString *))passwordHandler

Modified: trunk/Tools/ChangeLog (265283 => 265284)


--- trunk/Tools/ChangeLog	2020-08-05 11:03:08 UTC (rev 265283)
+++ trunk/Tools/ChangeLog	2020-08-05 14:43:49 UTC (rev 265284)
@@ -1,3 +1,20 @@
+2020-08-05  Wenson Hsieh  <[email protected]>
+
+        [iOS] Keyboard shortcuts and arrow key scrolling stop working after navigating via swipe gesture
+        https://bugs.webkit.org/show_bug.cgi?id=215137
+        <rdar://problem/65082979>
+
+        Reviewed by Tim Horton.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/ios/NavigationSwipeTests.mm: Added.
+        (-[TestNavigationInteractiveTransition startInteractiveTransition:]):
+
+        Add an API test that exercises the bug by resigning first responder underneath `-startInteractiveTransition:`,
+        and checking that we have become first responder once again after completing the transition.
+
+        * TestWebKitAPI/ios/UIKitSPI.h:
+
 2020-08-04  Jonathan Bedard  <[email protected]>
 
         [webkitcorepy] Add mocks.ContextStack

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (265283 => 265284)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2020-08-05 11:03:08 UTC (rev 265283)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2020-08-05 14:43:49 UTC (rev 265284)
@@ -1075,6 +1075,8 @@
 		EB230D40245E727900C66AD1 /* IDBCheckpointWAL.mm in Sources */ = {isa = PBXBuildFile; fileRef = EB230D3E245E726300C66AD1 /* IDBCheckpointWAL.mm */; };
 		EB230D41245E813F00C66AD1 /* IDBCheckpointWAL.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = EB230D3D245E722E00C66AD1 /* IDBCheckpointWAL.html */; };
 		ECA680CE1E68CC0900731D20 /* StringUtilities.mm in Sources */ = {isa = PBXBuildFile; fileRef = ECA680CD1E68CC0900731D20 /* StringUtilities.mm */; };
+		F4010B8024DA24AC00A876E2 /* NavigationSwipeTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4010B7F24DA24AC00A876E2 /* NavigationSwipeTests.mm */; };
+		F4010B8324DA267F00A876E2 /* PoseAsClass.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4010B8124DA267F00A876E2 /* PoseAsClass.mm */; };
 		F402F56C23ECC2FB00865549 /* UIWKInteractionViewProtocol.mm in Sources */ = {isa = PBXBuildFile; fileRef = F402F56B23ECC2FB00865549 /* UIWKInteractionViewProtocol.mm */; };
 		F407FE391F1D0DFC0017CF25 /* enormous.svg in Copy Resources */ = {isa = PBXBuildFile; fileRef = F407FE381F1D0DE60017CF25 /* enormous.svg */; };
 		F4106C6921ACBF84004B89A1 /* WKWebViewFirstResponderTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4106C6821ACBF84004B89A1 /* WKWebViewFirstResponderTests.mm */; };
@@ -2775,6 +2777,9 @@
 		EC79F168BE454E579E417B05 /* Markable.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Markable.cpp; sourceTree = "<group>"; };
 		ECA680CD1E68CC0900731D20 /* StringUtilities.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = StringUtilities.mm; sourceTree = "<group>"; };
 		F3FC3EE213678B7300126A65 /* libgtest.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libgtest.a; sourceTree = BUILT_PRODUCTS_DIR; };
+		F4010B7F24DA24AC00A876E2 /* NavigationSwipeTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NavigationSwipeTests.mm; sourceTree = "<group>"; };
+		F4010B8124DA267F00A876E2 /* PoseAsClass.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = PoseAsClass.mm; path = ../TestRunnerShared/cocoa/PoseAsClass.mm; sourceTree = "<group>"; };
+		F4010B8224DA267F00A876E2 /* PoseAsClass.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PoseAsClass.h; path = ../TestRunnerShared/cocoa/PoseAsClass.h; sourceTree = "<group>"; };
 		F402F56B23ECC2FB00865549 /* UIWKInteractionViewProtocol.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = UIWKInteractionViewProtocol.mm; sourceTree = "<group>"; };
 		F407FE381F1D0DE60017CF25 /* enormous.svg */ = {isa = PBXFileReference; lastKnownFileType = text; path = enormous.svg; sourceTree = "<group>"; };
 		F4106C6821ACBF84004B89A1 /* WKWebViewFirstResponderTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewFirstResponderTests.mm; sourceTree = "<group>"; };
@@ -3047,6 +3052,8 @@
 				F44A530D21B8976900DBB99C /* InstanceMethodSwizzler.h */,
 				F44A531021B8976900DBB99C /* InstanceMethodSwizzler.mm */,
 				0F139E721A423A2B00F590F5 /* PlatformUtilitiesCocoa.mm */,
+				F4010B8224DA267F00A876E2 /* PoseAsClass.h */,
+				F4010B8124DA267F00A876E2 /* PoseAsClass.mm */,
 				CE640CA52370A4F300C5CAA4 /* TestCocoa.h */,
 				CE640CA62370A4F300C5CAA4 /* TestCocoa.mm */,
 				5CE7594822A883A500C12409 /* TestContextMenuDriver.h */,
@@ -3537,6 +3544,7 @@
 				F4BC0B132146C849002A0478 /* FocusPreservationTests.mm */,
 				CDA93DAC22F4EC2200490A69 /* FullscreenTouchSecheuristicTests.cpp */,
 				F45E15722112CE2900307E82 /* KeyboardInputTestsIOS.mm */,
+				F4010B7F24DA24AC00A876E2 /* NavigationSwipeTests.mm */,
 				0F34077523037FDC0060A1A0 /* OverflowScrollViewTests.mm */,
 				F464AF9120BB66EA007F9B18 /* RenderingProgressTests.mm */,
 				F4C8797E2059D8D3009CD00B /* ScrollViewInsetTests.mm */,
@@ -5214,6 +5222,7 @@
 				7CCE7F011A411AE600447C4C /* MouseMoveAfterCrash.cpp in Sources */,
 				7CCE7F241A411AF600447C4C /* Navigation.mm in Sources */,
 				6351992822275C6A00890AD3 /* NavigationAction.mm in Sources */,
+				F4010B8024DA24AC00A876E2 /* NavigationSwipeTests.mm in Sources */,
 				5C8BC799218CF44700813886 /* NetworkProcess.mm in Sources */,
 				5CAE463820193B6A0051610F /* NetworkProcessCrashNonPersistentDataStore.mm in Sources */,
 				9B19CDA01F06DFE3000548DD /* NetworkProcessCrashWithPendingConnection.mm in Sources */,
@@ -5258,6 +5267,7 @@
 				7CCE7EA61A411A0F00447C4C /* PlatformUtilitiesMac.mm in Sources */,
 				7CCE7EA71A411A1300447C4C /* PlatformWebViewMac.mm in Sources */,
 				83BAEE8D1EF4625500DDE894 /* PluginLoadClientPolicies.mm in Sources */,
+				F4010B8324DA267F00A876E2 /* PoseAsClass.mm in Sources */,
 				DFB8FF322492F52400F00B0D /* Preconnect.mm in Sources */,
 				1D67BFDC2433E0A7006B5047 /* PreemptVideoFullscreen.mm in Sources */,
 				C15CBB3F23FB177A00300CC7 /* PreferenceChanges.mm in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/ios/NavigationSwipeTests.mm (0 => 265284)


--- trunk/Tools/TestWebKitAPI/Tests/ios/NavigationSwipeTests.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/ios/NavigationSwipeTests.mm	2020-08-05 14:43:49 UTC (rev 265284)
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2020 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 "PoseAsClass.h"
+#import "TestWKWebView.h"
+#import "UIKitSPI.h"
+#import <WebKit/WKWebViewPrivate.h>
+#import <WebKit/WKWebViewPrivateForTesting.h>
+
+@interface TestNavigationInteractiveTransition : UIPercentDrivenInteractiveTransition
+@end
+
+@implementation TestNavigationInteractiveTransition
+
+- (void)startInteractiveTransition:(id <UIViewControllerContextTransitioning>)transitionContext
+{
+    [super startInteractiveTransition:transitionContext];
+    EXPECT_TRUE([transitionContext.containerView.window.firstResponder resignFirstResponder]);
+}
+
+@end
+
+TEST(NavigationSwipeTests, RestoreFirstResponderAfterNavigationSwipe)
+{
+    poseAsClass("TestNavigationInteractiveTransition", "_UINavigationInteractiveTransitionBase");
+
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+    [webView setAllowsBackForwardNavigationGestures:YES];
+    [webView becomeFirstResponder];
+
+    [webView synchronouslyLoadTestPageNamed:@"simple"];
+    [webView synchronouslyLoadTestPageNamed:@"simple2"];
+
+    [webView _beginBackSwipeForTesting];
+    [webView _completeBackSwipeForTesting];
+    EXPECT_TRUE([webView _contentViewIsFirstResponder]);
+}
+
+TEST(NavigationSwipeTests, DoNotBecomeFirstResponderAfterNavigationSwipeIfWebViewIsUnparented)
+{
+    poseAsClass("TestNavigationInteractiveTransition", "_UINavigationInteractiveTransitionBase");
+
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+    [webView setAllowsBackForwardNavigationGestures:YES];
+    [webView becomeFirstResponder];
+
+    [webView synchronouslyLoadTestPageNamed:@"simple"];
+    [webView synchronouslyLoadTestPageNamed:@"simple2"];
+
+    [webView _beginBackSwipeForTesting];
+    [webView removeFromSuperview];
+    [webView _completeBackSwipeForTesting];
+    EXPECT_FALSE([webView _contentViewIsFirstResponder]);
+}
+
+#endif // PLATFORM(IOS_FAMILY)

Modified: trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h (265283 => 265284)


--- trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h	2020-08-05 11:03:08 UTC (rev 265283)
+++ trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h	2020-08-05 14:43:49 UTC (rev 265284)
@@ -44,6 +44,7 @@
 #import <UIKit/UIViewController_Private.h>
 #import <UIKit/UIWKTextInteractionAssistant.h>
 #import <UIKit/UIWebFormAccessory.h>
+#import <UIKit/_UINavigationInteractiveTransition.h>
 
 IGNORE_WARNINGS_BEGIN("deprecated-implementations")
 #import <UIKit/UIWebBrowserView.h>
@@ -131,6 +132,9 @@
 + (UICalloutBar *)sharedCalloutBar;
 @end
 
+@interface _UINavigationInteractiveTransitionBase : UIPercentDrivenInteractiveTransition
+@end
+
 @interface UIWKDocumentContext : NSObject
 
 @property (nonatomic, copy) NSObject *contextBefore;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to