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

Changeset 275297 in webkit


Ignore:
Timestamp:
Mar 31, 2021, 11:33:39 AM (5 years ago)
Author:
Wenson Hsieh
Message:

WKContentView should support UIKit protocol methods for becoming focused
https://bugs.webkit.org/show_bug.cgi?id=224003
<rdar://problem/75313658>

Reviewed by Megan Gardner.

Source/WebKit:

Implement a few protocol methods on UIFocusEnvironment. See below for more details.

Test: UIFocusTests.OverrideCanBecomeFocused

  • UIProcess/API/ios/WKWebViewIOS.mm:

(-[WKWebView canBecomeFocused]):

  • UIProcess/ios/WKContentView.h:
  • UIProcess/ios/WKContentView.mm:

(-[WKContentView canBecomeFocused]):
(-[WKContentView canBecomeFocusedForWebView]):

Implement -canBecomeFocused, and return YES by default. If -canBecomeFocused is overridden on WKWebView,
then defer to that overridden method instead.

(-[WKContentView didUpdateFocusInContext:withAnimationCoordinator:]):

Handle the focus environment change by advancing to the next or previous focusable element, depending on the
focus context's heading direction.

  • UIProcess/ios/WKContentViewInteraction.mm:

(-[WKContentView _becomeFirstResponderWithSelectionMovingForward:completionHandler:]):

Add a null check so that callers that don't need to know when the focus change is complete are able to pass in a
nil completion handler.

Tools:

Add a test to verify that the vaue of -[WKContentView canBecomeFocused] can be overridden by subclassing
-[WKWebView canBecomeFocused].

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/ios/UIFocusTests.mm: Added.

(-[UIFocusTestWKWebView canBecomeFocused]):

Location:
trunk
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r275294 r275297  
     12021-03-31  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        WKContentView should support UIKit protocol methods for becoming focused
     4        https://bugs.webkit.org/show_bug.cgi?id=224003
     5        <rdar://problem/75313658>
     6
     7        Reviewed by Megan Gardner.
     8
     9        Implement a few protocol methods on `UIFocusEnvironment`. See below for more details.
     10
     11        Test: UIFocusTests.OverrideCanBecomeFocused
     12
     13        * UIProcess/API/ios/WKWebViewIOS.mm:
     14        (-[WKWebView canBecomeFocused]):
     15        * UIProcess/ios/WKContentView.h:
     16        * UIProcess/ios/WKContentView.mm:
     17        (-[WKContentView canBecomeFocused]):
     18        (-[WKContentView canBecomeFocusedForWebView]):
     19
     20        Implement `-canBecomeFocused`, and return `YES` by default. If `-canBecomeFocused` is overridden on `WKWebView`,
     21        then defer to that overridden method instead.
     22
     23        (-[WKContentView didUpdateFocusInContext:withAnimationCoordinator:]):
     24
     25        Handle the focus environment change by advancing to the next or previous focusable element, depending on the
     26        focus context's heading direction.
     27
     28        * UIProcess/ios/WKContentViewInteraction.mm:
     29        (-[WKContentView _becomeFirstResponderWithSelectionMovingForward:completionHandler:]):
     30
     31        Add a null check so that callers that don't need to know when the focus change is complete are able to pass in a
     32        `nil` completion handler.
     33
    1342021-03-31  Youenn Fablet  <youenn@apple.com>
    235
  • trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm

    r275046 r275297  
    25192519}
    25202520
     2521- (BOOL)canBecomeFocused
     2522{
     2523    if (self.usesStandardContentView)
     2524        return [_contentView canBecomeFocusedForWebView];
     2525
     2526    return [_customContentView canBecomeFocused];
     2527}
     2528
    25212529@end
    25222530
  • trunk/Source/WebKit/UIProcess/ios/WKContentView.h

    r271771 r275297  
    7272@property (nonatomic) BOOL sizeChangedSinceLastVisibleContentRectUpdate;
    7373@property (nonatomic, readonly) UIInterfaceOrientation interfaceOrientation;
     74@property (nonatomic, readonly) BOOL canBecomeFocusedForWebView;
    7475
    7576- (instancetype)initWithFrame:(CGRect)frame processPool:(NakedRef<WebKit::WebProcessPool>)processPool configuration:(Ref<API::PageConfiguration>&&)configuration webView:(WKWebView *)webView;
  • trunk/Source/WebKit/UIProcess/ios/WKContentView.mm

    r274822 r275297  
    532532}
    533533
     534- (BOOL)canBecomeFocused
     535{
     536    return [_webView canBecomeFocused];
     537}
     538
     539- (BOOL)canBecomeFocusedForWebView
     540{
     541    return YES;
     542}
     543
     544- (void)didUpdateFocusInContext:(UIFocusUpdateContext *)context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator
     545{
     546    [self _becomeFirstResponderWithSelectionMovingForward:context.focusHeading == UIFocusHeadingNext completionHandler:nil];
     547}
     548
    534549#pragma mark Internal
    535550
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm

    r275270 r275297  
    45494549    constexpr bool isKeyboardEventValid = false;
    45504550    _page->setInitialFocus(selectingForward, isKeyboardEventValid, { }, [protectedSelf = retainPtr(self), completionHandler = makeBlockPtr(completionHandler)] {
    4551         completionHandler([protectedSelf becomeFirstResponder]);
     4551        if (completionHandler)
     4552            completionHandler([protectedSelf becomeFirstResponder]);
    45524553    });
    45534554}
  • trunk/Tools/ChangeLog

    r275290 r275297  
     12021-03-31  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        WKContentView should support UIKit protocol methods for becoming focused
     4        https://bugs.webkit.org/show_bug.cgi?id=224003
     5        <rdar://problem/75313658>
     6
     7        Reviewed by Megan Gardner.
     8
     9        Add a test to verify that the vaue of `-[WKContentView canBecomeFocused]` can be overridden by subclassing
     10        `-[WKWebView canBecomeFocused]`.
     11
     12        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     13        * TestWebKitAPI/Tests/ios/UIFocusTests.mm: Added.
     14        (-[UIFocusTestWKWebView canBecomeFocused]):
     15
    1162021-03-31  Alex Christensen  <achristensen@webkit.org>
    217
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r275267 r275297  
    11881188                F460F65B261119580064F2B6 /* InjectedBundleHitTestPlugIn.mm in Sources */ = {isa = PBXBuildFile; fileRef = F460F659261117E70064F2B6 /* InjectedBundleHitTestPlugIn.mm */; };
    11891189                F460F669261263370064F2B6 /* simple-responsive-page.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F460F668261262C70064F2B6 /* simple-responsive-page.html */; };
     1190                F460F6752614DE2F0064F2B6 /* UIFocusTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = F460F6742614DE2F0064F2B6 /* UIFocusTests.mm */; };
    11901191                F46128B7211C8ED500D9FADB /* DragAndDropSimulatorMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = F46128B6211C8ED500D9FADB /* DragAndDropSimulatorMac.mm */; };
    11911192                F46128CB211D475100D9FADB /* TestDraggingInfo.mm in Sources */ = {isa = PBXBuildFile; fileRef = F46128CA211D475100D9FADB /* TestDraggingInfo.mm */; };
     
    29952996                F460F65A2611183F0064F2B6 /* InjectedBundleHitTestProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = InjectedBundleHitTestProtocol.h; sourceTree = "<group>"; };
    29962997                F460F668261262C70064F2B6 /* simple-responsive-page.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "simple-responsive-page.html"; sourceTree = "<group>"; };
     2998                F460F6742614DE2F0064F2B6 /* UIFocusTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = UIFocusTests.mm; sourceTree = "<group>"; };
    29972999                F46128B4211C861A00D9FADB /* DragAndDropSimulator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DragAndDropSimulator.h; path = cocoa/DragAndDropSimulator.h; sourceTree = "<group>"; };
    29983000                F46128B6211C8ED500D9FADB /* DragAndDropSimulatorMac.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = DragAndDropSimulatorMac.mm; sourceTree = "<group>"; };
     
    37753777                                F45E15752112CE6200307E82 /* TestInputDelegate.mm */,
    37763778                                F45033F4206BEC95009351CE /* TextAutosizingBoost.mm */,
     3779                                F460F6742614DE2F0064F2B6 /* UIFocusTests.mm */,
    37773780                                F46849BD1EEF58E400B937FE /* UIPasteboardTests.mm */,
    37783781                                F402F56B23ECC2FB00865549 /* UIWKInteractionViewProtocol.mm */,
     
    56815684                                57152B7821DD4E8D000C37CA /* U2fCommandConstructorTest.cpp in Sources */,
    56825685                                5CB40B4E1F4B98D3007DC7B9 /* UIDelegate.mm in Sources */,
     5686                                F460F6752614DE2F0064F2B6 /* UIFocusTests.mm in Sources */,
    56835687                                F46849BE1EEF58E400B937FE /* UIPasteboardTests.mm in Sources */,
    56845688                                F402F56C23ECC2FB00865549 /* UIWKInteractionViewProtocol.mm in Sources */,
Note: See TracChangeset for help on using the changeset viewer.