<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[175595] trunk/Source/WebKit2</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/175595">175595</a></dd>
<dt>Author</dt> <dd>aestes@apple.com</dd>
<dt>Date</dt> <dd>2014-11-04 17:24:20 -0800 (Tue, 04 Nov 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>[iOS] Add long press support for links in WKPDFView
https://bugs.webkit.org/show_bug.cgi?id=138357
Reviewed by Dan Bernstein.
Use WKActionSheetAssistant to show a link action sheet in response to long-pressing on a link. Have WKPDFView
conform to WKActionSheetAssistantDelegate in order to respond to the open and copy actions as well as to
provide the link's URL and position information to WKActionSheetAssistant. The long-pressed link is highlighted
for .75 seconds before the sheet is displayed in order to match UIWebPDFView.
* UIProcess/ios/WKActionSheetAssistant.h: Made protocol methods that WKPDFView doesn't implement optional.
* UIProcess/ios/WKActionSheetAssistant.mm:
(-[WKActionSheetAssistant updatePositionInformation]): Checked if delegate responds to
updatePositionInformationForActionSheetAssistant: before calling.
(-[WKActionSheetAssistant _createSheetWithElementActions:showLinkTitle:]): Checked if delegate responds to
actionSheetAssistant:willStartInteractionWithElement: before calling.
(-[WKActionSheetAssistant cleanupSheet]): Checked if delegate responds to actionSheetAssistantDidStopInteraction:
before calling.
* UIProcess/ios/WKPDFView.h: Conformed to WKActionSheetAssistantDelegate.
* UIProcess/ios/WKPDFView.mm:
(-[WKPDFView web_initWithFrame:webView:]): Instantiated a WKActionSheetAssistant and set self as its delegate.
(-[WKPDFView _highlightLinkAnnotation:forDuration:completionHandler:]): Moved highlight drawing to here from
annotation:wasTouchedAtPoint:controller: in order to be reused for long-press.
(-[WKPDFView _URLForLinkAnnotation:]): Moved URL creation to here from annotation:wasTouchedAtPoint:controller:
in order to be reused for long-press. Generated an absolute URL since this URL might go into the pasteboard.
(-[WKPDFView annotation:wasTouchedAtPoint:controller:]): Changed to call
_highlightLinkAnnotation:forDuration:completionHandler: and _URLForLinkAnnotation:.
(-[WKPDFView annotation:isBeingPressedAtPoint:controller:]): Set values on _positionInformation and called
-[WKActionSheetAssistant showLinkSheet] after showing a highlight for .75 seconds.
(-[WKPDFView positionInformation]): Returned _positionInformation.
(-[WKPDFView performAction:]): Added a UTF-8 text and URL representation of the pressed URL to the pasteboard.
(-[WKPDFView openElementAtLocation:]): Called WebPage::navigateToURLWithSimulatedClick().
(-[WKPDFView actionsForElement:defaultActions:]): Returned actions from UIClient::actionsForElement().
(-[WKPDFView _createHighlightViewWithFrame:]): Deleted.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosWKActionSheetAssistanth">trunk/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosWKActionSheetAssistantmm">trunk/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosWKPDFViewh">trunk/Source/WebKit2/UIProcess/ios/WKPDFView.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosWKPDFViewmm">trunk/Source/WebKit2/UIProcess/ios/WKPDFView.mm</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (175594 => 175595)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-11-05 01:21:31 UTC (rev 175594)
+++ trunk/Source/WebKit2/ChangeLog        2014-11-05 01:24:20 UTC (rev 175595)
</span><span class="lines">@@ -1,3 +1,40 @@
</span><ins>+2014-11-04 Andy Estes <aestes@apple.com>
+
+ [iOS] Add long press support for links in WKPDFView
+ https://bugs.webkit.org/show_bug.cgi?id=138357
+
+ Reviewed by Dan Bernstein.
+
+ Use WKActionSheetAssistant to show a link action sheet in response to long-pressing on a link. Have WKPDFView
+ conform to WKActionSheetAssistantDelegate in order to respond to the open and copy actions as well as to
+ provide the link's URL and position information to WKActionSheetAssistant. The long-pressed link is highlighted
+ for .75 seconds before the sheet is displayed in order to match UIWebPDFView.
+
+ * UIProcess/ios/WKActionSheetAssistant.h: Made protocol methods that WKPDFView doesn't implement optional.
+ * UIProcess/ios/WKActionSheetAssistant.mm:
+ (-[WKActionSheetAssistant updatePositionInformation]): Checked if delegate responds to
+ updatePositionInformationForActionSheetAssistant: before calling.
+ (-[WKActionSheetAssistant _createSheetWithElementActions:showLinkTitle:]): Checked if delegate responds to
+ actionSheetAssistant:willStartInteractionWithElement: before calling.
+ (-[WKActionSheetAssistant cleanupSheet]): Checked if delegate responds to actionSheetAssistantDidStopInteraction:
+ before calling.
+ * UIProcess/ios/WKPDFView.h: Conformed to WKActionSheetAssistantDelegate.
+ * UIProcess/ios/WKPDFView.mm:
+ (-[WKPDFView web_initWithFrame:webView:]): Instantiated a WKActionSheetAssistant and set self as its delegate.
+ (-[WKPDFView _highlightLinkAnnotation:forDuration:completionHandler:]): Moved highlight drawing to here from
+ annotation:wasTouchedAtPoint:controller: in order to be reused for long-press.
+ (-[WKPDFView _URLForLinkAnnotation:]): Moved URL creation to here from annotation:wasTouchedAtPoint:controller:
+ in order to be reused for long-press. Generated an absolute URL since this URL might go into the pasteboard.
+ (-[WKPDFView annotation:wasTouchedAtPoint:controller:]): Changed to call
+ _highlightLinkAnnotation:forDuration:completionHandler: and _URLForLinkAnnotation:.
+ (-[WKPDFView annotation:isBeingPressedAtPoint:controller:]): Set values on _positionInformation and called
+ -[WKActionSheetAssistant showLinkSheet] after showing a highlight for .75 seconds.
+ (-[WKPDFView positionInformation]): Returned _positionInformation.
+ (-[WKPDFView performAction:]): Added a UTF-8 text and URL representation of the pressed URL to the pasteboard.
+ (-[WKPDFView openElementAtLocation:]): Called WebPage::navigateToURLWithSimulatedClick().
+ (-[WKPDFView actionsForElement:defaultActions:]): Returned actions from UIClient::actionsForElement().
+ (-[WKPDFView _createHighlightViewWithFrame:]): Deleted.
+
</ins><span class="cx"> 2014-11-04 Anders Carlsson <andersca@apple.com>
</span><span class="cx">
</span><span class="cx"> Try to fix the 32-bit build.
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosWKActionSheetAssistanth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.h (175594 => 175595)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.h        2014-11-05 01:21:31 UTC (rev 175594)
+++ trunk/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.h        2014-11-05 01:24:20 UTC (rev 175595)
</span><span class="lines">@@ -40,15 +40,18 @@
</span><span class="cx"> @class _WKActivatedElementInfo;
</span><span class="cx"> @protocol WKActionSheetDelegate;
</span><span class="cx">
</span><del>-@protocol WKActionSheetAssistantDelegate
</del><ins>+@protocol WKActionSheetAssistantDelegate <NSObject>
</ins><span class="cx"> @required
</span><span class="cx"> - (const WebKit::InteractionInformationAtPosition&)positionInformationForActionSheetAssistant:(WKActionSheetAssistant *)assistant;
</span><del>-- (void)updatePositionInformationForActionSheetAssistant:(WKActionSheetAssistant *)assistant;
</del><span class="cx"> - (void)actionSheetAssistant:(WKActionSheetAssistant *)assistant performAction:(WebKit::SheetAction)action;
</span><span class="cx"> - (void)actionSheetAssistant:(WKActionSheetAssistant *)assistant openElementAtLocation:(CGPoint)location;
</span><span class="cx"> - (RetainPtr<NSArray>)actionSheetAssistant:(WKActionSheetAssistant *)assistant decideActionsForElement:(_WKActivatedElementInfo *)element defaultActions:(RetainPtr<NSArray>)defaultActions;
</span><ins>+
+@optional
+- (void)updatePositionInformationForActionSheetAssistant:(WKActionSheetAssistant *)assistant;
</ins><span class="cx"> - (void)actionSheetAssistant:(WKActionSheetAssistant *)assistant willStartInteractionWithElement:(_WKActivatedElementInfo *)element;
</span><span class="cx"> - (void)actionSheetAssistantDidStopInteraction:(WKActionSheetAssistant *)assistant;
</span><ins>+
</ins><span class="cx"> @end
</span><span class="cx">
</span><span class="cx"> @interface WKActionSheetAssistant : NSObject <WKActionSheetDelegate, DDDetectionControllerInteractionDelegate>
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosWKActionSheetAssistantmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.mm (175594 => 175595)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.mm        2014-11-05 01:21:31 UTC (rev 175594)
+++ trunk/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.mm        2014-11-05 01:24:20 UTC (rev 175595)
</span><span class="lines">@@ -163,7 +163,9 @@
</span><span class="cx">
</span><span class="cx"> - (void)updatePositionInformation
</span><span class="cx"> {
</span><del>- [_delegate.get() updatePositionInformationForActionSheetAssistant:self];
</del><ins>+ auto delegate = _delegate.get();
+ if ([delegate respondsToSelector:@selector(updatePositionInformationForActionSheetAssistant:)])
+ [delegate updatePositionInformationForActionSheetAssistant:self];
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> - (BOOL)presentSheet
</span><span class="lines">@@ -236,7 +238,9 @@
</span><span class="cx"> handler:^(UIAlertAction *action) {
</span><span class="cx"> [self cleanupSheet];
</span><span class="cx"> }]];
</span><del>- [delegate actionSheetAssistant:self willStartInteractionWithElement:_elementInfo.get()];
</del><ins>+
+ if ([delegate respondsToSelector:@selector(actionSheetAssistant:willStartInteractionWithElement:)])
+ [delegate actionSheetAssistant:self willStartInteractionWithElement:_elementInfo.get()];
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> - (void)showImageSheet
</span><span class="lines">@@ -365,7 +369,9 @@
</span><span class="cx">
</span><span class="cx"> - (void)cleanupSheet
</span><span class="cx"> {
</span><del>- [_delegate.get() actionSheetAssistantDidStopInteraction:self];
</del><ins>+ auto delegate = _delegate.get();
+ if ([delegate respondsToSelector:@selector(actionSheetAssistantDidStopInteraction:)])
+ [delegate actionSheetAssistantDidStopInteraction:self];
</ins><span class="cx">
</span><span class="cx"> [_interactionSheet doneWithSheet];
</span><span class="cx"> [_interactionSheet setSheetDelegate:nil];
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosWKPDFViewh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/WKPDFView.h (175594 => 175595)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/WKPDFView.h        2014-11-05 01:21:31 UTC (rev 175594)
+++ trunk/Source/WebKit2/UIProcess/ios/WKPDFView.h        2014-11-05 01:24:20 UTC (rev 175595)
</span><span class="lines">@@ -25,12 +25,13 @@
</span><span class="cx">
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx">
</span><ins>+#import "WKActionSheetAssistant.h"
</ins><span class="cx"> #import "WKWebViewContentProvider.h"
</span><span class="cx"> #import <CorePDF/UIPDFAnnotationController.h>
</span><span class="cx"> #import <CorePDF/UIPDFPageView.h>
</span><span class="cx"> #import <UIKit/UIView.h>
</span><span class="cx">
</span><del>-@interface WKPDFView : UIView <WKWebViewContentProvider, UIPDFPageViewDelegate, UIPDFAnnotationControllerDelegate>
</del><ins>+@interface WKPDFView : UIView <WKWebViewContentProvider, UIPDFPageViewDelegate, UIPDFAnnotationControllerDelegate, WKActionSheetAssistantDelegate>
</ins><span class="cx">
</span><span class="cx"> @property (nonatomic, readonly) NSString *suggestedFilename;
</span><span class="cx"> @property (nonatomic, readonly) CGPDFDocumentRef pdfDocument;
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosWKPDFViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/WKPDFView.mm (175594 => 175595)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/WKPDFView.mm        2014-11-05 01:21:31 UTC (rev 175594)
+++ trunk/Source/WebKit2/UIProcess/ios/WKPDFView.mm        2014-11-05 01:24:20 UTC (rev 175595)
</span><span class="lines">@@ -28,7 +28,9 @@
</span><span class="cx">
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx">
</span><ins>+#import "APIUIClient.h"
</ins><span class="cx"> #import "SessionState.h"
</span><ins>+#import "WKNSURLExtras.h"
</ins><span class="cx"> #import "WKPDFPageNumberIndicator.h"
</span><span class="cx"> #import "WKWebViewInternal.h"
</span><span class="cx"> #import "WebPageProxy.h"
</span><span class="lines">@@ -36,10 +38,10 @@
</span><span class="cx"> #import <CorePDF/UIPDFLinkAnnotation.h>
</span><span class="cx"> #import <CorePDF/UIPDFPage.h>
</span><span class="cx"> #import <CorePDF/UIPDFPageView.h>
</span><ins>+#import <MobileCoreServices/UTCoreTypes.h>
</ins><span class="cx"> #import <UIKit/UIScrollView_Private.h>
</span><span class="cx"> #import <WebCore/FloatRect.h>
</span><span class="cx"> #import <WebCore/_UIHighlightViewSPI.h>
</span><del>-#import <chrono>
</del><span class="cx"> #import <wtf/RetainPtr.h>
</span><span class="cx"> #import <wtf/Vector.h>
</span><span class="cx">
</span><span class="lines">@@ -79,6 +81,9 @@
</span><span class="cx">
</span><span class="cx"> BOOL _isStartingZoom;
</span><span class="cx"> BOOL _isPerformingSameDocumentNavigation;
</span><ins>+
+ RetainPtr<WKActionSheetAssistant> _actionSheetAssistant;
+ WebKit::InteractionInformationAtPosition _positionInformation;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> - (instancetype)web_initWithFrame:(CGRect)frame webView:(WKWebView *)webView
</span><span class="lines">@@ -95,6 +100,9 @@
</span><span class="cx"> [_scrollView setMaximumZoomScale:pdfMaximumZoomScale];
</span><span class="cx"> [_scrollView setBackgroundColor:[UIColor grayColor]];
</span><span class="cx">
</span><ins>+ _actionSheetAssistant = adoptNS([[WKActionSheetAssistant alloc] initWithView:self]);
+ [_actionSheetAssistant setDelegate:self];
+
</ins><span class="cx"> return self;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -319,19 +327,43 @@
</span><span class="cx"> _isStartingZoom = NO;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-- (RetainPtr<_UIHighlightView>)_createHighlightViewWithFrame:(CGRect)frame
</del><ins>+- (void)_highlightLinkAnnotation:(UIPDFLinkAnnotation *)linkAnnotation forDuration:(NSTimeInterval)duration completionHandler:(void (^)())completionHandler
</ins><span class="cx"> {
</span><span class="cx"> static const CGFloat highlightBorderRadius = 3;
</span><span class="cx"> static const CGFloat highlightColorComponent = 26.0 / 255;
</span><span class="cx"> static UIColor *highlightColor = [[UIColor alloc] initWithRed:highlightColorComponent green:highlightColorComponent blue:highlightColorComponent alpha:0.3];
</span><span class="cx">
</span><del>- RetainPtr<_UIHighlightView> highlightView = adoptNS([[_UIHighlightView alloc] initWithFrame:CGRectInset(frame, -highlightBorderRadius, -highlightBorderRadius)]);
</del><ins>+ UIPDFPageView *pageView = linkAnnotation.annotationController.pageView;
+ CGRect highlightViewFrame = [self convertRect:[pageView convertRectFromPDFPageSpace:linkAnnotation.Rect] fromView:pageView];
+ RetainPtr<_UIHighlightView> highlightView = adoptNS([[_UIHighlightView alloc] initWithFrame:CGRectInset(highlightViewFrame, -highlightBorderRadius, -highlightBorderRadius)]);
</ins><span class="cx"> [highlightView setOpaque:NO];
</span><span class="cx"> [highlightView setCornerRadius:highlightBorderRadius];
</span><span class="cx"> [highlightView setColor:highlightColor];
</span><del>- return highlightView;
</del><ins>+
+ ASSERT(isMainThread());
+ [self addSubview:highlightView.get()];
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, duration * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
+ [highlightView removeFromSuperview];
+ completionHandler();
+ });
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+- (NSURL *)_URLForLinkAnnotation:(UIPDFLinkAnnotation *)linkAnnotation
+{
+ NSURL *documentURL = _webView.URL;
+
+ if (NSURL *url = linkAnnotation.url)
+ return [NSURL URLWithString:url.relativeString relativeToURL:documentURL];
+
+ if (NSUInteger pageNumber = linkAnnotation.pageNumber) {
+ String anchorString = ASCIILiteral("#page");
+ anchorString.append(String::number(pageNumber));
+ return [NSURL _web_URLWithWTFString:anchorString relativeToURL:documentURL];
+ }
+
+ return nil;
+}
+
</ins><span class="cx"> #pragma mark UIPDFPageViewDelegate
</span><span class="cx">
</span><span class="cx"> - (void)zoom:(UIPDFPageView *)pageView to:(CGRect)targetRect atPoint:(CGPoint)origin kind:(UIPDFObjectKind)kind
</span><span class="lines">@@ -360,37 +392,73 @@
</span><span class="cx">
</span><span class="cx"> - (void)annotation:(UIPDFAnnotation *)annotation wasTouchedAtPoint:(CGPoint)point controller:(UIPDFAnnotationController *)controller
</span><span class="cx"> {
</span><del>- ASSERT(isMainThread());
-
</del><span class="cx"> if (![annotation isKindOfClass:[UIPDFLinkAnnotation class]])
</span><span class="cx"> return;
</span><span class="cx">
</span><span class="cx"> UIPDFLinkAnnotation *linkAnnotation = (UIPDFLinkAnnotation *)annotation;
</span><del>- String urlString;
- if (NSURL *url = linkAnnotation.url)
- urlString = url.absoluteString;
- else if (NSUInteger pageNumber = linkAnnotation.pageNumber) {
- urlString = ASCIILiteral("#page");
- urlString.append(String::number(pageNumber));
- }
-
- if (urlString.isEmpty())
</del><ins>+ RetainPtr<NSURL> url = [self _URLForLinkAnnotation:linkAnnotation];
+ if (!url)
</ins><span class="cx"> return;
</span><span class="cx">
</span><span class="cx"> CGPoint documentPoint = [controller.pageView convertPoint:point toView:self];
</span><span class="cx"> CGPoint screenPoint = [self.window convertPoint:[self convertPoint:documentPoint toView:nil] toWindow:nil];
</span><del>- static const int64_t dispatchOffset = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::milliseconds(200)).count();
</del><span class="cx"> RetainPtr<WKWebView> retainedWebView = _webView;
</span><span class="cx">
</span><del>- CGRect highlightViewFrame = [self convertRect:[controller.pageView convertRectFromPDFPageSpace:annotation.Rect] fromView:controller.pageView];
- RetainPtr<_UIHighlightView> highlightView = [self _createHighlightViewWithFrame:highlightViewFrame];
- [self addSubview:highlightView.get()];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, dispatchOffset), dispatch_get_main_queue(), ^ {
- retainedWebView->_page->navigateToURLWithSimulatedClick(urlString, roundedIntPoint(documentPoint), roundedIntPoint(screenPoint));
- [highlightView removeFromSuperview];
- });
</del><ins>+ [self _highlightLinkAnnotation:linkAnnotation forDuration:.2 completionHandler:^{
+ retainedWebView->_page->navigateToURLWithSimulatedClick([url absoluteString], roundedIntPoint(documentPoint), roundedIntPoint(screenPoint));
+ }];
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+- (void)annotation:(UIPDFAnnotation *)annotation isBeingPressedAtPoint:(CGPoint)point controller:(UIPDFAnnotationController *)controller
+{
+ if (![annotation isKindOfClass:[UIPDFLinkAnnotation class]])
+ return;
+
+ UIPDFLinkAnnotation *linkAnnotation = (UIPDFLinkAnnotation *)annotation;
+ NSURL *url = [self _URLForLinkAnnotation:linkAnnotation];
+ if (!url)
+ return;
+
+ _positionInformation.url = url.absoluteString;
+ _positionInformation.point = roundedIntPoint([controller.pageView convertPoint:point toView:self]);
+ _positionInformation.bounds = roundedIntRect([self convertRect:[controller.pageView convertRectFromPDFPageSpace:annotation.Rect] fromView:controller.pageView]);
+
+ [self _highlightLinkAnnotation:linkAnnotation forDuration:.75 completionHandler:^{
+ [_actionSheetAssistant showLinkSheet];
+ }];
+}
+
+#pragma mark WKActionSheetAssistantDelegate
+
+- (const WebKit::InteractionInformationAtPosition&)positionInformationForActionSheetAssistant:(WKActionSheetAssistant *)assistant
+{
+ return _positionInformation;
+}
+
+- (void)actionSheetAssistant:(WKActionSheetAssistant *)assistant performAction:(WebKit::SheetAction)action
+{
+ if (action != WebKit::SheetAction::Copy)
+ return;
+
+ NSDictionary *representations = @{
+ (NSString *)kUTTypeUTF8PlainText : _positionInformation.url,
+ (NSString *)kUTTypeURL : [NSURL URLWithString:_positionInformation.url]
+ };
+
+ [UIPasteboard generalPasteboard].items = @[ representations ];
+}
+
+- (void)actionSheetAssistant:(WKActionSheetAssistant *)assistant openElementAtLocation:(CGPoint)location
+{
+ CGPoint screenPoint = [self.window convertPoint:[self convertPoint:location toView:nil] toWindow:nil];
+ _webView->_page->navigateToURLWithSimulatedClick(_positionInformation.url, roundedIntPoint(location), roundedIntPoint(screenPoint));
+}
+
+- (RetainPtr<NSArray>)actionSheetAssistant:(WKActionSheetAssistant *)assistant decideActionsForElement:(_WKActivatedElementInfo *)element defaultActions:(RetainPtr<NSArray>)defaultActions
+{
+ return _webView->_page->uiClient().actionsForElement(element, WTF::move(defaultActions));
+}
+
</ins><span class="cx"> @end
</span><span class="cx">
</span><span class="cx"> #endif /* PLATFORM(IOS) */
</span></span></pre>
</div>
</div>
</body>
</html>