Title: [243153] trunk
Revision
243153
Author
[email protected]
Date
2019-03-19 11:25:21 -0700 (Tue, 19 Mar 2019)

Log Message

[iOS] Focus not preserved when switching between tabs
https://bugs.webkit.org/show_bug.cgi?id=195820
<rdar://problem/43614450>

Reviewed by Brent Fulgham.

Source/WebKit:

Fixes a usability annoyance when using a hardware keyboard; focus is not preserved when switching between tabs.
Do not unconditionally tell the WebProcess to blur the currently focused element when the content view (WKContentView)
resigns first responder. Instead only tell it to blur when the content view is resigning because either the
accessory view was dismissed (Done button was pressed) or the keyboard was dismissed (the hide keyboard button
was pressed).

* UIProcess/ios/WKContentViewInteraction.h:
* UIProcess/ios/WKContentViewInteraction.mm: Add new ivar to track whether the content view is resigning
first responder status because the accessory view is being dismissed.
(-[WKContentView resignFirstResponderForWebView]): Only tell WebKit to blur the focused element if we are
resigning because the accessory view is being dismissed or the keyboard was hidden. We continue to do all
other steps when resigning, including hiding the keyboard. Note that by not telling WebKit to blur the
focused element we let it's focus controller manage the focused element with respect to the current
page activation state (i.e. whether the content view is first responder or not). When the content view
becomes the first responder then WebKit's focus controller will be told that the page has become activated
and will tell the UIProcess to focus the currently focused element, which will bring up the keyboard.
(-[WKContentView accessoryDone]): Update state so we know that a subsequent call to resign first responder
was due to the accessory view being dismissed.

Tools:

Add tests to ensure that we restore focus when resigning and becoming first responder.

* TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm:
(TestWebKitAPI::TEST):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (243152 => 243153)


--- trunk/Source/WebKit/ChangeLog	2019-03-19 18:03:33 UTC (rev 243152)
+++ trunk/Source/WebKit/ChangeLog	2019-03-19 18:25:21 UTC (rev 243153)
@@ -1,3 +1,30 @@
+2019-03-19  Daniel Bates  <[email protected]>
+
+        [iOS] Focus not preserved when switching between tabs
+        https://bugs.webkit.org/show_bug.cgi?id=195820
+        <rdar://problem/43614450>
+
+        Reviewed by Brent Fulgham.
+
+        Fixes a usability annoyance when using a hardware keyboard; focus is not preserved when switching between tabs.
+        Do not unconditionally tell the WebProcess to blur the currently focused element when the content view (WKContentView)
+        resigns first responder. Instead only tell it to blur when the content view is resigning because either the
+        accessory view was dismissed (Done button was pressed) or the keyboard was dismissed (the hide keyboard button
+        was pressed).
+
+        * UIProcess/ios/WKContentViewInteraction.h:
+        * UIProcess/ios/WKContentViewInteraction.mm: Add new ivar to track whether the content view is resigning
+        first responder status because the accessory view is being dismissed.
+        (-[WKContentView resignFirstResponderForWebView]): Only tell WebKit to blur the focused element if we are
+        resigning because the accessory view is being dismissed or the keyboard was hidden. We continue to do all
+        other steps when resigning, including hiding the keyboard. Note that by not telling WebKit to blur the
+        focused element we let it's focus controller manage the focused element with respect to the current
+        page activation state (i.e. whether the content view is first responder or not). When the content view
+        becomes the first responder then WebKit's focus controller will be told that the page has become activated
+        and will tell the UIProcess to focus the currently focused element, which will bring up the keyboard.
+        (-[WKContentView accessoryDone]): Update state so we know that a subsequent call to resign first responder
+        was due to the accessory view being dismissed.
+
 2019-03-19  Per Arne Vollan  <[email protected]>
 
         [iOS] Remove overridden rules in sandbox

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h (243152 => 243153)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h	2019-03-19 18:03:33 UTC (rev 243152)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h	2019-03-19 18:25:21 UTC (rev 243153)
@@ -311,6 +311,7 @@
 
     BOOL _becomingFirstResponder;
     BOOL _resigningFirstResponder;
+    BOOL _dismissingAccessory;
     BOOL _needsDeferredEndScrollingSelectionUpdate;
     BOOL _isChangingFocus;
     BOOL _isBlurringFocusedElement;

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (243152 => 243153)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2019-03-19 18:03:33 UTC (rev 243152)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2019-03-19 18:25:21 UTC (rev 243153)
@@ -1174,7 +1174,8 @@
     if (!_webView._retainingActiveFocusedState) {
         // We need to complete the editing operation before we blur the element.
         [self _endEditing];
-        _page->blurFocusedElement();
+        if (_dismissingAccessory || _keyboardDidRequestDismissal)
+            _page->blurFocusedElement();
     }
 
     [self _cancelInteraction];
@@ -3691,6 +3692,7 @@
 // UIWebFormAccessoryDelegate
 - (void)accessoryDone
 {
+    SetForScope<BOOL> dismissingAccessoryScope { _dismissingAccessory, YES };
     [self resignFirstResponder];
 }
 

Modified: trunk/Tools/ChangeLog (243152 => 243153)


--- trunk/Tools/ChangeLog	2019-03-19 18:03:33 UTC (rev 243152)
+++ trunk/Tools/ChangeLog	2019-03-19 18:25:21 UTC (rev 243153)
@@ -1,3 +1,16 @@
+2019-03-19  Daniel Bates  <[email protected]>
+
+        [iOS] Focus not preserved when switching between tabs
+        https://bugs.webkit.org/show_bug.cgi?id=195820
+        <rdar://problem/43614450>
+
+        Reviewed by Brent Fulgham.
+
+        Add tests to ensure that we restore focus when resigning and becoming first responder.
+
+        * TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm:
+        (TestWebKitAPI::TEST):
+
 2019-03-19  Alex Christensen  <[email protected]>
 
         Make WTFLogChannelState and WTFLogLevel enum classes

Modified: trunk/Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm (243152 => 243153)


--- trunk/Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm	2019-03-19 18:03:33 UTC (rev 243152)
+++ trunk/Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm	2019-03-19 18:25:21 UTC (rev 243153)
@@ -274,7 +274,7 @@
     EXPECT_WK_STREQ("a", [webView stringByEvaluatingJavaScript:@"document.querySelector('input').value"]);
 }
 
-TEST(KeyboardInputTests, CaretSelectionRectAfterRestoringFirstResponder)
+TEST(KeyboardInputTests, CaretSelectionRectAfterRestoringFirstResponderWithRetainActiveFocusedState)
 {
     auto expectedCaretRect = CGRectMake(16, 13, 2, 15);
     auto webView = webViewWithAutofocusedInput();
@@ -290,7 +290,7 @@
     [webView waitForCaretViewFrameToBecome:expectedCaretRect];
 }
 
-TEST(KeyboardInputTests, RangedSelectionRectAfterRestoringFirstResponder)
+TEST(KeyboardInputTests, RangedSelectionRectAfterRestoringFirstResponderWithRetainActiveFocusedState)
 {
     NSArray *expectedSelectionRects = @[ [NSValue valueWithCGRect:CGRectMake(16, 13, 24, 15)] ];
 
@@ -309,6 +309,37 @@
     [webView waitForSelectionViewRectsToBecome:expectedSelectionRects];
 }
 
+TEST(KeyboardInputTests, CaretSelectionRectAfterRestoringFirstResponder)
+{
+    auto expectedCaretRect = CGRectMake(16, 13, 2, 15);
+    auto webView = webViewWithAutofocusedInput();
+    EXPECT_WK_STREQ("INPUT", [webView stringByEvaluatingJavaScript:@"document.activeElement.tagName"]);
+    [webView waitForCaretViewFrameToBecome:expectedCaretRect];
+
+    [webView resignFirstResponder];
+    [webView waitForCaretViewFrameToBecome:CGRectZero];
+
+    [webView becomeFirstResponder];
+    [webView waitForCaretViewFrameToBecome:expectedCaretRect];
+}
+
+TEST(KeyboardInputTests, RangedSelectionRectAfterRestoringFirstResponder)
+{
+    NSArray *expectedSelectionRects = @[ [NSValue valueWithCGRect:CGRectMake(16, 13, 24, 15)] ];
+
+    auto webView = webViewWithAutofocusedInput();
+    [[webView textInputContentView] insertText:@"hello"];
+    [webView selectAll:nil];
+    EXPECT_WK_STREQ("INPUT", [webView stringByEvaluatingJavaScript:@"document.activeElement.tagName"]);
+    [webView waitForSelectionViewRectsToBecome:expectedSelectionRects];
+
+    [webView resignFirstResponder];
+    [webView waitForSelectionViewRectsToBecome:@[ ]];
+
+    [webView becomeFirstResponder];
+    [webView waitForSelectionViewRectsToBecome:expectedSelectionRects];
+}
+
 TEST(KeyboardInputTests, KeyboardTypeForInput)
 {
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to