[iOS] Navigate to URL and page number annotations in WKPDFView
authoraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Apr 2018 22:35:46 +0000 (22:35 +0000)
committeraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Apr 2018 22:35:46 +0000 (22:35 +0000)
https://bugs.webkit.org/show_bug.cgi?id=184410

Reviewed by Timothy Hatcher.

Implemented navigation to URL and page number (same-document) link annotations in PDFs.

* UIProcess/ios/WKPDFView.mm:
(-[WKPDFView _scrollToURLFragment:]):
(-[WKPDFView web_didSameDocumentNavigation:]):
(-[WKPDFView pdfHostViewController:updatePageCount:]):
(-[WKPDFView pdfHostViewController:goToURL:]):
(-[WKPDFView pdfHostViewController:goToPageIndex:withViewFrustum:]):

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

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

index 8652571..b456955 100644 (file)
@@ -1,5 +1,21 @@
 2018-04-10  Andy Estes  <aestes@apple.com>
 
+        [iOS] Navigate to URL and page number annotations in WKPDFView
+        https://bugs.webkit.org/show_bug.cgi?id=184410
+
+        Reviewed by Timothy Hatcher.
+
+        Implemented navigation to URL and page number (same-document) link annotations in PDFs.
+
+        * UIProcess/ios/WKPDFView.mm:
+        (-[WKPDFView _scrollToURLFragment:]):
+        (-[WKPDFView web_didSameDocumentNavigation:]):
+        (-[WKPDFView pdfHostViewController:updatePageCount:]):
+        (-[WKPDFView pdfHostViewController:goToURL:]):
+        (-[WKPDFView pdfHostViewController:goToPageIndex:withViewFrustum:]):
+
+2018-04-10  Andy Estes  <aestes@apple.com>
+
         [iOS] WKPDFView should conform to _WKWebViewPrintProvider
         https://bugs.webkit.org/show_bug.cgi?id=184471
 
index 52d9d35..70fa16a 100644 (file)
     _fixedOverlayView = fixedOverlayView;
 }
 
+- (void)_scrollToURLFragment:(NSString *)fragment
+{
+    NSInteger pageIndex = 0;
+    if ([fragment hasPrefix:@"page"])
+        pageIndex = [[fragment substringFromIndex:4] integerValue] - 1;
+
+    if (pageIndex >= 0 && pageIndex < [_hostViewController pageCount] && pageIndex != [_hostViewController currentPageIndex])
+        [_hostViewController goToPageIndex:pageIndex];
+}
+
 - (void)web_didSameDocumentNavigation:(WKSameDocumentNavigationType)navigationType
 {
-    // FIXME: Implement page number navigations.
+    if (navigationType == kWKSameDocumentNavigationSessionStatePop)
+        [self _scrollToURLFragment:[_webView URL].fragment];
 }
 
 - (void)web_countStringMatches:(NSString *)string options:(_WKFindOptions)options maxCount:(NSUInteger)maxCount
     return self.isBackground;
 }
 
+#pragma mark PDFHostViewControllerDelegate
+
+- (void)pdfHostViewController:(PDFHostViewController *)controller updatePageCount:(NSInteger)pageCount
+{
+    [self _scrollToURLFragment:[_webView URL].fragment];
+}
+
+- (void)pdfHostViewController:(PDFHostViewController *)controller goToURL:(NSURL *)url
+{
+    WKWebView *webView = _webView.getAutoreleased();
+    if (!webView)
+        return;
+
+    // FIXME: We'd use the real tap location if we knew it.
+    WebCore::IntPoint point;
+    webView->_page->navigateToPDFLinkWithSimulatedClick(url.absoluteString, point, point);
+}
+
+- (void)pdfHostViewController:(PDFHostViewController *)controller goToPageIndex:(NSInteger)pageIndex withViewFrustum:(CGRect)documentViewRect
+{
+    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));
+}
+
 @end
 
 #pragma mark _WKWebViewPrintProvider