WebKit Bugzilla
Attachment 339077 Details for
Bug 185093
: [iOS] Present an action sheet when long-pressing on PDF links
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-185093-20180428152916.patch (text/plain), 8.21 KB, created by
Andy Estes
on 2018-04-28 15:29:17 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Andy Estes
Created:
2018-04-28 15:29:17 PDT
Size:
8.21 KB
patch
obsolete
>Subversion Revision: 231137 >diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog >index 20084f45df5790087ae30b5967deb7ea77ecde57..a7f9ac17ac039e5e2c88696379bdbf2f85c24167 100644 >--- a/Source/WebKit/ChangeLog >+++ b/Source/WebKit/ChangeLog >@@ -1,3 +1,22 @@ >+2018-04-27 Andy Estes <aestes@apple.com> >+ >+ [iOS] Present an action sheet when long-pressing on PDF links >+ https://bugs.webkit.org/show_bug.cgi?id=185093 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * UIProcess/ios/WKPDFView.mm: >+ (-[WKPDFView web_initWithFrame:webView:]): >+ (-[WKPDFView pdfHostViewController:goToURL:]): >+ (-[WKPDFView pdfHostViewController:didLongPressURL:atLocation:]): >+ (-[WKPDFView pdfHostViewController:didLongPressPageIndex:atLocation:]): >+ (-[WKPDFView positionInformationForActionSheetAssistant:]): >+ (-[WKPDFView actionSheetAssistant:performAction:]): >+ (-[WKPDFView actionSheetAssistant:openElementAtLocation:]): >+ (-[WKPDFView actionSheetAssistant:shareElementWithURL:rect:]): >+ (-[WKPDFView actionSheetAssistant:shouldIncludeAppLinkActionsForElement:]): >+ (-[WKPDFView actionSheetAssistant:decideActionsForElement:defaultActions:]): >+ > 2018-04-28 Brent Fulgham <bfulgham@apple.com> > > Revise sandboxes to allow additional IOKit property access >diff --git a/Source/WebKit/UIProcess/ios/WKPDFView.mm b/Source/WebKit/UIProcess/ios/WKPDFView.mm >index 0d60750bf1af48a5b0cdf8923a377b84539c9022..2a0c1006cc15efb7bd0ffb182757927b998da462 100644 >--- a/Source/WebKit/UIProcess/ios/WKPDFView.mm >+++ b/Source/WebKit/UIProcess/ios/WKPDFView.mm >@@ -28,20 +28,24 @@ > > #if ENABLE(WKPDFVIEW) > >+#import "APIUIClient.h" > #import "FindClient.h" >+#import "WKActionSheetAssistant.h" > #import "WKWebViewInternal.h" > #import "WeakObjCPtr.h" > #import "WebPageProxy.h" > #import "_WKWebViewPrintFormatterInternal.h" > #import <PDFKit/PDFHostViewController.h> >+#import <WebCore/WebCoreNSURLExtras.h> > #import <wtf/BlockPtr.h> > #import <wtf/MainThread.h> > #import <wtf/RetainPtr.h> > >-@interface WKPDFView () <PDFHostViewControllerDelegate> >+@interface WKPDFView () <PDFHostViewControllerDelegate, WKActionSheetAssistantDelegate> > @end > > @implementation WKPDFView { >+ RetainPtr<WKActionSheetAssistant> _actionSheetAssistant; > RetainPtr<NSData> _data; > BlockPtr<void()> _findCompletion; > RetainPtr<NSString> _findString; >@@ -53,12 +57,14 @@ @implementation WKPDFView { > RetainPtr<PDFHostViewController> _hostViewController; > CGSize _overlaidAccessoryViewsInset; > RetainPtr<UIView> _pageNumberIndicator; >+ WebKit::InteractionInformationAtPosition _positionInformation; > RetainPtr<NSString> _suggestedFilename; > WebKit::WeakObjCPtr<WKWebView> _webView; > } > > - (void)dealloc > { >+ [_actionSheetAssistant cleanupSheet]; > [[_hostViewController view] removeFromSuperview]; > [_pageNumberIndicator removeFromSuperview]; > [super dealloc]; >@@ -107,6 +113,9 @@ - (void)web_setContentProviderData:(NSData *)data suggestedFilename:(NSString *) > [self removeFromSuperview]; > [scrollView addSubview:hostView]; > >+ _actionSheetAssistant = adoptNS([[WKActionSheetAssistant alloc] initWithView:hostView]); >+ [_actionSheetAssistant setDelegate:self]; >+ > _pageNumberIndicator = hostViewController.pageNumberIndicator; > [_fixedOverlayView addSubview:_pageNumberIndicator.get()]; > >@@ -362,27 +371,109 @@ - (void)pdfHostViewController:(PDFHostViewController *)controller findStringUpda > findCompletion(); > } > >-- (void)pdfHostViewController:(PDFHostViewController *)controller goToURL:(NSURL *)url >+- (NSURL *)_URLWithPageIndex:(NSInteger)pageIndex > { >- WKWebView *webView = _webView.getAutoreleased(); >- if (!webView) >+ return [NSURL URLWithString:[NSString stringWithFormat:@"#page%ld", (long)pageIndex + 1] relativeToURL:[_webView URL]]; >+} >+ >+- (void)_goToURL:(NSURL *)url atLocation:(CGPoint)location >+{ >+ auto page = [_webView _page]; >+ if (!page) > return; > >+ UIView *hostView = [_hostViewController view]; >+ CGPoint locationInScreen = [hostView.window convertPoint:[hostView convertPoint:location toView:nil] toWindow:nil]; >+ page->navigateToPDFLinkWithSimulatedClick(url.absoluteString, WebCore::roundedIntPoint(location), WebCore::roundedIntPoint(locationInScreen)); >+} >+ >+- (void)pdfHostViewController:(PDFHostViewController *)controller goToURL:(NSURL *)url >+{ > // FIXME: We'd use the real tap location if we knew it. >- WebCore::IntPoint point; >- webView->_page->navigateToPDFLinkWithSimulatedClick(url.absoluteString, point, point); >+ [self _goToURL:url atLocation:CGPointMake(0, 0)]; > } > > - (void)pdfHostViewController:(PDFHostViewController *)controller goToPageIndex:(NSInteger)pageIndex withViewFrustum:(CGRect)documentViewRect >+{ >+ [self _goToURL:[self _URLWithPageIndex:pageIndex] atLocation:documentViewRect.origin]; >+} >+ >+- (void)_showActionSheetForURL:(NSURL *)url atLocation:(CGPoint)location > { > WKWebView *webView = _webView.getAutoreleased(); > if (!webView) > return; > >- NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"#page%ld", (long)pageIndex + 1] relativeToURL:webView.URL]; >- CGPoint documentPoint = documentViewRect.origin; >- CGPoint screenPoint = [self.window convertPoint:[self convertPoint:documentPoint toView:nil] toWindow:nil]; >- webView->_page->navigateToPDFLinkWithSimulatedClick(url.absoluteString, WebCore::roundedIntPoint(documentPoint), WebCore::roundedIntPoint(screenPoint)); >+ CGPoint locationInHostView = [webView.scrollView convertPoint:location toView:[_hostViewController view]]; >+ >+ WebKit::InteractionInformationAtPosition positionInformation; >+ positionInformation.bounds = WebCore::roundedIntRect(CGRect { locationInHostView, CGSizeMake(0, 0) }); >+ positionInformation.request.point = WebCore::roundedIntPoint(locationInHostView); >+ positionInformation.url = url; >+ >+ _positionInformation = WTFMove(positionInformation); >+ [_actionSheetAssistant showLinkSheet]; >+} >+ >+- (void)pdfHostViewController:(PDFHostViewController *)controller didLongPressURL:(NSURL *)url atLocation:(CGPoint)location >+{ >+ [self _showActionSheetForURL:url atLocation:location]; >+} >+ >+- (void)pdfHostViewController:(PDFHostViewController *)controller didLongPressPageIndex:(NSInteger)pageIndex atLocation:(CGPoint)location >+{ >+ [self _showActionSheetForURL:[self _URLWithPageIndex:pageIndex] atLocation:location]; >+} >+ >+#pragma mark WKActionSheetAssistantDelegate >+ >+- (std::optional<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 : (NSString *)_positionInformation.url, >+ (NSString *)kUTTypeURL : (NSURL *)_positionInformation.url, >+ }; >+ >+ [UIPasteboard generalPasteboard].items = @[ representations ]; >+} >+ >+- (void)actionSheetAssistant:(WKActionSheetAssistant *)assistant openElementAtLocation:(CGPoint)location >+{ >+ [self _goToURL:_positionInformation.url atLocation:location]; >+} >+ >+- (void)actionSheetAssistant:(WKActionSheetAssistant *)assistant shareElementWithURL:(NSURL *)url rect:(CGRect)boundingRect >+{ >+ auto selectionAssistant = adoptNS([[UIWKSelectionAssistant alloc] initWithView:[_hostViewController view]]); >+ [selectionAssistant showShareSheetFor:WebCore::userVisibleString(url) fromRect:boundingRect]; >+} >+ >+#if HAVE(APP_LINKS) >+- (BOOL)actionSheetAssistant:(WKActionSheetAssistant *)assistant shouldIncludeAppLinkActionsForElement:(_WKActivatedElementInfo *)element >+{ >+ auto page = [_webView _page]; >+ if (!page) >+ return NO; >+ >+ return page->uiClient().shouldIncludeAppLinkActionsForElement(element); >+} >+#endif >+ >+- (RetainPtr<NSArray>)actionSheetAssistant:(WKActionSheetAssistant *)assistant decideActionsForElement:(_WKActivatedElementInfo *)element defaultActions:(RetainPtr<NSArray>)defaultActions >+{ >+ auto page = [_webView _page]; >+ if (!page) >+ return nil; >+ >+ return page->uiClient().actionsForElement(element, WTFMove(defaultActions)); > } > > @end
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 185093
:
339035
|
339077
|
339082