Title: [230497] trunk/Source/WebKit
Revision
230497
Author
aes...@apple.com
Date
2018-04-10 15:35:46 -0700 (Tue, 10 Apr 2018)

Log Message

[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:]):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (230496 => 230497)


--- trunk/Source/WebKit/ChangeLog	2018-04-10 22:26:45 UTC (rev 230496)
+++ trunk/Source/WebKit/ChangeLog	2018-04-10 22:35:46 UTC (rev 230497)
@@ -1,5 +1,21 @@
 2018-04-10  Andy Estes  <aes...@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  <aes...@apple.com>
+
         [iOS] WKPDFView should conform to _WKWebViewPrintProvider
         https://bugs.webkit.org/show_bug.cgi?id=184471
 

Modified: trunk/Source/WebKit/UIProcess/ios/WKPDFView.mm (230496 => 230497)


--- trunk/Source/WebKit/UIProcess/ios/WKPDFView.mm	2018-04-10 22:26:45 UTC (rev 230496)
+++ trunk/Source/WebKit/UIProcess/ios/WKPDFView.mm	2018-04-10 22:35:46 UTC (rev 230497)
@@ -162,9 +162,20 @@
     _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
@@ -222,6 +233,36 @@
     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 = "" 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
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to