Changeset 230497 in webkit


Ignore:
Timestamp:
Apr 10, 2018 3:35:46 PM (6 years ago)
Author:
aestes@apple.com
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:]):

Location:
trunk/Source/WebKit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r230496 r230497  
     12018-04-10  Andy Estes  <aestes@apple.com>
     2
     3        [iOS] Navigate to URL and page number annotations in WKPDFView
     4        https://bugs.webkit.org/show_bug.cgi?id=184410
     5
     6        Reviewed by Timothy Hatcher.
     7
     8        Implemented navigation to URL and page number (same-document) link annotations in PDFs.
     9
     10        * UIProcess/ios/WKPDFView.mm:
     11        (-[WKPDFView _scrollToURLFragment:]):
     12        (-[WKPDFView web_didSameDocumentNavigation:]):
     13        (-[WKPDFView pdfHostViewController:updatePageCount:]):
     14        (-[WKPDFView pdfHostViewController:goToURL:]):
     15        (-[WKPDFView pdfHostViewController:goToPageIndex:withViewFrustum:]):
     16
    1172018-04-10  Andy Estes  <aestes@apple.com>
    218
  • trunk/Source/WebKit/UIProcess/ios/WKPDFView.mm

    r230496 r230497  
    163163}
    164164
     165- (void)_scrollToURLFragment:(NSString *)fragment
     166{
     167    NSInteger pageIndex = 0;
     168    if ([fragment hasPrefix:@"page"])
     169        pageIndex = [[fragment substringFromIndex:4] integerValue] - 1;
     170
     171    if (pageIndex >= 0 && pageIndex < [_hostViewController pageCount] && pageIndex != [_hostViewController currentPageIndex])
     172        [_hostViewController goToPageIndex:pageIndex];
     173}
     174
    165175- (void)web_didSameDocumentNavigation:(WKSameDocumentNavigationType)navigationType
    166176{
    167     // FIXME: Implement page number navigations.
     177    if (navigationType == kWKSameDocumentNavigationSessionStatePop)
     178        [self _scrollToURLFragment:[_webView URL].fragment];
    168179}
    169180
     
    221232{
    222233    return self.isBackground;
     234}
     235
     236#pragma mark PDFHostViewControllerDelegate
     237
     238- (void)pdfHostViewController:(PDFHostViewController *)controller updatePageCount:(NSInteger)pageCount
     239{
     240    [self _scrollToURLFragment:[_webView URL].fragment];
     241}
     242
     243- (void)pdfHostViewController:(PDFHostViewController *)controller goToURL:(NSURL *)url
     244{
     245    WKWebView *webView = _webView.getAutoreleased();
     246    if (!webView)
     247        return;
     248
     249    // FIXME: We'd use the real tap location if we knew it.
     250    WebCore::IntPoint point;
     251    webView->_page->navigateToPDFLinkWithSimulatedClick(url.absoluteString, point, point);
     252}
     253
     254- (void)pdfHostViewController:(PDFHostViewController *)controller goToPageIndex:(NSInteger)pageIndex withViewFrustum:(CGRect)documentViewRect
     255{
     256    WKWebView *webView = _webView.getAutoreleased();
     257    if (!webView)
     258        return;
     259
     260    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"#page%ld", (long)pageIndex + 1] relativeToURL:webView.URL];
     261    CGPoint documentPoint = documentViewRect.origin;
     262    CGPoint screenPoint = [self.window convertPoint:[self convertPoint:documentPoint toView:nil] toWindow:nil];
     263    webView->_page->navigateToPDFLinkWithSimulatedClick(url.absoluteString, WebCore::roundedIntPoint(documentPoint), WebCore::roundedIntPoint(screenPoint));
    223264}
    224265
Note: See TracChangeset for help on using the changeset viewer.