Diff
Modified: trunk/Source/WebKit/ChangeLog (288761 => 288762)
--- trunk/Source/WebKit/ChangeLog 2022-01-28 23:06:19 UTC (rev 288761)
+++ trunk/Source/WebKit/ChangeLog 2022-01-28 23:12:40 UTC (rev 288762)
@@ -1,5 +1,55 @@
2022-01-28 Aditya Keerthi <[email protected]>
+ Migrate _UITextSearching implementation to be backed by WebFoundTextRangeController
+ https://bugs.webkit.org/show_bug.cgi?id=235693
+ rdar://88117303
+
+ Reviewed by Tim Horton.
+
+ Migrate _UITextSearching implementation to be backed by
+ WebFoundTextRangeController to support restoreable find results.
+
+ * UIProcess/API/ios/WKWebViewIOS.mm:
+ (-[WKWebView scrollRangeToVisible:inDocument:]):
+ (-[WKWebView didBeginTextSearchOperation]):
+ (-[WKWebView didEndTextSearchOperation]):
+ * UIProcess/WebPageProxy.cpp:
+ (WebKit::WebPageProxy::findTextRangesForStringMatches):
+ (WebKit::WebPageProxy::decorateTextRangeWithStyle):
+ (WebKit::WebPageProxy::scrollTextRangeToVisible):
+ (WebKit::WebPageProxy::clearAllDecoratedFoundText):
+ (WebKit::WebPageProxy::didBeginTextSearchOperation):
+ (WebKit::WebPageProxy::didEndTextSearchOperation):
+ * UIProcess/WebPageProxy.h:
+ * UIProcess/ios/WKContentViewInteraction.h:
+ * UIProcess/ios/WKContentViewInteraction.mm:
+ (-[WKContentView offsetFromPosition:toPosition:]):
+ (-[WKContentView performTextSearchWithQueryString:usingOptions:resultAggregator:]):
+ (-[WKContentView decorateFoundTextRange:inDocument:usingStyle:]):
+ (-[WKContentView scrollRangeToVisible:inDocument:]):
+ (-[WKContentView clearAllDecoratedFoundText]):
+ (-[WKContentView didBeginTextSearchOperation]):
+ (-[WKContentView didEndTextSearchOperation]):
+ (+[WKFoundTextRange foundTextRangeWithWebFoundTextRange:]):
+ (-[WKFoundTextRange start]):
+ (-[WKFoundTextRange end]):
+ (-[WKFoundTextRange webFoundTextRange]):
+ (+[WKFoundTextPosition textPositionWithOffset:order:]):
+ (+[WKFoundTextRange foundTextRangeWithRect:index:]): Deleted.
+ (+[WKFoundTextPosition textPositionWithIndex:]): Deleted.
+ * WebProcess/WebPage/WebPage.cpp:
+ (WebKit::WebPage::findTextRangesForStringMatches):
+ (WebKit::WebPage::decorateTextRangeWithStyle):
+ (WebKit::WebPage::scrollTextRangeToVisible):
+ (WebKit::WebPage::clearAllDecoratedFoundText):
+ (WebKit::WebPage::didBeginTextSearchOperation):
+ (WebKit::WebPage::didEndTextSearchOperation):
+ * WebProcess/WebPage/WebPage.h:
+ (WebKit::WebPage::foundTextRangeController):
+ * WebProcess/WebPage/WebPage.messages.in:
+
+2022-01-28 Aditya Keerthi <[email protected]>
+
Add support for decorating and scrolling to ranges in WebFoundTextRangeController
https://bugs.webkit.org/show_bug.cgi?id=235692
rdar://88117232
Modified: trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm (288761 => 288762)
--- trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm 2022-01-28 23:06:19 UTC (rev 288761)
+++ trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm 2022-01-28 23:12:40 UTC (rev 288762)
@@ -3533,11 +3533,26 @@
[_contentView decorateFoundTextRange:range inDocument:document usingStyle:style];
}
+- (void)scrollRangeToVisible:(UITextRange *)range inDocument:(_UITextSearchDocumentIdentifier)document
+{
+ [_contentView scrollRangeToVisible:range inDocument:document];
+}
+
- (void)clearAllDecoratedFoundText
{
[_contentView clearAllDecoratedFoundText];
}
+- (void)didBeginTextSearchOperation
+{
+ [_contentView didBeginTextSearchOperation];
+}
+
+- (void)didEndTextSearchOperation
+{
+ [_contentView didEndTextSearchOperation];
+}
+
#endif // HAVE(UIFINDINTERACTION)
@end // WKWebView (WKPrivateIOS)
Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (288761 => 288762)
--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp 2022-01-28 23:06:19 UTC (rev 288761)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp 2022-01-28 23:12:40 UTC (rev 288762)
@@ -108,6 +108,7 @@
#include "WebCoreArgumentCoders.h"
#include "WebEditCommandProxy.h"
#include "WebEventConversion.h"
+#include "WebFoundTextRange.h"
#include "WebFrame.h"
#include "WebFramePolicyListenerProxy.h"
#include "WebFullScreenManagerProxy.h"
@@ -4285,6 +4286,36 @@
sendWithAsyncReply(Messages::WebPage::FindRectsForStringMatches(string, options, maxMatchCount), WTFMove(callbackFunction));
}
+void WebPageProxy::findTextRangesForStringMatches(const String& string, OptionSet<FindOptions> options, unsigned maxMatchCount, CompletionHandler<void(Vector<WebFoundTextRange>&&)>&& callbackFunction)
+{
+ sendWithAsyncReply(Messages::WebPage::FindTextRangesForStringMatches(string, options, maxMatchCount), WTFMove(callbackFunction));
+}
+
+void WebPageProxy::decorateTextRangeWithStyle(const WebFoundTextRange& range, FindDecorationStyle style)
+{
+ send(Messages::WebPage::DecorateTextRangeWithStyle(range, style));
+}
+
+void WebPageProxy::scrollTextRangeToVisible(const WebFoundTextRange& range)
+{
+ send(Messages::WebPage::ScrollTextRangeToVisible(range));
+}
+
+void WebPageProxy::clearAllDecoratedFoundText()
+{
+ send(Messages::WebPage::ClearAllDecoratedFoundText());
+}
+
+void WebPageProxy::didBeginTextSearchOperation()
+{
+ send(Messages::WebPage::DidBeginTextSearchOperation());
+}
+
+void WebPageProxy::didEndTextSearchOperation()
+{
+ send(Messages::WebPage::DidEndTextSearchOperation());
+}
+
void WebPageProxy::getImageForFindMatch(int32_t matchIndex)
{
send(Messages::WebPage::GetImageForFindMatch(matchIndex));
Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (288761 => 288762)
--- trunk/Source/WebKit/UIProcess/WebPageProxy.h 2022-01-28 23:06:19 UTC (rev 288761)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h 2022-01-28 23:12:40 UTC (rev 288762)
@@ -410,6 +410,7 @@
struct UserMessage;
struct WebAutocorrectionData;
struct WebBackForwardListCounts;
+struct WebFoundTextRange;
struct WebHitTestResultData;
struct WebNavigationDataStore;
struct WebPopupItem;
@@ -1213,6 +1214,13 @@
void didFailToFindString(const String&);
void didFindStringMatches(const String&, const Vector<Vector<WebCore::IntRect>>& matchRects, int32_t firstIndexAfterSelection);
+ void findTextRangesForStringMatches(const String&, OptionSet<FindOptions>, unsigned maxMatchCount, CompletionHandler<void(Vector<WebFoundTextRange>&&)>&&);
+ void decorateTextRangeWithStyle(const WebFoundTextRange&, FindDecorationStyle);
+ void scrollTextRangeToVisible(const WebFoundTextRange&);
+ void clearAllDecoratedFoundText();
+ void didBeginTextSearchOperation();
+ void didEndTextSearchOperation();
+
void getContentsAsString(ContentAsStringIncludesChildFrames, CompletionHandler<void(const String&)>&&);
#if PLATFORM(COCOA)
void getContentsAsAttributedString(CompletionHandler<void(const WebCore::AttributedString&)>&&);
Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h (288761 => 288762)
--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h 2022-01-28 23:06:19 UTC (rev 288761)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h 2022-01-28 23:12:40 UTC (rev 288762)
@@ -417,10 +417,6 @@
WeakObjCPtr<WKDataListSuggestionsControl> _dataListSuggestionsControl;
#endif
-#if HAVE(UIFINDINTERACTION)
- RetainPtr<UITextRange> _foundHighlightedTextRange;
-#endif
-
BOOL _isEditable;
BOOL _showingTextStyleOptions;
BOOL _hasValidPositionInformation;
Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (288761 => 288762)
--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm 2022-01-28 23:06:19 UTC (rev 288761)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm 2022-01-28 23:12:40 UTC (rev 288762)
@@ -83,6 +83,7 @@
#import "WebAutocorrectionData.h"
#import "WebDataListSuggestionsDropdownIOS.h"
#import "WebEvent.h"
+#import "WebFoundTextRange.h"
#import "WebIOSEventFactory.h"
#import "WebPageMessages.h"
#import "WebPageProxyMessages.h"
@@ -401,18 +402,23 @@
@interface WKFoundTextRange : UITextRange
-@property (nonatomic) CGRect rect;
-@property (nonatomic) NSUInteger index;
+@property (nonatomic) NSUInteger location;
+@property (nonatomic) NSUInteger length;
+@property (nonatomic, copy) NSString *frameIdentifier;
+@property (nonatomic) NSUInteger order;
-+ (WKFoundTextRange *)foundTextRangeWithRect:(CGRect)rect index:(NSUInteger)index;
++ (WKFoundTextRange *)foundTextRangeWithWebFoundTextRange:(WebKit::WebFoundTextRange)range;
+- (WebKit::WebFoundTextRange)webFoundTextRange;
+
@end
@interface WKFoundTextPosition : UITextPosition
-@property (nonatomic) NSUInteger index;
+@property (nonatomic) NSUInteger offset;
+@property (nonatomic) NSUInteger order;
-+ (WKFoundTextPosition *)textPositionWithIndex:(NSUInteger)index;
++ (WKFoundTextPosition *)textPositionWithOffset:(NSUInteger)offset order:(NSUInteger)order;
@end
@@ -5265,11 +5271,18 @@
return NSOrderedSame;
}
-- (NSInteger)offsetFromPosition:(UITextPosition *)from toPosition:(UITextPosition *)toPosition
+- (NSInteger)offsetFromPosition:(UITextPosition *)from toPosition:(UITextPosition *)to
{
#if HAVE(UIFINDINTERACTION)
- if ([from isKindOfClass:[WKFoundTextPosition class]] && [toPosition isKindOfClass:[WKFoundTextPosition class]])
- return ((WKFoundTextPosition *)from).index - ((WKFoundTextPosition *)toPosition).index;
+ if ([from isKindOfClass:[WKFoundTextPosition class]] && [to isKindOfClass:[WKFoundTextPosition class]]) {
+ WKFoundTextPosition *fromPosition = (WKFoundTextPosition *)from;
+ WKFoundTextPosition *toPosition = (WKFoundTextPosition *)to;
+
+ if (fromPosition.order == toPosition.order)
+ return fromPosition.offset - toPosition.offset;
+
+ return fromPosition.order - toPosition.order;
+ }
#endif
return 0;
@@ -9993,8 +10006,6 @@
- (void)performTextSearchWithQueryString:(NSString *)string usingOptions:(_UITextSearchOptions *)options resultAggregator:(id<_UITextSearchAggregator>)aggregator
{
OptionSet<WebKit::FindOptions> findOptions;
- findOptions.add(WebKit::FindOptions::ShowOverlay);
-
switch (options.wordMatchMethod) {
case _UITextSearchMatchMethodStartsWith:
findOptions.add(WebKit::FindOptions::AtWordStarts);
@@ -10009,12 +10020,12 @@
if (options.stringCompareOptions & NSCaseInsensitiveSearch)
findOptions.add(WebKit::FindOptions::CaseInsensitive);
- _page->findRectsForStringMatches(string, findOptions, 1000, [string, aggregator = retainPtr(aggregator)](const Vector<WebCore::FloatRect>& rects) {
- NSUInteger index = 0;
- for (auto& rect : rects) {
- WKFoundTextRange *range = [WKFoundTextRange foundTextRangeWithRect:rect index:index];
- [aggregator foundRange:range forSearchString:string inDocument:nil];
- index++;
+ // The limit matches the limit set on existing WKWebView find API.
+ constexpr auto maxMatches = 1000;
+ _page->findTextRangesForStringMatches(string, findOptions, maxMatches, [string, aggregator = retainPtr(aggregator)](const Vector<WebKit::WebFoundTextRange> ranges) {
+ for (auto& range : ranges) {
+ WKFoundTextRange *textRange = [WKFoundTextRange foundTextRangeWithWebFoundTextRange:range];
+ [aggregator foundRange:textRange forSearchString:string inDocument:nil];
}
[aggregator finishedSearching];
@@ -10023,23 +10034,40 @@
- (void)decorateFoundTextRange:(UITextRange *)range inDocument:(_UITextSearchDocumentIdentifier)document usingStyle:(_UIFoundTextStyle)style
{
- if (![range isKindOfClass:[WKFoundTextRange class]])
+ auto foundTextRange = dynamic_objc_cast<WKFoundTextRange>(range);
+ if (!foundTextRange)
return;
- if (style == _UIFoundTextStyleHighlighted) {
- _foundHighlightedTextRange = range;
- WKFoundTextRange *foundRange = (WKFoundTextRange *)range;
- _page->indicateFindMatch(foundRange.index);
- } else if (style == _UIFoundTextStyleFound && _foundHighlightedTextRange == range)
- _page->hideFindIndicator();
+ auto decorationStyle = WebKit::FindDecorationStyle::Normal;
+ if (style == _UIFoundTextStyleFound)
+ decorationStyle = WebKit::FindDecorationStyle::Found;
+ else if (style == _UIFoundTextStyleHighlighted)
+ decorationStyle = WebKit::FindDecorationStyle::Highlighted;
+
+ _page->decorateTextRangeWithStyle([foundTextRange webFoundTextRange], decorationStyle);
}
+- (void)scrollRangeToVisible:(UITextRange *)range inDocument:(_UITextSearchDocumentIdentifier)document
+{
+ if (auto foundTextRange = dynamic_objc_cast<WKFoundTextRange>(range))
+ _page->scrollTextRangeToVisible([foundTextRange webFoundTextRange]);
+}
+
- (void)clearAllDecoratedFoundText
{
- _foundHighlightedTextRange = nil;
- _page->hideFindUI();
+ _page->clearAllDecoratedFoundText();
}
+- (void)didBeginTextSearchOperation
+{
+ _page->didBeginTextSearchOperation();
+}
+
+- (void)didEndTextSearchOperation
+{
+ _page->didEndTextSearchOperation();
+}
+
- (NSInteger)offsetFromPosition:(UITextPosition *)from toPosition:(UITextPosition *)toPosition inDocument:(_UITextSearchDocumentIdentifier)document
{
return [self offsetFromPosition:from toPosition:toPosition];
@@ -11914,23 +11942,27 @@
@implementation WKFoundTextRange
-+ (WKFoundTextRange *)foundTextRangeWithRect:(CGRect)rect index:(NSUInteger)index
+
++ (WKFoundTextRange *)foundTextRangeWithWebFoundTextRange:(WebKit::WebFoundTextRange)webRange
{
auto range = adoptNS([[WKFoundTextRange alloc] init]);
- [range setRect:rect];
- [range setIndex:index];
+ [range setLocation:webRange.location];
+ [range setLength:webRange.length];
+ [range setFrameIdentifier:webRange.frameIdentifier];
+ [range setOrder:webRange.order];
return range.autorelease();
}
- (WKFoundTextPosition *)start
{
- WKFoundTextPosition *position = [WKFoundTextPosition textPositionWithIndex:self.index];
+ WKFoundTextPosition *position = [WKFoundTextPosition textPositionWithOffset:self.location order:self.order];
return position;
}
- (UITextPosition *)end
{
- return self.start;
+ WKFoundTextPosition *position = [WKFoundTextPosition textPositionWithOffset:(self.location + self.length) order:self.order];
+ return position;
}
- (BOOL)isEmpty
@@ -11938,14 +11970,20 @@
return NO;
}
+- (WebKit::WebFoundTextRange)webFoundTextRange
+{
+ return { self.location, self.length, self.frameIdentifier, self.order };
+}
+
@end
@implementation WKFoundTextPosition
-+ (WKFoundTextPosition *)textPositionWithIndex:(NSUInteger)index
++ (WKFoundTextPosition *)textPositionWithOffset:(NSUInteger)offset order:(NSUInteger)order
{
auto pos = adoptNS([[WKFoundTextPosition alloc] init]);
- [pos setIndex:index];
+ [pos setOffset:offset];
+ [pos setOrder:order];
return pos.autorelease();
}
Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (288761 => 288762)
--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp 2022-01-28 23:06:19 UTC (rev 288761)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp 2022-01-28 23:12:40 UTC (rev 288762)
@@ -91,6 +91,8 @@
#include "WebEditorClient.h"
#include "WebEventConversion.h"
#include "WebEventFactory.h"
+#include "WebFoundTextRange.h"
+#include "WebFoundTextRangeController.h"
#include "WebFrame.h"
#include "WebFrameLoaderClient.h"
#include "WebFullScreenManager.h"
@@ -509,6 +511,7 @@
, m_resourceLoadClient(makeUnique<API::InjectedBundle::ResourceLoadClient>())
, m_uiClient(makeUnique<API::InjectedBundle::PageUIClient>())
, m_findController(makeUniqueRef<FindController>(this))
+ , m_foundTextRangeController(makeUniqueRef<WebFoundTextRangeController>(*this))
, m_inspectorTargetController(makeUnique<WebPageInspectorTargetController>(*this))
, m_userContentController(WebUserContentController::getOrCreate(parameters.userContentControllerParameters.identifier))
#if ENABLE(GEOLOCATION)
@@ -4706,6 +4709,36 @@
findController().hideFindIndicator();
}
+void WebPage::findTextRangesForStringMatches(const String& string, OptionSet<FindOptions> options, uint32_t maxMatchCount, CompletionHandler<void(Vector<WebFoundTextRange>&&)>&& completionHandler)
+{
+ foundTextRangeController().findTextRangesForStringMatches(string, options, maxMatchCount, WTFMove(completionHandler));
+}
+
+void WebPage::decorateTextRangeWithStyle(const WebFoundTextRange& range, WebKit::FindDecorationStyle style)
+{
+ foundTextRangeController().decorateTextRangeWithStyle(range, style);
+}
+
+void WebPage::scrollTextRangeToVisible(const WebFoundTextRange& range)
+{
+ foundTextRangeController().scrollTextRangeToVisible(range);
+}
+
+void WebPage::clearAllDecoratedFoundText()
+{
+ foundTextRangeController().clearAllDecoratedFoundText();
+}
+
+void WebPage::didBeginTextSearchOperation()
+{
+ foundTextRangeController().didBeginTextSearchOperation();
+}
+
+void WebPage::didEndTextSearchOperation()
+{
+ foundTextRangeController().didEndTextSearchOperation();
+}
+
void WebPage::getImageForFindMatch(uint32_t matchIndex)
{
findController().getImageForFindMatch(matchIndex);
Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (288761 => 288762)
--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h 2022-01-28 23:06:19 UTC (rev 288761)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h 2022-01-28 23:12:40 UTC (rev 288762)
@@ -296,6 +296,7 @@
class WebDateTimeChooser;
class WebDocumentLoader;
class WebEvent;
+class WebFoundTextRangeController;
class PlaybackSessionManager;
class VideoFullscreenManager;
class WebFrame;
@@ -323,6 +324,7 @@
class RemoteLayerTreeTransaction;
enum class FindOptions : uint16_t;
+enum class FindDecorationStyle : uint8_t;
enum class DragControllerAction : uint8_t;
enum class TextRecognitionUpdateResult : uint8_t;
enum class SyntheticEditingCommandType : uint8_t;
@@ -343,6 +345,7 @@
struct UserMessage;
struct WebAutocorrectionData;
struct WebAutocorrectionContext;
+struct WebFoundTextRange;
struct WebPageCreationParameters;
struct WebPreferencesStore;
struct WebsitePoliciesData;
@@ -705,6 +708,7 @@
static const WebEvent* currentEvent();
FindController& findController() { return m_findController.get(); }
+ WebFoundTextRangeController& foundTextRangeController() { return m_foundTextRangeController.get(); }
#if ENABLE(GEOLOCATION)
GeolocationPermissionRequestManager& geolocationPermissionRequestManager() { return m_geolocationPermissionRequestManager.get(); }
@@ -1755,6 +1759,13 @@
void findRectsForStringMatches(const String&, OptionSet<FindOptions>, uint32_t maxMatchCount, CompletionHandler<void(Vector<WebCore::FloatRect>&&)>&&);
void hideFindIndicator();
+ void findTextRangesForStringMatches(const String&, OptionSet<FindOptions>, uint32_t maxMatchCount, CompletionHandler<void(Vector<WebFoundTextRange>&&)>&&);
+ void decorateTextRangeWithStyle(const WebFoundTextRange&, WebKit::FindDecorationStyle);
+ void scrollTextRangeToVisible(const WebFoundTextRange&);
+ void clearAllDecoratedFoundText();
+ void didBeginTextSearchOperation();
+ void didEndTextSearchOperation();
+
#if USE(COORDINATED_GRAPHICS)
void sendViewportAttributesChanged(const WebCore::ViewportArguments&);
#endif
@@ -2060,6 +2071,8 @@
UniqueRef<FindController> m_findController;
+ UniqueRef<WebFoundTextRangeController> m_foundTextRangeController;
+
RefPtr<WebInspector> m_inspector;
RefPtr<WebInspectorUI> m_inspectorUI;
RefPtr<RemoteWebInspectorUI> m_remoteInspectorUI;
Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in (288761 => 288762)
--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in 2022-01-28 23:06:19 UTC (rev 288761)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in 2022-01-28 23:12:40 UTC (rev 288762)
@@ -311,6 +311,13 @@
FindRectsForStringMatches(String string, OptionSet<WebKit::FindOptions> findOptions, unsigned maxMatchCount) -> (Vector<WebCore::FloatRect> matches) Async
HideFindIndicator()
+
+ FindTextRangesForStringMatches(String string, OptionSet<WebKit::FindOptions> findOptions, unsigned maxMatchCount) -> (Vector<WebKit::WebFoundTextRange> ranges) Async
+ DecorateTextRangeWithStyle(struct WebKit::WebFoundTextRange range, enum:uint8_t WebKit::FindDecorationStyle style)
+ ScrollTextRangeToVisible(struct WebKit::WebFoundTextRange range)
+ ClearAllDecoratedFoundText();
+ DidBeginTextSearchOperation();
+ DidEndTextSearchOperation();
AddMIMETypeWithCustomContentProvider(String mimeType)