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

Changeset 286823 in webkit


Ignore:
Timestamp:
Dec 9, 2021, 6:16:28 PM (5 years ago)
Author:
Aditya Keerthi
Message:

[iOS] Add SPI to enable find interactions on WKWebView
https://bugs.webkit.org/show_bug.cgi?id=234017
rdar://86140542

Reviewed by Wenson Hsieh.

Source/WebKit:

  • Platform/spi/ios/UIKitSPI.h:
  • UIProcess/API/Cocoa/WKWebView.mm:

(-[WKWebView _initializeWithConfiguration:]):

  • UIProcess/API/Cocoa/WKWebViewInternal.h:
  • UIProcess/API/Cocoa/WKWebViewPrivate.h:
  • UIProcess/API/ios/WKWebViewIOS.mm:

(-[WKWebView _findInteractionEnabled]):
(-[WKWebView _setFindInteractionEnabled:]):

Make the contentView the searchableObject, rather than self (the WKWebView)
to avoid a retain cycle.

(-[WKWebView _findInteraction]):
(-[WKWebView offsetFromPosition:toPosition:inDocument:]):
(-[WKWebView decorateFoundTextRange:inDocument:usingStyle:]):

  • UIProcess/ios/WKContentViewInteraction.h:

Make WKContentView conform to _UITextSearching so that it can be set as
the interaction's searchableObject.

  • UIProcess/ios/WKContentViewInteraction.mm:

(-[WKContentView decorateFoundTextRange:inDocument:usingStyle:]):
(-[WKContentView offsetFromPosition:toPosition:inDocument:]):
(-[WKContentView decorateFoundTextRange:usingStyle:]): Deleted.

Tools:

  • TestWebKitAPI/Tests/WebKitCocoa/FindInPage.mm:

(TEST):

Test that the new SPI installs a _UIFindInteraction on the web view.

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r286816 r286823  
     12021-12-09  Aditya Keerthi  <akeerthi@apple.com>
     2
     3        [iOS] Add SPI to enable find interactions on WKWebView
     4        https://bugs.webkit.org/show_bug.cgi?id=234017
     5        rdar://86140542
     6
     7        Reviewed by Wenson Hsieh.
     8
     9        * Platform/spi/ios/UIKitSPI.h:
     10        * UIProcess/API/Cocoa/WKWebView.mm:
     11        (-[WKWebView _initializeWithConfiguration:]):
     12        * UIProcess/API/Cocoa/WKWebViewInternal.h:
     13        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
     14        * UIProcess/API/ios/WKWebViewIOS.mm:
     15        (-[WKWebView _findInteractionEnabled]):
     16        (-[WKWebView _setFindInteractionEnabled:]):
     17
     18        Make the contentView the searchableObject, rather than self (the WKWebView)
     19        to avoid a retain cycle.
     20
     21        (-[WKWebView _findInteraction]):
     22        (-[WKWebView offsetFromPosition:toPosition:inDocument:]):
     23        (-[WKWebView decorateFoundTextRange:inDocument:usingStyle:]):
     24        * UIProcess/ios/WKContentViewInteraction.h:
     25
     26        Make WKContentView conform to _UITextSearching so that it can be set as
     27        the interaction's searchableObject.
     28
     29        * UIProcess/ios/WKContentViewInteraction.mm:
     30        (-[WKContentView decorateFoundTextRange:inDocument:usingStyle:]):
     31        (-[WKContentView offsetFromPosition:toPosition:inDocument:]):
     32        (-[WKContentView decorateFoundTextRange:usingStyle:]): Deleted.
     33
    1342021-12-09  Alex Christensen  <achristensen@webkit.org>
    235
  • trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h

    r286641 r286823  
    132132
    133133#if HAVE(UIFINDINTERACTION)
     134#import <UIKit/_UIFindInteraction.h>
    134135#import <UIKit/_UITextSearching.h>
    135136#endif
     
    327328- (void)clearAllDecoratedFoundText;
    328329
     330@end
     331
     332@interface _UIFindInteraction : NSObject <UIInteraction>
     333@property (nonatomic, strong) id<_UITextSearching> searchableObject;
    329334@end
    330335
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm

    r286815 r286823  
    368368    _allowsLinkPreview = linkedOnOrAfter(WebCore::SDKVersion::FirstWithLinkPreviewEnabledByDefault);
    369369
     370#if HAVE(UIFINDINTERACTION)
     371    _findInteractionEnabled = NO;
     372#endif
     373
    370374    auto fastClickingEnabled = []() {
    371375        if (NSNumber *enabledValue = [[NSUserDefaults standardUserDefaults] objectForKey:@"WebKitFastClickingDisabled"])
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h

    r284628 r286823  
    152152#endif
    153153
     154#if HAVE(UIFINDINTERACTION)
     155    RetainPtr<_UIFindInteraction> _findInteraction;
     156    BOOL _findInteractionEnabled;
     157#endif
     158
    154159    RetainPtr<_WKRemoteObjectRegistry> _remoteObjectRegistry;
    155160
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h

    r286751 r286823  
    2525
    2626#if TARGET_OS_IPHONE
     27#if __has_include(<UIKit/_UIFindInteraction.h>)
     28#import <UIKit/_UIFindInteraction.h>
     29#endif
    2730#if __has_include(<UIKit/_UITextSearching.h>)
    2831#import <UIKit/_UITextSearching.h>
     
    439442@property (nonatomic, copy, setter=_setEphemeralUIEventAttribution:) UIEventAttribution *_ephemeralUIEventAttribution WK_API_AVAILABLE(ios(WK_IOS_TBA));
    440443- (void)_setEphemeralUIEventAttribution:(UIEventAttribution *)attribution forApplicationWithBundleID:(NSString *)bundleID WK_API_AVAILABLE(ios(WK_IOS_TBA));
     444
     445#if __has_include(<UIKit/_UIFindInteraction.h>)
     446@property (nonatomic, readonly) _UIFindInteraction *_findInteraction WK_API_AVAILABLE(ios(WK_IOS_TBA));
     447@property (nonatomic, readwrite, setter=_setFindInteractionEnabled:) BOOL _findInteractionEnabled WK_API_AVAILABLE(ios(WK_IOS_TBA));
     448#endif
     449
    441450#endif
    442451
  • trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm

    r286641 r286823  
    34843484#if HAVE(UIFINDINTERACTION)
    34853485
     3486- (BOOL)_findInteractionEnabled
     3487{
     3488    return _findInteractionEnabled;
     3489}
     3490
     3491- (void)_setFindInteractionEnabled:(BOOL)enabled
     3492{
     3493    if (_findInteractionEnabled != enabled) {
     3494        _findInteractionEnabled = enabled;
     3495
     3496        if (enabled) {
     3497            if (!_findInteraction) {
     3498                _findInteraction = adoptNS([[_UIFindInteraction alloc] init]);
     3499                [_findInteraction setSearchableObject:_contentView.get()];
     3500            }
     3501
     3502            [self addInteraction:_findInteraction.get()];
     3503        } else {
     3504            [self removeInteraction:_findInteraction.get()];
     3505            _findInteraction = nil;
     3506        }
     3507    }
     3508}
     3509
     3510- (_UIFindInteraction *)_findInteraction
     3511{
     3512    return _findInteraction.get();
     3513}
     3514
    34863515- (UITextRange *)selectedTextRange
    34873516{
     
    34913520- (NSInteger)offsetFromPosition:(UITextPosition *)from toPosition:(UITextPosition *)toPosition inDocument:(_UITextSearchDocumentIdentifier)document
    34923521{
    3493     return [_contentView offsetFromPosition:from toPosition:toPosition];
     3522    return [_contentView offsetFromPosition:from toPosition:toPosition inDocument:document];
    34943523}
    34953524
     
    35013530- (void)decorateFoundTextRange:(UITextRange *)range inDocument:(_UITextSearchDocumentIdentifier)document usingStyle:(_UIFoundTextStyle)style
    35023531{
    3503     [_contentView decorateFoundTextRange:range usingStyle:style];
     3532    [_contentView decorateFoundTextRange:range inDocument:document usingStyle:style];
    35043533}
    35053534
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h

    r286705 r286823  
    538538    , WKHoverPlatterDelegate
    539539#endif
     540#if HAVE(UIFINDINTERACTION)
     541    , _UITextSearching
     542#endif
    540543>
    541544
     
    715718- (void)clearTextIndicator:(WebCore::TextIndicatorDismissalAnimation)animation;
    716719
    717 #if HAVE(UIFINDINTERACTION)
    718 - (void)performTextSearchWithQueryString:(NSString *)string usingOptions:(_UITextSearchOptions *)options resultAggregator:(id<_UITextSearchAggregator>)aggregator;
    719 - (void)decorateFoundTextRange:(UITextRange *)range usingStyle:(_UIFoundTextStyle)style;
    720 - (void)clearAllDecoratedFoundText;
    721 #endif
    722 
    723720@property (nonatomic, readonly) BOOL _shouldUseContextMenus;
    724721@property (nonatomic, readonly) BOOL _shouldUseContextMenusForFormControls;
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm

    r286705 r286823  
    99889988}
    99899989
    9990 - (void)decorateFoundTextRange:(UITextRange *)range usingStyle:(_UIFoundTextStyle)style
     9990- (void)decorateFoundTextRange:(UITextRange *)range inDocument:(_UITextSearchDocumentIdentifier)document usingStyle:(_UIFoundTextStyle)style
    99919991{
    99929992    if (![range isKindOfClass:[WKFoundTextRange class]])
     
    1000510005    _foundHighlightedTextRange = nil;
    1000610006    _page->hideFindUI();
     10007}
     10008
     10009- (NSInteger)offsetFromPosition:(UITextPosition *)from toPosition:(UITextPosition *)toPosition inDocument:(_UITextSearchDocumentIdentifier)document
     10010{
     10011    return [self offsetFromPosition:from toPosition:toPosition];
    1000710012}
    1000810013
  • trunk/Tools/ChangeLog

    r286817 r286823  
     12021-12-09  Aditya Keerthi  <akeerthi@apple.com>
     2
     3        [iOS] Add SPI to enable find interactions on WKWebView
     4        https://bugs.webkit.org/show_bug.cgi?id=234017
     5        rdar://86140542
     6
     7        Reviewed by Wenson Hsieh.
     8
     9        * TestWebKitAPI/Tests/WebKitCocoa/FindInPage.mm:
     10        (TEST):
     11
     12        Test that the new SPI installs a _UIFindInteraction on the web view.
     13
    1142021-12-09  Lauro Moura  <lmoura@igalia.com>
    215
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/FindInPage.mm

    r286660 r286823  
    453453}
    454454
     455TEST(WebKit, FindInteraction)
     456{
     457    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)]);
     458
     459    EXPECT_NULL([webView _findInteraction]);
     460
     461    [webView _setFindInteractionEnabled:YES];
     462    EXPECT_NOT_NULL([webView _findInteraction]);
     463
     464    [webView _setFindInteractionEnabled:NO];
     465    EXPECT_NULL([webView _findInteraction]);
     466}
     467
    455468#endif // HAVE(UIFINDINTERACTION)
Note: See TracChangeset for help on using the changeset viewer.