Title: [289282] branches/safari-613-branch
Revision
289282
Author
[email protected]
Date
2022-02-07 18:53:53 -0800 (Mon, 07 Feb 2022)

Log Message

Cherry-pick r288178. rdar://problem/79296770

    REGRESSION (r264352): Mail compose body field does not avoid the keyboard when scrolling after focus
    https://bugs.webkit.org/show_bug.cgi?id=235331
    rdar://79296770

    Reviewed by Tim Horton.

    Source/WebKit:

    After r264352 added the call to `_page->scheduleFullEditorStateUpdate();` during element focus, scrolling to
    reveal the selection in the focused body field in Mail stopped working. This is because Mail:

    1.  Sets `firstResponderKeyboardAvoidanceEnabled` to NO on the WKScrollView, which prevents automatic inset
        adjustment logic in UIKit from taking effect and adding the keyboard height to the bottom system content
        inset.

    2.  Manually sets `-contentScrollInset` on the WKScrollView during a UIKeyboardDidShowNotification, which occurs
        after we've already attempted to zoom to the selection.

    ...combined with the fact that without the call to `scheduleFullEditorStateUpdate()`, the next EditorState
    would've arrived only after the keyboard animation finished.

    The end result is that we don't end up avoiding the keyboard at all when focusing the body field in Mail
    compose. While rdar://87733414 tracks refactoring logic in WebKit2 Mail compose to ensure that the content
    scroll insets on WKScrollView are applied during UIKeyboardWillShowNotification instead of after the keyboard
    has finished animating in, this patch provides a short-term workaround by restoring pre-r264352 behavior, with
    respect to when the element is scrolled into view.

    Test: editing/selection/ios/scroll-to-reveal-selection-with-keyboard-avoidance-disabled.html

    * Platform/spi/ios/UIKitSPI.h:

    Add a declaration for the `-firstResponderKeyboardAvoidanceEnabled` SPI property on non-internal iOS SDKs.

    * UIProcess/API/ios/WKWebViewIOS.mm:
    (-[WKWebView _keyboardDidShow:]):

    Plumb this through to the WKContentView, so we can zoom/scroll to the focused element if needed.

    * UIProcess/WebPageProxy.h:
    * UIProcess/ios/WKContentViewInteraction.h:
    * UIProcess/ios/WKContentViewInteraction.mm:
    (-[WKContentView cleanUpInteraction]):
    (-[WKContentView _keyboardDidShow]):

    If we previously deferred the call to `-_zoomToRevealFocusedElement` due to the keyboard still animating in,
    schedule a call to it now on a 0-delay timer; this delay is necessary to ensure that this zoom occurs *after*
    Mail has already set the content inset, which also happens underneath a "KeyboardDidShow" notification.

    (-[WKContentView _zoomToRevealFocusedElement]):

    In the case where the (presumably internal) client has set `firstResponderKeyboardAvoidanceEnabled` to NO and
    the keyboard is animating in, defer the actual call into the web view to `-_zoomToRevealFocusedElement` until
    after the keyboard animation is finished. This ensures compatibility with existant logic in Mail for manually
    setting the content scroll inset on the WKScrollView after the keyboard animation is complete.

    (-[WKContentView resetShouldZoomToFocusRectAfterShowingKeyboard]):
    (-[WKContentView _elementDidBlur]):

    Tools:

    Add support for a UIScriptController hook to override `firstResponderKeyboardAvoidanceEnabled` on WKScrollView.
    See LayoutTests for more details.

    * TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
    * TestRunnerShared/UIScriptContext/UIScriptController.h:
    (WTR::UIScriptController::setScrollViewKeyboardAvoidanceEnabled):
    * WebKitTestRunner/ios/TestControllerIOS.mm:
    (WTR::TestController::platformResetStateToConsistentValues):
    * WebKitTestRunner/ios/UIScriptControllerIOS.h:
    * WebKitTestRunner/ios/UIScriptControllerIOS.mm:
    (WTR::UIScriptControllerIOS::setScrollViewKeyboardAvoidanceEnabled):

    LayoutTests:

    Add a layout test that (at least) exercises the newly added codepath, where focusing an editor when the scroll
    view has `firstResponderKeyboardAvoidanceEnabled` set to NO will still allow us to scroll to the selection.

    * editing/selection/ios/scroll-to-reveal-selection-with-keyboard-avoidance-disabled-expected.txt: Added.
    * editing/selection/ios/scroll-to-reveal-selection-with-keyboard-avoidance-disabled.html: Added.
    * resources/ui-helper.js:
    (window.UIHelper.setScrollViewKeyboardAvoidanceEnabled):

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@288178 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Added Paths

Diff

Modified: branches/safari-613-branch/LayoutTests/ChangeLog (289281 => 289282)


--- branches/safari-613-branch/LayoutTests/ChangeLog	2022-02-08 02:53:46 UTC (rev 289281)
+++ branches/safari-613-branch/LayoutTests/ChangeLog	2022-02-08 02:53:53 UTC (rev 289282)
@@ -1,5 +1,110 @@
 2022-02-07  Russell Epstein  <[email protected]>
 
+        Cherry-pick r288178. rdar://problem/79296770
+
+    REGRESSION (r264352): Mail compose body field does not avoid the keyboard when scrolling after focus
+    https://bugs.webkit.org/show_bug.cgi?id=235331
+    rdar://79296770
+    
+    Reviewed by Tim Horton.
+    
+    Source/WebKit:
+    
+    After r264352 added the call to `_page->scheduleFullEditorStateUpdate();` during element focus, scrolling to
+    reveal the selection in the focused body field in Mail stopped working. This is because Mail:
+    
+    1.  Sets `firstResponderKeyboardAvoidanceEnabled` to NO on the WKScrollView, which prevents automatic inset
+        adjustment logic in UIKit from taking effect and adding the keyboard height to the bottom system content
+        inset.
+    
+    2.  Manually sets `-contentScrollInset` on the WKScrollView during a UIKeyboardDidShowNotification, which occurs
+        after we've already attempted to zoom to the selection.
+    
+    ...combined with the fact that without the call to `scheduleFullEditorStateUpdate()`, the next EditorState
+    would've arrived only after the keyboard animation finished.
+    
+    The end result is that we don't end up avoiding the keyboard at all when focusing the body field in Mail
+    compose. While rdar://87733414 tracks refactoring logic in WebKit2 Mail compose to ensure that the content
+    scroll insets on WKScrollView are applied during UIKeyboardWillShowNotification instead of after the keyboard
+    has finished animating in, this patch provides a short-term workaround by restoring pre-r264352 behavior, with
+    respect to when the element is scrolled into view.
+    
+    Test: editing/selection/ios/scroll-to-reveal-selection-with-keyboard-avoidance-disabled.html
+    
+    * Platform/spi/ios/UIKitSPI.h:
+    
+    Add a declaration for the `-firstResponderKeyboardAvoidanceEnabled` SPI property on non-internal iOS SDKs.
+    
+    * UIProcess/API/ios/WKWebViewIOS.mm:
+    (-[WKWebView _keyboardDidShow:]):
+    
+    Plumb this through to the WKContentView, so we can zoom/scroll to the focused element if needed.
+    
+    * UIProcess/WebPageProxy.h:
+    * UIProcess/ios/WKContentViewInteraction.h:
+    * UIProcess/ios/WKContentViewInteraction.mm:
+    (-[WKContentView cleanUpInteraction]):
+    (-[WKContentView _keyboardDidShow]):
+    
+    If we previously deferred the call to `-_zoomToRevealFocusedElement` due to the keyboard still animating in,
+    schedule a call to it now on a 0-delay timer; this delay is necessary to ensure that this zoom occurs *after*
+    Mail has already set the content inset, which also happens underneath a "KeyboardDidShow" notification.
+    
+    (-[WKContentView _zoomToRevealFocusedElement]):
+    
+    In the case where the (presumably internal) client has set `firstResponderKeyboardAvoidanceEnabled` to NO and
+    the keyboard is animating in, defer the actual call into the web view to `-_zoomToRevealFocusedElement` until
+    after the keyboard animation is finished. This ensures compatibility with existant logic in Mail for manually
+    setting the content scroll inset on the WKScrollView after the keyboard animation is complete.
+    
+    (-[WKContentView resetShouldZoomToFocusRectAfterShowingKeyboard]):
+    (-[WKContentView _elementDidBlur]):
+    
+    Tools:
+    
+    Add support for a UIScriptController hook to override `firstResponderKeyboardAvoidanceEnabled` on WKScrollView.
+    See LayoutTests for more details.
+    
+    * TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
+    * TestRunnerShared/UIScriptContext/UIScriptController.h:
+    (WTR::UIScriptController::setScrollViewKeyboardAvoidanceEnabled):
+    * WebKitTestRunner/ios/TestControllerIOS.mm:
+    (WTR::TestController::platformResetStateToConsistentValues):
+    * WebKitTestRunner/ios/UIScriptControllerIOS.h:
+    * WebKitTestRunner/ios/UIScriptControllerIOS.mm:
+    (WTR::UIScriptControllerIOS::setScrollViewKeyboardAvoidanceEnabled):
+    
+    LayoutTests:
+    
+    Add a layout test that (at least) exercises the newly added codepath, where focusing an editor when the scroll
+    view has `firstResponderKeyboardAvoidanceEnabled` set to NO will still allow us to scroll to the selection.
+    
+    * editing/selection/ios/scroll-to-reveal-selection-with-keyboard-avoidance-disabled-expected.txt: Added.
+    * editing/selection/ios/scroll-to-reveal-selection-with-keyboard-avoidance-disabled.html: Added.
+    * resources/ui-helper.js:
+    (window.UIHelper.setScrollViewKeyboardAvoidanceEnabled):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@288178 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2022-01-18  Wenson Hsieh  <[email protected]>
+
+            REGRESSION (r264352): Mail compose body field does not avoid the keyboard when scrolling after focus
+            https://bugs.webkit.org/show_bug.cgi?id=235331
+            rdar://79296770
+
+            Reviewed by Tim Horton.
+
+            Add a layout test that (at least) exercises the newly added codepath, where focusing an editor when the scroll
+            view has `firstResponderKeyboardAvoidanceEnabled` set to NO will still allow us to scroll to the selection.
+
+            * editing/selection/ios/scroll-to-reveal-selection-with-keyboard-avoidance-disabled-expected.txt: Added.
+            * editing/selection/ios/scroll-to-reveal-selection-with-keyboard-avoidance-disabled.html: Added.
+            * resources/ui-helper.js:
+            (window.UIHelper.setScrollViewKeyboardAvoidanceEnabled):
+
+2022-02-07  Russell Epstein  <[email protected]>
+
         Cherry-pick r288132. rdar://problem/87569029
 
     CSP: Improve handling of multiple policies

Added: branches/safari-613-branch/LayoutTests/editing/selection/ios/scroll-to-reveal-selection-with-keyboard-avoidance-disabled-expected.txt (0 => 289282)


--- branches/safari-613-branch/LayoutTests/editing/selection/ios/scroll-to-reveal-selection-with-keyboard-avoidance-disabled-expected.txt	                        (rev 0)
+++ branches/safari-613-branch/LayoutTests/editing/selection/ios/scroll-to-reveal-selection-with-keyboard-avoidance-disabled-expected.txt	2022-02-08 02:53:53 UTC (rev 289282)
@@ -0,0 +1,10 @@
+This test verifies that focusing an editable element causes us to scroll to reveal the selection, even if first responder keyboard avoidance is disabled on the web view's scroller. This test requires WebKitTestRunner.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS document.scrollingElement.scrollTop became different from 0
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: branches/safari-613-branch/LayoutTests/editing/selection/ios/scroll-to-reveal-selection-with-keyboard-avoidance-disabled.html (0 => 289282)


--- branches/safari-613-branch/LayoutTests/editing/selection/ios/scroll-to-reveal-selection-with-keyboard-avoidance-disabled.html	                        (rev 0)
+++ branches/safari-613-branch/LayoutTests/editing/selection/ios/scroll-to-reveal-selection-with-keyboard-avoidance-disabled.html	2022-02-08 02:53:53 UTC (rev 289282)
@@ -0,0 +1,34 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true ] -->
+<html>
+<head>
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<script src=""
+<script src=""
+<script>
+jsTestIsAsync = true;
+
+addEventListener("load", async () => {
+    document.designMode = "on";
+    description("This test verifies that focusing an editable element causes us to scroll to reveal the selection, even if first responder keyboard avoidance is disabled on the web view's scroller. This test requires WebKitTestRunner.");
+
+    await UIHelper.setScrollViewKeyboardAvoidanceEnabled(false);
+    await UIHelper.setHardwareKeyboardAttached(false);
+    await UIHelper.activateAndWaitForInputSessionAt(160, innerHeight - 50);
+
+    shouldBecomeDifferent("document.scrollingElement.scrollTop", "0", () => {
+        document.getElementById("content").remove();
+        finishJSTest();
+    });
+});
+</script>
+</head>
+<body>
+<pre id="console"></pre>
+<div id="content" style="font-size: 24px;">
+    <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
+    <p>Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
+    <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
+    <p>Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
+</div>
+</body>
+</html>
\ No newline at end of file

Modified: branches/safari-613-branch/LayoutTests/resources/ui-helper.js (289281 => 289282)


--- branches/safari-613-branch/LayoutTests/resources/ui-helper.js	2022-02-08 02:53:46 UTC (rev 289281)
+++ branches/safari-613-branch/LayoutTests/resources/ui-helper.js	2022-02-08 02:53:53 UTC (rev 289282)
@@ -1154,6 +1154,14 @@
         return new Promise(resolve => testRunner.runUIScript(`uiController.setViewScale(${scale})`, resolve));
     }
 
+    static setScrollViewKeyboardAvoidanceEnabled(enabled)
+    {
+        if (!this.isWebKit2())
+            return Promise.resolve();
+
+        return new Promise(resolve => testRunner.runUIScript(`uiController.setScrollViewKeyboardAvoidanceEnabled(${enabled})`, resolve));
+    }
+
     static resignFirstResponder()
     {
         if (!this.isWebKit2())

Modified: branches/safari-613-branch/Source/WebKit/ChangeLog (289281 => 289282)


--- branches/safari-613-branch/Source/WebKit/ChangeLog	2022-02-08 02:53:46 UTC (rev 289281)
+++ branches/safari-613-branch/Source/WebKit/ChangeLog	2022-02-08 02:53:53 UTC (rev 289282)
@@ -1,5 +1,152 @@
 2022-02-07  Russell Epstein  <[email protected]>
 
+        Cherry-pick r288178. rdar://problem/79296770
+
+    REGRESSION (r264352): Mail compose body field does not avoid the keyboard when scrolling after focus
+    https://bugs.webkit.org/show_bug.cgi?id=235331
+    rdar://79296770
+    
+    Reviewed by Tim Horton.
+    
+    Source/WebKit:
+    
+    After r264352 added the call to `_page->scheduleFullEditorStateUpdate();` during element focus, scrolling to
+    reveal the selection in the focused body field in Mail stopped working. This is because Mail:
+    
+    1.  Sets `firstResponderKeyboardAvoidanceEnabled` to NO on the WKScrollView, which prevents automatic inset
+        adjustment logic in UIKit from taking effect and adding the keyboard height to the bottom system content
+        inset.
+    
+    2.  Manually sets `-contentScrollInset` on the WKScrollView during a UIKeyboardDidShowNotification, which occurs
+        after we've already attempted to zoom to the selection.
+    
+    ...combined with the fact that without the call to `scheduleFullEditorStateUpdate()`, the next EditorState
+    would've arrived only after the keyboard animation finished.
+    
+    The end result is that we don't end up avoiding the keyboard at all when focusing the body field in Mail
+    compose. While rdar://87733414 tracks refactoring logic in WebKit2 Mail compose to ensure that the content
+    scroll insets on WKScrollView are applied during UIKeyboardWillShowNotification instead of after the keyboard
+    has finished animating in, this patch provides a short-term workaround by restoring pre-r264352 behavior, with
+    respect to when the element is scrolled into view.
+    
+    Test: editing/selection/ios/scroll-to-reveal-selection-with-keyboard-avoidance-disabled.html
+    
+    * Platform/spi/ios/UIKitSPI.h:
+    
+    Add a declaration for the `-firstResponderKeyboardAvoidanceEnabled` SPI property on non-internal iOS SDKs.
+    
+    * UIProcess/API/ios/WKWebViewIOS.mm:
+    (-[WKWebView _keyboardDidShow:]):
+    
+    Plumb this through to the WKContentView, so we can zoom/scroll to the focused element if needed.
+    
+    * UIProcess/WebPageProxy.h:
+    * UIProcess/ios/WKContentViewInteraction.h:
+    * UIProcess/ios/WKContentViewInteraction.mm:
+    (-[WKContentView cleanUpInteraction]):
+    (-[WKContentView _keyboardDidShow]):
+    
+    If we previously deferred the call to `-_zoomToRevealFocusedElement` due to the keyboard still animating in,
+    schedule a call to it now on a 0-delay timer; this delay is necessary to ensure that this zoom occurs *after*
+    Mail has already set the content inset, which also happens underneath a "KeyboardDidShow" notification.
+    
+    (-[WKContentView _zoomToRevealFocusedElement]):
+    
+    In the case where the (presumably internal) client has set `firstResponderKeyboardAvoidanceEnabled` to NO and
+    the keyboard is animating in, defer the actual call into the web view to `-_zoomToRevealFocusedElement` until
+    after the keyboard animation is finished. This ensures compatibility with existant logic in Mail for manually
+    setting the content scroll inset on the WKScrollView after the keyboard animation is complete.
+    
+    (-[WKContentView resetShouldZoomToFocusRectAfterShowingKeyboard]):
+    (-[WKContentView _elementDidBlur]):
+    
+    Tools:
+    
+    Add support for a UIScriptController hook to override `firstResponderKeyboardAvoidanceEnabled` on WKScrollView.
+    See LayoutTests for more details.
+    
+    * TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
+    * TestRunnerShared/UIScriptContext/UIScriptController.h:
+    (WTR::UIScriptController::setScrollViewKeyboardAvoidanceEnabled):
+    * WebKitTestRunner/ios/TestControllerIOS.mm:
+    (WTR::TestController::platformResetStateToConsistentValues):
+    * WebKitTestRunner/ios/UIScriptControllerIOS.h:
+    * WebKitTestRunner/ios/UIScriptControllerIOS.mm:
+    (WTR::UIScriptControllerIOS::setScrollViewKeyboardAvoidanceEnabled):
+    
+    LayoutTests:
+    
+    Add a layout test that (at least) exercises the newly added codepath, where focusing an editor when the scroll
+    view has `firstResponderKeyboardAvoidanceEnabled` set to NO will still allow us to scroll to the selection.
+    
+    * editing/selection/ios/scroll-to-reveal-selection-with-keyboard-avoidance-disabled-expected.txt: Added.
+    * editing/selection/ios/scroll-to-reveal-selection-with-keyboard-avoidance-disabled.html: Added.
+    * resources/ui-helper.js:
+    (window.UIHelper.setScrollViewKeyboardAvoidanceEnabled):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@288178 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2022-01-18  Wenson Hsieh  <[email protected]>
+
+            REGRESSION (r264352): Mail compose body field does not avoid the keyboard when scrolling after focus
+            https://bugs.webkit.org/show_bug.cgi?id=235331
+            rdar://79296770
+
+            Reviewed by Tim Horton.
+
+            After r264352 added the call to `_page->scheduleFullEditorStateUpdate();` during element focus, scrolling to
+            reveal the selection in the focused body field in Mail stopped working. This is because Mail:
+
+            1.  Sets `firstResponderKeyboardAvoidanceEnabled` to NO on the WKScrollView, which prevents automatic inset
+                adjustment logic in UIKit from taking effect and adding the keyboard height to the bottom system content
+                inset.
+
+            2.  Manually sets `-contentScrollInset` on the WKScrollView during a UIKeyboardDidShowNotification, which occurs
+                after we've already attempted to zoom to the selection.
+
+            ...combined with the fact that without the call to `scheduleFullEditorStateUpdate()`, the next EditorState
+            would've arrived only after the keyboard animation finished.
+
+            The end result is that we don't end up avoiding the keyboard at all when focusing the body field in Mail
+            compose. While rdar://87733414 tracks refactoring logic in WebKit2 Mail compose to ensure that the content
+            scroll insets on WKScrollView are applied during UIKeyboardWillShowNotification instead of after the keyboard
+            has finished animating in, this patch provides a short-term workaround by restoring pre-r264352 behavior, with
+            respect to when the element is scrolled into view.
+
+            Test: editing/selection/ios/scroll-to-reveal-selection-with-keyboard-avoidance-disabled.html
+
+            * Platform/spi/ios/UIKitSPI.h:
+
+            Add a declaration for the `-firstResponderKeyboardAvoidanceEnabled` SPI property on non-internal iOS SDKs.
+
+            * UIProcess/API/ios/WKWebViewIOS.mm:
+            (-[WKWebView _keyboardDidShow:]):
+
+            Plumb this through to the WKContentView, so we can zoom/scroll to the focused element if needed.
+
+            * UIProcess/WebPageProxy.h:
+            * UIProcess/ios/WKContentViewInteraction.h:
+            * UIProcess/ios/WKContentViewInteraction.mm:
+            (-[WKContentView cleanUpInteraction]):
+            (-[WKContentView _keyboardDidShow]):
+
+            If we previously deferred the call to `-_zoomToRevealFocusedElement` due to the keyboard still animating in,
+            schedule a call to it now on a 0-delay timer; this delay is necessary to ensure that this zoom occurs *after*
+            Mail has already set the content inset, which also happens underneath a "KeyboardDidShow" notification.
+
+            (-[WKContentView _zoomToRevealFocusedElement]):
+
+            In the case where the (presumably internal) client has set `firstResponderKeyboardAvoidanceEnabled` to NO and
+            the keyboard is animating in, defer the actual call into the web view to `-_zoomToRevealFocusedElement` until
+            after the keyboard animation is finished. This ensures compatibility with existant logic in Mail for manually
+            setting the content scroll inset on the WKScrollView after the keyboard animation is complete.
+
+            (-[WKContentView resetShouldZoomToFocusRectAfterShowingKeyboard]):
+            (-[WKContentView _elementDidBlur]):
+
+2022-02-07  Russell Epstein  <[email protected]>
+
         Cherry-pick r288128. rdar://problem/87711220
 
     Copy com.apple.WebKit.adattributiond.sb into place with other iOS sandbox profiles

Modified: branches/safari-613-branch/Source/WebKit/Platform/spi/ios/UIKitSPI.h (289281 => 289282)


--- branches/safari-613-branch/Source/WebKit/Platform/spi/ios/UIKitSPI.h	2022-02-08 02:53:46 UTC (rev 289281)
+++ branches/safari-613-branch/Source/WebKit/Platform/spi/ios/UIKitSPI.h	2022-02-08 02:53:53 UTC (rev 289282)
@@ -515,6 +515,7 @@
 @property (nonatomic, readonly) UIEdgeInsets _systemContentInset;
 @property (nonatomic, readonly) UIEdgeInsets _effectiveContentInset;
 @property (nonatomic, getter=_allowsAsyncScrollEvent, setter=_setAllowsAsyncScrollEvent:) BOOL _allowsAsyncScrollEvent;
+@property (nonatomic, getter=_isFirstResponderKeyboardAvoidanceEnabled, setter=_setFirstResponderKeyboardAvoidanceEnabled:) BOOL firstResponderKeyboardAvoidanceEnabled;
 @end
 
 typedef NS_ENUM(NSUInteger, UIScrollPhase) {

Modified: branches/safari-613-branch/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm (289281 => 289282)


--- branches/safari-613-branch/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm	2022-02-08 02:53:46 UTC (rev 289281)
+++ branches/safari-613-branch/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm	2022-02-08 02:53:53 UTC (rev 289282)
@@ -2492,6 +2492,7 @@
 - (void)_keyboardDidShow:(NSNotification *)notification
 {
     _page->setIsKeyboardAnimatingIn(false);
+    [_contentView _keyboardDidShow];
 }
 
 - (void)_keyboardWillHide:(NSNotification *)notification

Modified: branches/safari-613-branch/Source/WebKit/UIProcess/WebPageProxy.h (289281 => 289282)


--- branches/safari-613-branch/Source/WebKit/UIProcess/WebPageProxy.h	2022-02-08 02:53:46 UTC (rev 289281)
+++ branches/safari-613-branch/Source/WebKit/UIProcess/WebPageProxy.h	2022-02-08 02:53:53 UTC (rev 289282)
@@ -1619,6 +1619,7 @@
 
 #if PLATFORM(IOS_FAMILY)
     void setIsKeyboardAnimatingIn(bool isKeyboardAnimatingIn) { m_isKeyboardAnimatingIn = isKeyboardAnimatingIn; }
+    bool isKeyboardAnimatingIn() const { return m_isKeyboardAnimatingIn; }
 
     void setWaitingForPostLayoutEditorStateUpdateAfterFocusingElement(bool waitingForPostLayoutEditorStateUpdateAfterFocusingElement) { m_waitingForPostLayoutEditorStateUpdateAfterFocusingElement = waitingForPostLayoutEditorStateUpdateAfterFocusingElement; }
     bool waitingForPostLayoutEditorStateUpdateAfterFocusingElement() const { return m_waitingForPostLayoutEditorStateUpdateAfterFocusingElement; }

Modified: branches/safari-613-branch/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h (289281 => 289282)


--- branches/safari-613-branch/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h	2022-02-08 02:53:46 UTC (rev 289281)
+++ branches/safari-613-branch/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h	2022-02-08 02:53:53 UTC (rev 289282)
@@ -462,6 +462,7 @@
     BOOL _isRelinquishingFirstResponderToFocusedElement;
     BOOL _unsuppressSoftwareKeyboardAfterNextAutocorrectionContextUpdate;
     BOOL _isUnsuppressingSoftwareKeyboardUsingLastAutocorrectionContext;
+    BOOL _shouldZoomToFocusRectAfterShowingKeyboard;
 
     BOOL _focusRequiresStrongPasswordAssistance;
     BOOL _waitingForEditDragSnapshot;
@@ -600,6 +601,8 @@
 - (BOOL)_hasFocusedElement;
 - (void)_zoomToRevealFocusedElement;
 
+- (void)_keyboardDidShow;
+
 - (void)cancelPointersForGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer;
 - (std::optional<unsigned>)activeTouchIdentifierForGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer;
 

Modified: branches/safari-613-branch/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (289281 => 289282)


--- branches/safari-613-branch/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2022-02-08 02:53:46 UTC (rev 289281)
+++ branches/safari-613-branch/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2022-02-08 02:53:53 UTC (rev 289282)
@@ -1216,6 +1216,8 @@
     _pointerInteraction = nil;
 #endif
 
+    [self resetShouldZoomToFocusRectAfterShowingKeyboard];
+
 #if HAVE(PENCILKIT_TEXT_INPUT)
     [self cleanUpScribbleInteraction];
 #endif
@@ -2344,11 +2346,32 @@
     return boundingRect;
 }
 
+- (void)_keyboardDidShow
+{
+    if (!_shouldZoomToFocusRectAfterShowingKeyboard)
+        return;
+
+    // FIXME: This deferred call to -_zoomToRevealFocusedElement works around the fact that Mail compose
+    // disables automatic content inset adjustment using the keyboard height, and instead has logic to
+    // explicitly set WKScrollView's contentScrollInset after receiving UIKeyboardDidShowNotification.
+    // This means that if we -_zoomToRevealFocusedElement immediately after focusing the body field in
+    // Mail, we won't take the keyboard height into account when scrolling.
+    // Mitigate this by deferring the call to -_zoomToRevealFocusedElement in this case until after the
+    // keyboard has finished animating. We can revert this once rdar://87733414 is fixed.
+    [self resetShouldZoomToFocusRectAfterShowingKeyboard];
+    [self performSelector:@selector(_zoomToRevealFocusedElement) withObject:nil afterDelay:0];
+}
+
 - (void)_zoomToRevealFocusedElement
 {
     if (_suppressSelectionAssistantReasons || _activeTextInteractionCount)
         return;
 
+    if (!self._scroller.firstResponderKeyboardAvoidanceEnabled && _page->isKeyboardAnimatingIn()) {
+        _shouldZoomToFocusRectAfterShowingKeyboard = YES;
+        return;
+    }
+
     // In case user scaling is force enabled, do not use that scaling when zooming in with an input field.
     // Zooming above the page's default scale factor should only happen when the user performs it.
     [self _zoomToFocusRect:_focusedElementInformation.interactionRect
@@ -2360,6 +2383,12 @@
         forceScroll:[self requiresAccessoryView]];
 }
 
+- (void)resetShouldZoomToFocusRectAfterShowingKeyboard
+{
+    _shouldZoomToFocusRectAfterShowingKeyboard = NO;
+    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(_zoomToRevealFocusedElement) object:nil];
+}
+
 - (UIView *)inputView
 {
     return [_webView inputView];
@@ -6575,6 +6604,8 @@
     _focusRequiresStrongPasswordAssistance = NO;
     _additionalContextForStrongPasswordAssistance = nil;
 
+    [self resetShouldZoomToFocusRectAfterShowingKeyboard];
+
     // When defocusing an editable element reset a seen keydown before calling -_hideKeyboard so that we
     // re-evaluate whether we still need a keyboard when UIKit calls us back in -_requiresKeyboardWhenFirstResponder.
     if (editableChanged)

Modified: branches/safari-613-branch/Tools/ChangeLog (289281 => 289282)


--- branches/safari-613-branch/Tools/ChangeLog	2022-02-08 02:53:46 UTC (rev 289281)
+++ branches/safari-613-branch/Tools/ChangeLog	2022-02-08 02:53:53 UTC (rev 289282)
@@ -1,5 +1,114 @@
 2022-02-07  Russell Epstein  <[email protected]>
 
+        Cherry-pick r288178. rdar://problem/79296770
+
+    REGRESSION (r264352): Mail compose body field does not avoid the keyboard when scrolling after focus
+    https://bugs.webkit.org/show_bug.cgi?id=235331
+    rdar://79296770
+    
+    Reviewed by Tim Horton.
+    
+    Source/WebKit:
+    
+    After r264352 added the call to `_page->scheduleFullEditorStateUpdate();` during element focus, scrolling to
+    reveal the selection in the focused body field in Mail stopped working. This is because Mail:
+    
+    1.  Sets `firstResponderKeyboardAvoidanceEnabled` to NO on the WKScrollView, which prevents automatic inset
+        adjustment logic in UIKit from taking effect and adding the keyboard height to the bottom system content
+        inset.
+    
+    2.  Manually sets `-contentScrollInset` on the WKScrollView during a UIKeyboardDidShowNotification, which occurs
+        after we've already attempted to zoom to the selection.
+    
+    ...combined with the fact that without the call to `scheduleFullEditorStateUpdate()`, the next EditorState
+    would've arrived only after the keyboard animation finished.
+    
+    The end result is that we don't end up avoiding the keyboard at all when focusing the body field in Mail
+    compose. While rdar://87733414 tracks refactoring logic in WebKit2 Mail compose to ensure that the content
+    scroll insets on WKScrollView are applied during UIKeyboardWillShowNotification instead of after the keyboard
+    has finished animating in, this patch provides a short-term workaround by restoring pre-r264352 behavior, with
+    respect to when the element is scrolled into view.
+    
+    Test: editing/selection/ios/scroll-to-reveal-selection-with-keyboard-avoidance-disabled.html
+    
+    * Platform/spi/ios/UIKitSPI.h:
+    
+    Add a declaration for the `-firstResponderKeyboardAvoidanceEnabled` SPI property on non-internal iOS SDKs.
+    
+    * UIProcess/API/ios/WKWebViewIOS.mm:
+    (-[WKWebView _keyboardDidShow:]):
+    
+    Plumb this through to the WKContentView, so we can zoom/scroll to the focused element if needed.
+    
+    * UIProcess/WebPageProxy.h:
+    * UIProcess/ios/WKContentViewInteraction.h:
+    * UIProcess/ios/WKContentViewInteraction.mm:
+    (-[WKContentView cleanUpInteraction]):
+    (-[WKContentView _keyboardDidShow]):
+    
+    If we previously deferred the call to `-_zoomToRevealFocusedElement` due to the keyboard still animating in,
+    schedule a call to it now on a 0-delay timer; this delay is necessary to ensure that this zoom occurs *after*
+    Mail has already set the content inset, which also happens underneath a "KeyboardDidShow" notification.
+    
+    (-[WKContentView _zoomToRevealFocusedElement]):
+    
+    In the case where the (presumably internal) client has set `firstResponderKeyboardAvoidanceEnabled` to NO and
+    the keyboard is animating in, defer the actual call into the web view to `-_zoomToRevealFocusedElement` until
+    after the keyboard animation is finished. This ensures compatibility with existant logic in Mail for manually
+    setting the content scroll inset on the WKScrollView after the keyboard animation is complete.
+    
+    (-[WKContentView resetShouldZoomToFocusRectAfterShowingKeyboard]):
+    (-[WKContentView _elementDidBlur]):
+    
+    Tools:
+    
+    Add support for a UIScriptController hook to override `firstResponderKeyboardAvoidanceEnabled` on WKScrollView.
+    See LayoutTests for more details.
+    
+    * TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
+    * TestRunnerShared/UIScriptContext/UIScriptController.h:
+    (WTR::UIScriptController::setScrollViewKeyboardAvoidanceEnabled):
+    * WebKitTestRunner/ios/TestControllerIOS.mm:
+    (WTR::TestController::platformResetStateToConsistentValues):
+    * WebKitTestRunner/ios/UIScriptControllerIOS.h:
+    * WebKitTestRunner/ios/UIScriptControllerIOS.mm:
+    (WTR::UIScriptControllerIOS::setScrollViewKeyboardAvoidanceEnabled):
+    
+    LayoutTests:
+    
+    Add a layout test that (at least) exercises the newly added codepath, where focusing an editor when the scroll
+    view has `firstResponderKeyboardAvoidanceEnabled` set to NO will still allow us to scroll to the selection.
+    
+    * editing/selection/ios/scroll-to-reveal-selection-with-keyboard-avoidance-disabled-expected.txt: Added.
+    * editing/selection/ios/scroll-to-reveal-selection-with-keyboard-avoidance-disabled.html: Added.
+    * resources/ui-helper.js:
+    (window.UIHelper.setScrollViewKeyboardAvoidanceEnabled):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@288178 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2022-01-18  Wenson Hsieh  <[email protected]>
+
+            REGRESSION (r264352): Mail compose body field does not avoid the keyboard when scrolling after focus
+            https://bugs.webkit.org/show_bug.cgi?id=235331
+            rdar://79296770
+
+            Reviewed by Tim Horton.
+
+            Add support for a UIScriptController hook to override `firstResponderKeyboardAvoidanceEnabled` on WKScrollView.
+            See LayoutTests for more details.
+
+            * TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
+            * TestRunnerShared/UIScriptContext/UIScriptController.h:
+            (WTR::UIScriptController::setScrollViewKeyboardAvoidanceEnabled):
+            * WebKitTestRunner/ios/TestControllerIOS.mm:
+            (WTR::TestController::platformResetStateToConsistentValues):
+            * WebKitTestRunner/ios/UIScriptControllerIOS.h:
+            * WebKitTestRunner/ios/UIScriptControllerIOS.mm:
+            (WTR::UIScriptControllerIOS::setScrollViewKeyboardAvoidanceEnabled):
+
+2022-02-07  Russell Epstein  <[email protected]>
+
         Cherry-pick r287992. rdar://problem/74845918
 
     Crash in Document::updateStyleIfNeeded() when removing a node containing the drag caret

Modified: branches/safari-613-branch/Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl (289281 => 289282)


--- branches/safari-613-branch/Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl	2022-02-08 02:53:46 UTC (rev 289281)
+++ branches/safari-613-branch/Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl	2022-02-08 02:53:53 UTC (rev 289282)
@@ -285,6 +285,8 @@
     undefined setMinimumEffectiveWidth(double effectiveWidth);
     undefined setAllowsViewportShrinkToFit(boolean allows);
 
+    undefined setScrollViewKeyboardAvoidanceEnabled(boolean enabled);
+
     undefined becomeFirstResponder();
     undefined resignFirstResponder();
     readonly attribute boolean isPresentingModally;

Modified: branches/safari-613-branch/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h (289281 => 289282)


--- branches/safari-613-branch/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h	2022-02-08 02:53:46 UTC (rev 289281)
+++ branches/safari-613-branch/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h	2022-02-08 02:53:53 UTC (rev 289282)
@@ -97,6 +97,8 @@
     virtual void setMinimumEffectiveWidth(double) { notImplemented(); }
     virtual void setAllowsViewportShrinkToFit(bool) { notImplemented(); }
 
+    virtual void setScrollViewKeyboardAvoidanceEnabled(bool) { notImplemented(); }
+
     virtual std::optional<bool> stableStateOverride() const { notImplemented(); return std::nullopt; }
     virtual void setStableStateOverride(std::optional<bool>) { notImplemented(); }
 

Modified: branches/safari-613-branch/Tools/WebKitTestRunner/ios/TestControllerIOS.mm (289281 => 289282)


--- branches/safari-613-branch/Tools/WebKitTestRunner/ios/TestControllerIOS.mm	2022-02-08 02:53:46 UTC (rev 289281)
+++ branches/safari-613-branch/Tools/WebKitTestRunner/ios/TestControllerIOS.mm	2022-02-08 02:53:53 UTC (rev 289282)
@@ -227,6 +227,7 @@
         UIScrollView *scrollView = webView.scrollView;
         [scrollView _removeAllAnimations:YES];
         [scrollView setZoomScale:1 animated:NO];
+        scrollView.firstResponderKeyboardAvoidanceEnabled = YES;
 
         auto currentContentInset = scrollView.contentInset;
         auto contentInsetTop = options.contentInsetTop();

Modified: branches/safari-613-branch/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.h (289281 => 289282)


--- branches/safari-613-branch/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.h	2022-02-08 02:53:46 UTC (rev 289281)
+++ branches/safari-613-branch/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.h	2022-02-08 02:53:53 UTC (rev 289282)
@@ -146,6 +146,7 @@
     void copyText(JSStringRef) override;
     void installTapGestureOnWindow(JSValueRef) override;
     void setSpellCheckerResults(JSValueRef) override { }
+    void setScrollViewKeyboardAvoidanceEnabled(bool) override;
 
     bool mayContainEditableElementsInRect(unsigned x, unsigned y, unsigned width, unsigned height) override;
 

Modified: branches/safari-613-branch/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm (289281 => 289282)


--- branches/safari-613-branch/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm	2022-02-08 02:53:46 UTC (rev 289281)
+++ branches/safari-613-branch/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm	2022-02-08 02:53:53 UTC (rev 289282)
@@ -1272,6 +1272,11 @@
     webView()._allowsViewportShrinkToFit = allows;
 }
 
+void UIScriptControllerIOS::setScrollViewKeyboardAvoidanceEnabled(bool enabled)
+{
+    webView().scrollView.firstResponderKeyboardAvoidanceEnabled = enabled;
+}
+
 void UIScriptControllerIOS::doAfterDoubleTapDelay(JSValueRef callback)
 {
     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to