⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 277386 in webkit


Ignore:
Timestamp:
May 12, 2021, 1:40:15 PM (5 years ago)
Author:
Aditya Keerthi
Message:

REGRESSION (r275297): Unexpected autofocus when switching tabs
https://bugs.webkit.org/show_bug.cgi?id=225710
<rdar://problem/77542939>

Reviewed by Wenson Hsieh.

r275297 introduced logic to handle a focus environment change by
advancing to the next or previous focusable element, depending on the
focus context's heading direction. This logic enables a tab or a
shift+tab to change the focus from browser chrome directly to an
element on a web page.

However, the focus environment can change through mechanisms other than
tab / shift+tab. One example of this is when a user switches tabs. In
these cases, the UIFocusHeading supplied by the focus context is
UIFocusHeadingNone. Nevertheless, we unconditionally call
-[WKContentView _becomeFirstResponderWithSelectionMovingForward:completionHandler:]
when the focus context changes. Consequently, an element on the web page
is always focused when the WKContentView gains focus.

  • UIProcess/ios/WKContentView.mm:

(-[WKContentView didUpdateFocusInContext:withAnimationCoordinator:]):

To fix, ensure we only focus an element on the page if the focus heading
is UIFocusHeadingNext or UIFocusHeadingPrevious. UIFocusHeadingNext will
focus the first focusable element, while UIFocusHeadingPrevious will focus
the last focusable element.

Note that a call to -[WKContentView becomeFirstResponder] is not made
if the focus heading is UIFocusHeadingNone. From my testing, I observed
that the view already was the first responder in that case.

Location:
trunk/Source/WebKit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r277380 r277386  
     12021-05-12  Aditya Keerthi  <akeerthi@apple.com>
     2
     3        REGRESSION (r275297): Unexpected autofocus when switching tabs
     4        https://bugs.webkit.org/show_bug.cgi?id=225710
     5        <rdar://problem/77542939>
     6
     7        Reviewed by Wenson Hsieh.
     8
     9        r275297 introduced logic to handle a focus environment change by
     10        advancing to the next or previous focusable element, depending on the
     11        focus context's heading direction. This logic enables a tab or a
     12        shift+tab to change the focus from browser chrome directly to an
     13        element on a web page.
     14
     15        However, the focus environment can change through mechanisms other than
     16        tab / shift+tab. One example of this is when a user switches tabs. In
     17        these cases, the UIFocusHeading supplied by the focus context is
     18        UIFocusHeadingNone. Nevertheless, we unconditionally call
     19        `-[WKContentView _becomeFirstResponderWithSelectionMovingForward:completionHandler:]`
     20        when the focus context changes. Consequently, an element on the web page
     21        is always focused when the WKContentView gains focus.
     22
     23        * UIProcess/ios/WKContentView.mm:
     24        (-[WKContentView didUpdateFocusInContext:withAnimationCoordinator:]):
     25
     26        To fix, ensure we only focus an element on the page if the focus heading
     27        is UIFocusHeadingNext or UIFocusHeadingPrevious. UIFocusHeadingNext will
     28        focus the first focusable element, while UIFocusHeadingPrevious will focus
     29        the last focusable element.
     30
     31        Note that a call to `-[WKContentView becomeFirstResponder]` is not made
     32        if the focus heading is UIFocusHeadingNone. From my testing, I observed
     33        that the view already was the first responder in that case.
     34
    1352021-05-12  Chris Dumez  <cdumez@apple.com>
    236
  • trunk/Source/WebKit/UIProcess/ios/WKContentView.mm

    r276523 r277386  
    556556- (void)didUpdateFocusInContext:(UIFocusUpdateContext *)context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator
    557557{
    558     if (context.nextFocusedView == self)
    559         [self _becomeFirstResponderWithSelectionMovingForward:context.focusHeading == UIFocusHeadingNext completionHandler:nil];
     558    if (context.nextFocusedView == self) {
     559        if (context.focusHeading & UIFocusHeadingNext)
     560            [self _becomeFirstResponderWithSelectionMovingForward:YES completionHandler:nil];
     561        else if (context.focusHeading & UIFocusHeadingPrevious)
     562            [self _becomeFirstResponderWithSelectionMovingForward:NO completionHandler:nil];
     563    }
    560564}
    561565
Note: See TracChangeset for help on using the changeset viewer.