Diff
Modified: trunk/Source/WebKit/ChangeLog (286822 => 286823)
--- trunk/Source/WebKit/ChangeLog 2021-12-10 02:07:11 UTC (rev 286822)
+++ trunk/Source/WebKit/ChangeLog 2021-12-10 02:16:28 UTC (rev 286823)
@@ -1,3 +1,36 @@
+2021-12-09 Aditya Keerthi <akeer...@apple.com>
+
+ [iOS] Add SPI to enable find interactions on WKWebView
+ https://bugs.webkit.org/show_bug.cgi?id=234017
+ rdar://86140542
+
+ Reviewed by Wenson Hsieh.
+
+ * 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.
+
2021-12-09 Alex Christensen <achristen...@webkit.org>
Prepare for transition to C++20
Modified: trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h (286822 => 286823)
--- trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h 2021-12-10 02:07:11 UTC (rev 286822)
+++ trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h 2021-12-10 02:16:28 UTC (rev 286823)
@@ -131,6 +131,7 @@
#endif
#if HAVE(UIFINDINTERACTION)
+#import <UIKit/_UIFindInteraction.h>
#import <UIKit/_UITextSearching.h>
#endif
@@ -328,6 +329,10 @@
@end
+@interface _UIFindInteraction : NSObject <UIInteraction>
+@property (nonatomic, strong) id<_UITextSearching> searchableObject;
+@end
+
#endif // HAVE(UIFINDINTERACTION)
typedef enum {
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (286822 => 286823)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm 2021-12-10 02:07:11 UTC (rev 286822)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm 2021-12-10 02:16:28 UTC (rev 286823)
@@ -367,6 +367,10 @@
_allowsViewportShrinkToFit = defaultAllowsViewportShrinkToFit;
_allowsLinkPreview = linkedOnOrAfter(WebCore::SDKVersion::FirstWithLinkPreviewEnabledByDefault);
+#if HAVE(UIFINDINTERACTION)
+ _findInteractionEnabled = NO;
+#endif
+
auto fastClickingEnabled = []() {
if (NSNumber *enabledValue = [[NSUserDefaults standardUserDefaults] objectForKey:@"WebKitFastClickingDisabled"])
return enabledValue.boolValue;
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h (286822 => 286823)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h 2021-12-10 02:07:11 UTC (rev 286822)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h 2021-12-10 02:16:28 UTC (rev 286823)
@@ -151,6 +151,11 @@
RetainPtr<WKFullScreenWindowController> _fullScreenWindowController;
#endif
+#if HAVE(UIFINDINTERACTION)
+ RetainPtr<_UIFindInteraction> _findInteraction;
+ BOOL _findInteractionEnabled;
+#endif
+
RetainPtr<_WKRemoteObjectRegistry> _remoteObjectRegistry;
std::optional<CGSize> _viewLayoutSizeOverride;
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h (286822 => 286823)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h 2021-12-10 02:07:11 UTC (rev 286822)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h 2021-12-10 02:16:28 UTC (rev 286823)
@@ -24,6 +24,9 @@
*/
#if TARGET_OS_IPHONE
+#if __has_include(<UIKit/_UIFindInteraction.h>)
+#import <UIKit/_UIFindInteraction.h>
+#endif
#if __has_include(<UIKit/_UITextSearching.h>)
#import <UIKit/_UITextSearching.h>
#endif
@@ -438,8 +441,14 @@
@property (nonatomic, copy, setter=_setUIEventAttribution:) UIEventAttribution *_uiEventAttribution WK_API_AVAILABLE(ios(15.0));
@property (nonatomic, copy, setter=_setEphemeralUIEventAttribution:) UIEventAttribution *_ephemeralUIEventAttribution WK_API_AVAILABLE(ios(WK_IOS_TBA));
- (void)_setEphemeralUIEventAttribution:(UIEventAttribution *)attribution forApplicationWithBundleID:(NSString *)bundleID WK_API_AVAILABLE(ios(WK_IOS_TBA));
+
+#if __has_include(<UIKit/_UIFindInteraction.h>)
+@property (nonatomic, readonly) _UIFindInteraction *_findInteraction WK_API_AVAILABLE(ios(WK_IOS_TBA));
+@property (nonatomic, readwrite, setter=_setFindInteractionEnabled:) BOOL _findInteractionEnabled WK_API_AVAILABLE(ios(WK_IOS_TBA));
#endif
+#endif
+
@property (nonatomic, readonly) CGRect _contentVisibleRect WK_API_AVAILABLE(ios(10.0));
// DERECATED: The setters of the three following function are deprecated, please use overrideLayoutParameters.
Modified: trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm (286822 => 286823)
--- trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm 2021-12-10 02:07:11 UTC (rev 286822)
+++ trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm 2021-12-10 02:16:28 UTC (rev 286823)
@@ -3483,6 +3483,35 @@
#if HAVE(UIFINDINTERACTION)
+- (BOOL)_findInteractionEnabled
+{
+ return _findInteractionEnabled;
+}
+
+- (void)_setFindInteractionEnabled:(BOOL)enabled
+{
+ if (_findInteractionEnabled != enabled) {
+ _findInteractionEnabled = enabled;
+
+ if (enabled) {
+ if (!_findInteraction) {
+ _findInteraction = adoptNS([[_UIFindInteraction alloc] init]);
+ [_findInteraction setSearchableObject:_contentView.get()];
+ }
+
+ [self addInteraction:_findInteraction.get()];
+ } else {
+ [self removeInteraction:_findInteraction.get()];
+ _findInteraction = nil;
+ }
+ }
+}
+
+- (_UIFindInteraction *)_findInteraction
+{
+ return _findInteraction.get();
+}
+
- (UITextRange *)selectedTextRange
{
return nil;
@@ -3490,7 +3519,7 @@
- (NSInteger)offsetFromPosition:(UITextPosition *)from toPosition:(UITextPosition *)toPosition inDocument:(_UITextSearchDocumentIdentifier)document
{
- return [_contentView offsetFromPosition:from toPosition:toPosition];
+ return [_contentView offsetFromPosition:from toPosition:toPosition inDocument:document];
}
- (void)performTextSearchWithQueryString:(NSString *)string usingOptions:(_UITextSearchOptions *)options resultAggregator:(id<_UITextSearchAggregator>)aggregator
@@ -3500,7 +3529,7 @@
- (void)decorateFoundTextRange:(UITextRange *)range inDocument:(_UITextSearchDocumentIdentifier)document usingStyle:(_UIFoundTextStyle)style
{
- [_contentView decorateFoundTextRange:range usingStyle:style];
+ [_contentView decorateFoundTextRange:range inDocument:document usingStyle:style];
}
- (void)clearAllDecoratedFoundText
Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h (286822 => 286823)
--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h 2021-12-10 02:07:11 UTC (rev 286822)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h 2021-12-10 02:16:28 UTC (rev 286823)
@@ -537,6 +537,9 @@
#if HAVE(UIKIT_WITH_MOUSE_SUPPORT) || ENABLE(HOVER_GESTURE_RECOGNIZER)
, WKHoverPlatterDelegate
#endif
+#if HAVE(UIFINDINTERACTION)
+ , _UITextSearching
+#endif
>
@property (nonatomic, readonly) CGPoint lastInteractionLocation;
@@ -714,12 +717,6 @@
- (void)setTextIndicatorAnimationProgress:(float)NSAnimationProgress;
- (void)clearTextIndicator:(WebCore::TextIndicatorDismissalAnimation)animation;
-#if HAVE(UIFINDINTERACTION)
-- (void)performTextSearchWithQueryString:(NSString *)string usingOptions:(_UITextSearchOptions *)options resultAggregator:(id<_UITextSearchAggregator>)aggregator;
-- (void)decorateFoundTextRange:(UITextRange *)range usingStyle:(_UIFoundTextStyle)style;
-- (void)clearAllDecoratedFoundText;
-#endif
-
@property (nonatomic, readonly) BOOL _shouldUseContextMenus;
@property (nonatomic, readonly) BOOL _shouldUseContextMenusForFormControls;
@property (nonatomic, readonly) BOOL _shouldAvoidResizingWhenInputViewBoundsChange;
Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (286822 => 286823)
--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm 2021-12-10 02:07:11 UTC (rev 286822)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm 2021-12-10 02:16:28 UTC (rev 286823)
@@ -9987,7 +9987,7 @@
});
}
-- (void)decorateFoundTextRange:(UITextRange *)range usingStyle:(_UIFoundTextStyle)style
+- (void)decorateFoundTextRange:(UITextRange *)range inDocument:(_UITextSearchDocumentIdentifier)document usingStyle:(_UIFoundTextStyle)style
{
if (![range isKindOfClass:[WKFoundTextRange class]])
return;
@@ -10006,6 +10006,11 @@
_page->hideFindUI();
}
+- (NSInteger)offsetFromPosition:(UITextPosition *)from toPosition:(UITextPosition *)toPosition inDocument:(_UITextSearchDocumentIdentifier)document
+{
+ return [self offsetFromPosition:from toPosition:toPosition];
+}
+
#endif // HAVE(UIFINDINTERACTION)
#if ENABLE(IMAGE_ANALYSIS)
Modified: trunk/Tools/ChangeLog (286822 => 286823)
--- trunk/Tools/ChangeLog 2021-12-10 02:07:11 UTC (rev 286822)
+++ trunk/Tools/ChangeLog 2021-12-10 02:16:28 UTC (rev 286823)
@@ -1,3 +1,16 @@
+2021-12-09 Aditya Keerthi <akeer...@apple.com>
+
+ [iOS] Add SPI to enable find interactions on WKWebView
+ https://bugs.webkit.org/show_bug.cgi?id=234017
+ rdar://86140542
+
+ Reviewed by Wenson Hsieh.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/FindInPage.mm:
+ (TEST):
+
+ Test that the new SPI installs a _UIFindInteraction on the web view.
+
2021-12-09 Lauro Moura <lmo...@igalia.com>
[webkitpy] Make check-webkit-style check WebDriverTests/TestExpectations.json
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/FindInPage.mm (286822 => 286823)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/FindInPage.mm 2021-12-10 02:07:11 UTC (rev 286822)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/FindInPage.mm 2021-12-10 02:16:28 UTC (rev 286823)
@@ -452,4 +452,17 @@
testPerformTextSearchWithQueryStringInWebView(webView.get(), @"Birth", searchOptions.get(), 0UL);
}
+TEST(WebKit, FindInteraction)
+{
+ RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)]);
+
+ EXPECT_NULL([webView _findInteraction]);
+
+ [webView _setFindInteractionEnabled:YES];
+ EXPECT_NOT_NULL([webView _findInteraction]);
+
+ [webView _setFindInteractionEnabled:NO];
+ EXPECT_NULL([webView _findInteraction]);
+}
+
#endif // HAVE(UIFINDINTERACTION)