Changeset 243153 in webkit


Ignore:
Timestamp:
Mar 19, 2019 11:25:21 AM (5 years ago)
Author:
dbates@webkit.org
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):

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r243149 r243153  
     12019-03-19  Daniel Bates  <dabates@apple.com>
     2
     3        [iOS] Focus not preserved when switching between tabs
     4        https://bugs.webkit.org/show_bug.cgi?id=195820
     5        <rdar://problem/43614450>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        Fixes a usability annoyance when using a hardware keyboard; focus is not preserved when switching between tabs.
     10        Do not unconditionally tell the WebProcess to blur the currently focused element when the content view (WKContentView)
     11        resigns first responder. Instead only tell it to blur when the content view is resigning because either the
     12        accessory view was dismissed (Done button was pressed) or the keyboard was dismissed (the hide keyboard button
     13        was pressed).
     14
     15        * UIProcess/ios/WKContentViewInteraction.h:
     16        * UIProcess/ios/WKContentViewInteraction.mm: Add new ivar to track whether the content view is resigning
     17        first responder status because the accessory view is being dismissed.
     18        (-[WKContentView resignFirstResponderForWebView]): Only tell WebKit to blur the focused element if we are
     19        resigning because the accessory view is being dismissed or the keyboard was hidden. We continue to do all
     20        other steps when resigning, including hiding the keyboard. Note that by not telling WebKit to blur the
     21        focused element we let it's focus controller manage the focused element with respect to the current
     22        page activation state (i.e. whether the content view is first responder or not). When the content view
     23        becomes the first responder then WebKit's focus controller will be told that the page has become activated
     24        and will tell the UIProcess to focus the currently focused element, which will bring up the keyboard.
     25        (-[WKContentView accessoryDone]): Update state so we know that a subsequent call to resign first responder
     26        was due to the accessory view being dismissed.
     27
    1282019-03-19  Per Arne Vollan  <pvollan@apple.com>
    229
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h

    r243102 r243153  
    312312    BOOL _becomingFirstResponder;
    313313    BOOL _resigningFirstResponder;
     314    BOOL _dismissingAccessory;
    314315    BOOL _needsDeferredEndScrollingSelectionUpdate;
    315316    BOOL _isChangingFocus;
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm

    r243102 r243153  
    11751175        // We need to complete the editing operation before we blur the element.
    11761176        [self _endEditing];
    1177         _page->blurFocusedElement();
     1177        if (_dismissingAccessory || _keyboardDidRequestDismissal)
     1178            _page->blurFocusedElement();
    11781179    }
    11791180
     
    36923693- (void)accessoryDone
    36933694{
     3695    SetForScope<BOOL> dismissingAccessoryScope { _dismissingAccessory, YES };
    36943696    [self resignFirstResponder];
    36953697}
  • trunk/Tools/ChangeLog

    r243141 r243153  
     12019-03-19  Daniel Bates  <dabates@apple.com>
     2
     3        [iOS] Focus not preserved when switching between tabs
     4        https://bugs.webkit.org/show_bug.cgi?id=195820
     5        <rdar://problem/43614450>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        Add tests to ensure that we restore focus when resigning and becoming first responder.
     10
     11        * TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm:
     12        (TestWebKitAPI::TEST):
     13
    1142019-03-19  Alex Christensen  <achristensen@webkit.org>
    215
  • trunk/Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm

    r242339 r243153  
    275275}
    276276
    277 TEST(KeyboardInputTests, CaretSelectionRectAfterRestoringFirstResponder)
     277TEST(KeyboardInputTests, CaretSelectionRectAfterRestoringFirstResponderWithRetainActiveFocusedState)
    278278{
    279279    auto expectedCaretRect = CGRectMake(16, 13, 2, 15);
     
    291291}
    292292
    293 TEST(KeyboardInputTests, RangedSelectionRectAfterRestoringFirstResponder)
     293TEST(KeyboardInputTests, RangedSelectionRectAfterRestoringFirstResponderWithRetainActiveFocusedState)
    294294{
    295295    NSArray *expectedSelectionRects = @[ [NSValue valueWithCGRect:CGRectMake(16, 13, 24, 15)] ];
     
    304304    [webView resignFirstResponder];
    305305    restoreActiveFocusState();
     306    [webView waitForSelectionViewRectsToBecome:@[ ]];
     307
     308    [webView becomeFirstResponder];
     309    [webView waitForSelectionViewRectsToBecome:expectedSelectionRects];
     310}
     311
     312TEST(KeyboardInputTests, CaretSelectionRectAfterRestoringFirstResponder)
     313{
     314    auto expectedCaretRect = CGRectMake(16, 13, 2, 15);
     315    auto webView = webViewWithAutofocusedInput();
     316    EXPECT_WK_STREQ("INPUT", [webView stringByEvaluatingJavaScript:@"document.activeElement.tagName"]);
     317    [webView waitForCaretViewFrameToBecome:expectedCaretRect];
     318
     319    [webView resignFirstResponder];
     320    [webView waitForCaretViewFrameToBecome:CGRectZero];
     321
     322    [webView becomeFirstResponder];
     323    [webView waitForCaretViewFrameToBecome:expectedCaretRect];
     324}
     325
     326TEST(KeyboardInputTests, RangedSelectionRectAfterRestoringFirstResponder)
     327{
     328    NSArray *expectedSelectionRects = @[ [NSValue valueWithCGRect:CGRectMake(16, 13, 24, 15)] ];
     329
     330    auto webView = webViewWithAutofocusedInput();
     331    [[webView textInputContentView] insertText:@"hello"];
     332    [webView selectAll:nil];
     333    EXPECT_WK_STREQ("INPUT", [webView stringByEvaluatingJavaScript:@"document.activeElement.tagName"]);
     334    [webView waitForSelectionViewRectsToBecome:expectedSelectionRects];
     335
     336    [webView resignFirstResponder];
    306337    [webView waitForSelectionViewRectsToBecome:@[ ]];
    307338
Note: See TracChangeset for help on using the changeset viewer.