[iOS] WKPDFView should show the Data Detectors sheet when long-pressing a URL that...
authoraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Jul 2018 20:13:22 +0000 (20:13 +0000)
committeraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Jul 2018 20:13:22 +0000 (20:13 +0000)
https://bugs.webkit.org/show_bug.cgi?id=187396
<rdar://problem/41786980>

Reviewed by Dan Bernstein.

If a URL can be presented by Data Detectors, show the Data Detectors sheet instead
of the link sheet. Also implement the optional WKActionSheetAssistantDelegate
method that asks the UI delegate for its data detection context.

* UIProcess/ios/WKPDFView.mm:
(-[WKPDFView _showActionSheetForURL:atLocation:withAnnotationRect:]):
(-[WKPDFView dataDetectionContextForActionSheetAssistant:]):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@233589 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/ios/WKPDFView.mm

index a30ac7b..f120e64 100644 (file)
@@ -1,3 +1,19 @@
+2018-07-06  Andy Estes  <aestes@apple.com>
+
+        [iOS] WKPDFView should show the Data Detectors sheet when long-pressing a URL that Data Detectors can handle
+        https://bugs.webkit.org/show_bug.cgi?id=187396
+        <rdar://problem/41786980>
+
+        Reviewed by Dan Bernstein.
+
+        If a URL can be presented by Data Detectors, show the Data Detectors sheet instead
+        of the link sheet. Also implement the optional WKActionSheetAssistantDelegate
+        method that asks the UI delegate for its data detection context.
+
+        * UIProcess/ios/WKPDFView.mm:
+        (-[WKPDFView _showActionSheetForURL:atLocation:withAnnotationRect:]):
+        (-[WKPDFView dataDetectionContextForActionSheetAssistant:]):
+
 2018-07-06  Chris Dumez  <cdumez@apple.com>
 
         WebResourceLoadStatisticsStore::callHasStorageAccessForFrameHandler() should take in a CompletionHandler
index 0a7b4fc..f19741c 100644 (file)
 #import "FindClient.h"
 #import "PDFKitSPI.h"
 #import "WKActionSheetAssistant.h"
+#import "WKUIDelegatePrivate.h"
 #import "WKWebViewInternal.h"
 #import "WebPageProxy.h"
 #import "_WKWebViewPrintFormatterInternal.h"
 #import <MobileCoreServices/MobileCoreServices.h>
+#import <WebCore/DataDetection.h>
 #import <WebCore/WebCoreNSURLExtras.h>
 #import <wtf/BlockPtr.h>
 #import <wtf/MainThread.h>
@@ -439,7 +441,12 @@ static NSStringCompareOptions stringCompareOptions(_WKFindOptions findOptions)
     positionInformation.url = url;
 
     _positionInformation = WTFMove(positionInformation);
-    [_actionSheetAssistant showLinkSheet];
+#if ENABLE(DATA_DETECTION)
+    if (WebCore::DataDetection::canBePresentedByDataDetectors(_positionInformation.url))
+        [_actionSheetAssistant showDataDetectorsSheet];
+    else
+#endif
+        [_actionSheetAssistant showLinkSheet];
 }
 
 - (void)pdfHostViewController:(PDFHostViewController *)controller didLongPressURL:(NSURL *)url atLocation:(CGPoint)location withAnnotationRect:(CGRect)annotationRect
@@ -513,6 +520,19 @@ static NSStringCompareOptions stringCompareOptions(_WKFindOptions findOptions)
     return page->uiClient().actionsForElement(element, WTFMove(defaultActions));
 }
 
+- (NSDictionary *)dataDetectionContextForActionSheetAssistant:(WKActionSheetAssistant *)assistant
+{
+    auto webView = _webView.getAutoreleased();
+    if (!webView)
+        return nil;
+
+    id <WKUIDelegatePrivate> uiDelegate = static_cast<id <WKUIDelegatePrivate>>(webView.UIDelegate);
+    if (![uiDelegate respondsToSelector:@selector(_dataDetectionContextForWebView:)])
+        return nil;
+
+    return [uiDelegate _dataDetectionContextForWebView:webView];
+}
+
 @end