- Revision
- 291770
- Author
- [email protected]
- Date
- 2022-03-23 15:07:06 -0700 (Wed, 23 Mar 2022)
Log Message
[iOS] Mail compose web view no longer scrolls to reveal selection upon showing the keyboard
https://bugs.webkit.org/show_bug.cgi?id=238271
rdar://89821087
Reviewed by Tim Horton.
Source/WebKit:
When a certain UIKit feature is enabled on certain builds of iOS, Mail compose no longer scrolls to reveal the
selection range or caret. This is because we have logic to defer scrolling/zooming to reveal the selection after
focusing the body element, for reasons outlined in trac.webkit.org/r288178. However, when the feature flag is
enabled, UIKeyboardWillShowNotification is no longer fired synchronously underneath the call to
`-reloadInputViews`, which means that `isKeyboardAnimatingIn()` will (most of the time) return false upon
calling `-_zoomToRevealFocusedElement` when receiving the next post-layout editor state update.
To mitigate this, add a new boolean flag, `_waitingForKeyboardToStartAnimatingInAfterElementFocus`, that's set
right before we reload input views when focusing an element that requires the keyboard (either software or
hardware), and unset when we observe the "WillShow" notification. In addition to checking
`_page->isKeyboardAnimatingIn()` when determining whether to defer zooming, we check this new flag as well.
Covered by an existing layout test (which currently fails when the aforementioned UIKit feature is enabled):
editing/selection/ios/scroll-to-reveal-selection-with-keyboard-avoidance-disabled.html
* UIProcess/API/ios/WKWebViewIOS.mm:
(-[WKWebView _keyboardWillShow:]):
* UIProcess/ios/WKContentViewInteraction.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView cleanUpInteraction]):
(-[WKContentView _keyboardWillShow]):
(-[WKContentView _zoomToRevealFocusedElement]):
(-[WKContentView _elementDidFocus:userIsInteracting:blurPreviousNode:activityStateChanges:userObject:]):
(-[WKContentView _elementDidBlur]):
LayoutTests:
While I'm here, adjust the test to ensure that the keyboard is hidden afterwards. When running this test back to
back with the relevant UIKit feature flag enabled, it sometimes fails without this adjustment, due to keyboard
disappearance notifications triggered from prior test invocations being fired in subsequent test invocations.
* editing/selection/ios/scroll-to-reveal-selection-with-keyboard-avoidance-disabled.html:
Modified Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (291769 => 291770)
--- trunk/LayoutTests/ChangeLog 2022-03-23 21:57:34 UTC (rev 291769)
+++ trunk/LayoutTests/ChangeLog 2022-03-23 22:07:06 UTC (rev 291770)
@@ -1,3 +1,17 @@
+2022-03-23 Wenson Hsieh <[email protected]>
+
+ [iOS] Mail compose web view no longer scrolls to reveal selection upon showing the keyboard
+ https://bugs.webkit.org/show_bug.cgi?id=238271
+ rdar://89821087
+
+ Reviewed by Tim Horton.
+
+ While I'm here, adjust the test to ensure that the keyboard is hidden afterwards. When running this test back to
+ back with the relevant UIKit feature flag enabled, it sometimes fails without this adjustment, due to keyboard
+ disappearance notifications triggered from prior test invocations being fired in subsequent test invocations.
+
+ * editing/selection/ios/scroll-to-reveal-selection-with-keyboard-avoidance-disabled.html:
+
2022-03-23 Andres Gonzalez <[email protected]>
ITM: Fix for accessibility/table-attributes.html in isolated tree mode.
Modified: trunk/LayoutTests/editing/selection/ios/scroll-to-reveal-selection-with-keyboard-avoidance-disabled.html (291769 => 291770)
--- trunk/LayoutTests/editing/selection/ios/scroll-to-reveal-selection-with-keyboard-avoidance-disabled.html 2022-03-23 21:57:34 UTC (rev 291769)
+++ trunk/LayoutTests/editing/selection/ios/scroll-to-reveal-selection-with-keyboard-avoidance-disabled.html 2022-03-23 22:07:06 UTC (rev 291770)
@@ -15,8 +15,10 @@
await UIHelper.setHardwareKeyboardAttached(false);
await UIHelper.activateAndWaitForInputSessionAt(160, innerHeight - 50);
- shouldBecomeDifferent("document.scrollingElement.scrollTop", "0", () => {
+ shouldBecomeDifferent("document.scrollingElement.scrollTop", "0", async () => {
document.getElementById("content").remove();
+ document.activeElement.blur();
+ await UIHelper.waitForKeyboardToHide();
finishJSTest();
});
});
Modified: trunk/Source/WebKit/ChangeLog (291769 => 291770)
--- trunk/Source/WebKit/ChangeLog 2022-03-23 21:57:34 UTC (rev 291769)
+++ trunk/Source/WebKit/ChangeLog 2022-03-23 22:07:06 UTC (rev 291770)
@@ -1,3 +1,36 @@
+2022-03-23 Wenson Hsieh <[email protected]>
+
+ [iOS] Mail compose web view no longer scrolls to reveal selection upon showing the keyboard
+ https://bugs.webkit.org/show_bug.cgi?id=238271
+ rdar://89821087
+
+ Reviewed by Tim Horton.
+
+ When a certain UIKit feature is enabled on certain builds of iOS, Mail compose no longer scrolls to reveal the
+ selection range or caret. This is because we have logic to defer scrolling/zooming to reveal the selection after
+ focusing the body element, for reasons outlined in trac.webkit.org/r288178. However, when the feature flag is
+ enabled, UIKeyboardWillShowNotification is no longer fired synchronously underneath the call to
+ `-reloadInputViews`, which means that `isKeyboardAnimatingIn()` will (most of the time) return false upon
+ calling `-_zoomToRevealFocusedElement` when receiving the next post-layout editor state update.
+
+ To mitigate this, add a new boolean flag, `_waitingForKeyboardToStartAnimatingInAfterElementFocus`, that's set
+ right before we reload input views when focusing an element that requires the keyboard (either software or
+ hardware), and unset when we observe the "WillShow" notification. In addition to checking
+ `_page->isKeyboardAnimatingIn()` when determining whether to defer zooming, we check this new flag as well.
+
+ Covered by an existing layout test (which currently fails when the aforementioned UIKit feature is enabled):
+ editing/selection/ios/scroll-to-reveal-selection-with-keyboard-avoidance-disabled.html
+
+ * UIProcess/API/ios/WKWebViewIOS.mm:
+ (-[WKWebView _keyboardWillShow:]):
+ * UIProcess/ios/WKContentViewInteraction.h:
+ * UIProcess/ios/WKContentViewInteraction.mm:
+ (-[WKContentView cleanUpInteraction]):
+ (-[WKContentView _keyboardWillShow]):
+ (-[WKContentView _zoomToRevealFocusedElement]):
+ (-[WKContentView _elementDidFocus:userIsInteracting:blurPreviousNode:activityStateChanges:userObject:]):
+ (-[WKContentView _elementDidBlur]):
+
2022-03-23 J Pascoe <[email protected]>
[WebAuthn] Specify correct ASCPublicKeyCredentialKind in configureAssertionOptions
Modified: trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm (291769 => 291770)
--- trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm 2022-03-23 21:57:34 UTC (rev 291769)
+++ trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm 2022-03-23 22:07:06 UTC (rev 291770)
@@ -2541,6 +2541,7 @@
[self _keyboardChangedWithInfo:notification.userInfo adjustScrollView:YES];
_page->setIsKeyboardAnimatingIn(true);
+ [_contentView _keyboardWillShow];
}
- (void)_keyboardDidShow:(NSNotification *)notification
Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h (291769 => 291770)
--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h 2022-03-23 21:57:34 UTC (rev 291769)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h 2022-03-23 22:07:06 UTC (rev 291770)
@@ -465,6 +465,7 @@
BOOL _isRelinquishingFirstResponderToFocusedElement;
BOOL _unsuppressSoftwareKeyboardAfterNextAutocorrectionContextUpdate;
BOOL _isUnsuppressingSoftwareKeyboardUsingLastAutocorrectionContext;
+ BOOL _waitingForKeyboardToStartAnimatingInAfterElementFocus;
BOOL _shouldZoomToFocusRectAfterShowingKeyboard;
BOOL _focusRequiresStrongPasswordAssistance;
@@ -610,6 +611,7 @@
- (BOOL)_hasFocusedElement;
- (void)_zoomToRevealFocusedElement;
+- (void)_keyboardWillShow;
- (void)_keyboardDidShow;
- (void)cancelPointersForGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer;
Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (291769 => 291770)
--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm 2022-03-23 21:57:34 UTC (rev 291769)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm 2022-03-23 22:07:06 UTC (rev 291770)
@@ -1165,6 +1165,7 @@
_interactionViewsContainerView = nil;
}
+ _waitingForKeyboardToStartAnimatingInAfterElementFocus = NO;
_lastInsertedCharacterToOverrideCharacterBeforeSelection = std::nullopt;
[_touchEventGestureRecognizer setDelegate:nil];
@@ -2372,6 +2373,11 @@
return boundingRect;
}
+- (void)_keyboardWillShow
+{
+ _waitingForKeyboardToStartAnimatingInAfterElementFocus = NO;
+}
+
- (void)_keyboardDidShow
{
if (!_shouldZoomToFocusRectAfterShowingKeyboard)
@@ -2396,7 +2402,8 @@
if (_suppressSelectionAssistantReasons || _activeTextInteractionCount)
return;
- if (!self._scroller.firstResponderKeyboardAvoidanceEnabled && _page->isKeyboardAnimatingIn()) {
+ if (!self._scroller.firstResponderKeyboardAvoidanceEnabled
+ && (_page->isKeyboardAnimatingIn() || _waitingForKeyboardToStartAnimatingInAfterElementFocus)) {
_shouldZoomToFocusRectAfterShowingKeyboard = YES;
return;
}
@@ -6773,8 +6780,8 @@
if (delegateImplementsWillStartInputSession)
[inputDelegate _webView:self.webView willStartInputSession:_formInputSession.get()];
- BOOL isSelectable = mayContainSelectableText(information.elementType);
- BOOL editableChanged = [self setIsEditable:isSelectable];
+ BOOL requiresKeyboard = mayContainSelectableText(information.elementType);
+ BOOL editableChanged = [self setIsEditable:requiresKeyboard];
_focusedElementInformation = information;
_traits = nil;
@@ -6781,7 +6788,7 @@
if (![self isFirstResponder])
[self becomeFirstResponder];
- if (!_suppressSelectionAssistantReasons && isSelectable && activityStateChanges.contains(WebCore::ActivityState::IsFocused)) {
+ if (!_suppressSelectionAssistantReasons && requiresKeyboard && activityStateChanges.contains(WebCore::ActivityState::IsFocused)) {
_treatAsContentEditableUntilNextEditorStateUpdate = YES;
[_textInteractionAssistant activateSelection];
_page->restoreSelectionInFocusedEditableElement();
@@ -6789,6 +6796,7 @@
}
_inputPeripheral = createInputPeripheralWithView(_focusedElementInformation.elementType, self);
+ _waitingForKeyboardToStartAnimatingInAfterElementFocus = requiresKeyboard;
#if HAVE(PEPPER_UI_CORE)
[self addFocusedFormControlOverlay];
@@ -6798,7 +6806,7 @@
[self reloadInputViews];
#endif
- if (isSelectable) {
+ if (requiresKeyboard) {
[self _showKeyboard];
if (!self.window.keyWindow)
[self.window makeKeyWindow];
@@ -6811,8 +6819,7 @@
// For elements that have selectable content (e.g. text field) we need to wait for the web process to send an up-to-date
// selection rect before we can zoom and reveal the selection. Non-selectable elements (e.g. <select>) can be zoomed
// immediately because they have no selection to reveal.
- BOOL needsEditorStateUpdate = mayContainSelectableText(_focusedElementInformation.elementType);
- if (needsEditorStateUpdate)
+ if (requiresKeyboard)
_page->setWaitingForPostLayoutEditorStateUpdateAfterFocusingElement(true);
else
[self _zoomToRevealFocusedElement];
@@ -6860,6 +6867,7 @@
_focusRequiresStrongPasswordAssistance = NO;
_autocorrectionContextNeedsUpdate = YES;
_additionalContextForStrongPasswordAssistance = nil;
+ _waitingForKeyboardToStartAnimatingInAfterElementFocus = NO;
[self resetShouldZoomToFocusRectAfterShowingKeyboard];