Diff
Modified: trunk/Source/WebKit2/ChangeLog (174071 => 174072)
--- trunk/Source/WebKit2/ChangeLog 2014-09-29 18:00:07 UTC (rev 174071)
+++ trunk/Source/WebKit2/ChangeLog 2014-09-29 18:05:36 UTC (rev 174072)
@@ -1,3 +1,30 @@
+2014-09-27 Andy Estes <aes...@apple.com>
+
+ [iOS] Add basic support for link navigation in WKPDFView
+ https://bugs.webkit.org/show_bug.cgi?id=137182
+
+ Reviewed by Tim Horton.
+
+ Teach WKPDFView to navigate to URLs when PDF link annotations are tapped.
+
+ * UIProcess/WebPageProxy.cpp:
+ (WebKit::WebPageProxy::navigateToURLWithSimulatedClick): Sent Messages::WebPage::NavigateToURLWithSimulatedClick.
+ * UIProcess/WebPageProxy.h:
+ * UIProcess/ios/WKPDFView.h:
+ * UIProcess/ios/WKPDFView.mm:
+ (-[WKPDFView _clearPages]): Removed self as the UIPDFAnnotationControllerDelegate.
+ (-[WKPDFView _revalidateViews]): Added self as the UIPDFAnnotationControllerDelegate.
+ (-[WKPDFView annotation:wasTouchedAtPoint:controller:]): Retrieved the URL from the touched annotation,
+ computed the touched point relative to the WKPDFView and to the screen, and called
+ navigateToURLWithSimulatedClick() after a 200 ms delay in order to show a soon-to-be-added tap highlight
+ (this value matches the delay in UIWebPDFView).
+ * WebProcess/WebPage/WebPage.cpp:
+ (WebKit::WebPage::navigateToURLWithSimulatedClick): Created a fake single-click MouseEvent and called
+ FrameLoader::urlSelected(). Creating a mouse event ensures that the navigation appears as a
+ NavigationTypeLinkClicked in navigation policy delegates.
+ * WebProcess/WebPage/WebPage.h:
+ * WebProcess/WebPage/WebPage.messages.in:
+
2014-09-29 Christophe Dumez <cdu...@apple.com>
Use the new is<>() / downcast<>() for Text Nodes
Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (174071 => 174072)
--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp 2014-09-29 18:00:07 UTC (rev 174071)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp 2014-09-29 18:05:36 UTC (rev 174072)
@@ -856,6 +856,18 @@
m_process->responsivenessTimer()->start();
}
+void WebPageProxy::navigateToURLWithSimulatedClick(const String& url, IntPoint documentPoint, IntPoint screenPoint)
+{
+ if (m_isClosed)
+ return;
+
+ if (!isValid())
+ reattachToWebProcess();
+
+ m_process->send(Messages::WebPage::NavigateToURLWithSimulatedClick(url, documentPoint, screenPoint), m_pageID);
+ m_process->responsivenessTimer()->start();
+}
+
void WebPageProxy::stopLoading()
{
if (!isValid())
Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (174071 => 174072)
--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h 2014-09-29 18:00:07 UTC (rev 174071)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h 2014-09-29 18:05:36 UTC (rev 174072)
@@ -308,6 +308,7 @@
void loadAlternateHTMLString(const String& htmlString, const String& baseURL, const String& unreachableURL, API::Object* userData = nullptr);
void loadPlainTextString(const String&, API::Object* userData = nullptr);
void loadWebArchiveData(API::Data*, API::Object* userData = nullptr);
+ void navigateToURLWithSimulatedClick(const String& url, WebCore::IntPoint documentPoint, WebCore::IntPoint screenPoint);
void stopLoading();
uint64_t reload(bool reloadFromOrigin);
Modified: trunk/Source/WebKit2/UIProcess/ios/WKPDFView.h (174071 => 174072)
--- trunk/Source/WebKit2/UIProcess/ios/WKPDFView.h 2014-09-29 18:00:07 UTC (rev 174071)
+++ trunk/Source/WebKit2/UIProcess/ios/WKPDFView.h 2014-09-29 18:05:36 UTC (rev 174072)
@@ -26,10 +26,11 @@
#if PLATFORM(IOS)
#import "WKWebViewContentProvider.h"
+#import <CorePDF/UIPDFAnnotationController.h>
#import <CorePDF/UIPDFPageView.h>
#import <UIKit/UIView.h>
-@interface WKPDFView : UIView <WKWebViewContentProvider, UIPDFPageViewDelegate>
+@interface WKPDFView : UIView <WKWebViewContentProvider, UIPDFPageViewDelegate, UIPDFAnnotationControllerDelegate>
@property (nonatomic, readonly) NSString *suggestedFilename;
@property (nonatomic, readonly) CGPDFDocumentRef pdfDocument;
Modified: trunk/Source/WebKit2/UIProcess/ios/WKPDFView.mm (174071 => 174072)
--- trunk/Source/WebKit2/UIProcess/ios/WKPDFView.mm 2014-09-29 18:00:07 UTC (rev 174071)
+++ trunk/Source/WebKit2/UIProcess/ios/WKPDFView.mm 2014-09-29 18:05:36 UTC (rev 174072)
@@ -30,11 +30,14 @@
#import "WKPDFPageNumberIndicator.h"
#import "WKWebViewInternal.h"
+#import "WebPageProxy.h"
#import <CorePDF/UIPDFDocument.h>
+#import <CorePDF/UIPDFLinkAnnotation.h>
#import <CorePDF/UIPDFPage.h>
#import <CorePDF/UIPDFPageView.h>
#import <UIKit/UIScrollView_Private.h>
#import <WebCore/FloatRect.h>
+#import <chrono>
#import <wtf/RetainPtr.h>
#import <wtf/Vector.h>
@@ -110,6 +113,7 @@
for (auto& page : _pages) {
[page.view removeFromSuperview];
[page.view setDelegate:nil];
+ [[page.view annotationController] setDelegate:nil];
}
_pages.clear();
@@ -179,6 +183,7 @@
pageInfo.view = adoptNS([[UIPDFPageView alloc] initWithPage:pageInfo.page.get() tiledContent:YES]);
[pageInfo.view setUseBackingLayer:YES];
[pageInfo.view setDelegate:self];
+ [[pageInfo.view annotationController] setDelegate:self];
[self addSubview:pageInfo.view.get()];
[pageInfo.view setFrame:pageInfo.frame];
@@ -259,6 +264,7 @@
[_scrollView setContentSize:newFrame.size];
}
+#pragma mark UIPDFPageViewDelegate
- (void)zoom:(UIPDFPageView *)pageView to:(CGRect)targetRect atPoint:(CGPoint)origin kind:(UIPDFObjectKind)kind
{
@@ -288,6 +294,33 @@
_isStartingZoom = NO;
}
+#pragma mark UIPDFAnnotationControllerDelegate
+
+- (void)annotation:(UIPDFAnnotation *)annotation wasTouchedAtPoint:(CGPoint)point controller:(UIPDFAnnotationController *)controller
+{
+ ASSERT(isMainThread());
+
+ if (![annotation isKindOfClass:[UIPDFLinkAnnotation class]])
+ return;
+
+ UIPDFLinkAnnotation *linkAnnotation = (UIPDFLinkAnnotation *)annotation;
+ String urlString = linkAnnotation.url.absoluteString;
+ if (urlString.isEmpty())
+ return;
+
+ // FIXME: Support pageNumber navigations
+
+ CGPoint documentPoint = [controller.pageView convertPoint:point toView:self];
+ CGPoint screenPoint = [self.window convertPoint:[self convertPoint:documentPoint toView:nil] toWindow:nil];
+ static const int64_t dispatchOffset = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::milliseconds(200)).count();
+ RetainPtr<WKWebView> retainedWebView = _webView;
+
+ // Call navigateToURLWithSimulatedClick() on a delay so that a tap highlight can be shown.
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, dispatchOffset), dispatch_get_main_queue(), ^ {
+ retainedWebView->_page->navigateToURLWithSimulatedClick(urlString, roundedIntPoint(documentPoint), roundedIntPoint(screenPoint));
+ });
+}
+
@end
#endif /* PLATFORM(IOS) */
Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (174071 => 174072)
--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp 2014-09-29 18:00:07 UTC (rev 174071)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp 2014-09-29 18:05:36 UTC (rev 174072)
@@ -102,6 +102,7 @@
#include <WebCore/ArchiveResource.h>
#include <WebCore/Chrome.h>
#include <WebCore/ContextMenuController.h>
+#include <WebCore/DataTransfer.h>
#include <WebCore/DatabaseManager.h>
#include <WebCore/DocumentFragment.h>
#include <WebCore/DocumentLoader.h>
@@ -1097,6 +1098,18 @@
loadDataImpl(0, sharedBuffer, ASCIILiteral("application/x-webarchive"), ASCIILiteral("utf-16"), blankURL(), URL(), decoder);
}
+void WebPage::navigateToURLWithSimulatedClick(const String& url, IntPoint documentPoint, IntPoint screenPoint)
+{
+ Frame* mainFrame = m_mainFrame->coreFrame();
+ Document* mainFrameDocument = mainFrame->document();
+ if (!mainFrameDocument)
+ return;
+
+ const int singleClick = 1;
+ RefPtr<MouseEvent> mouseEvent = MouseEvent::create(eventNames().clickEvent, true, true, currentTime(), nullptr, singleClick, screenPoint.x(), screenPoint.y(), documentPoint.x(), documentPoint.y(), false, false, false, false, 0, nullptr, nullptr);
+ mainFrame->loader().urlSelected(mainFrameDocument->completeURL(url), emptyString(), mouseEvent.release(), LockHistory::No, LockBackForwardList::No, ShouldSendReferrer::MaybeSendReferrer);
+}
+
void WebPage::stopLoadingFrame(uint64_t frameID)
{
WebFrame* frame = WebProcess::shared().webFrame(frameID);
Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h (174071 => 174072)
--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h 2014-09-29 18:00:07 UTC (rev 174071)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h 2014-09-29 18:05:36 UTC (rev 174072)
@@ -900,6 +900,7 @@
void loadAlternateHTMLString(const String& htmlString, const String& baseURL, const String& unreachableURL, IPC::MessageDecoder&);
void loadPlainTextString(const String&, IPC::MessageDecoder&);
void loadWebArchiveData(const IPC::DataReference&, IPC::MessageDecoder&);
+ void navigateToURLWithSimulatedClick(const String& url, WebCore::IntPoint documentPoint, WebCore::IntPoint screenPoint);
void reload(uint64_t navigationID, bool reloadFromOrigin, const SandboxExtension::Handle&);
void goForward(uint64_t navigationID, uint64_t);
void goBack(uint64_t navigationID, uint64_t);
Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in (174071 => 174072)
--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in 2014-09-29 18:00:07 UTC (rev 174071)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in 2014-09-29 18:05:36 UTC (rev 174072)
@@ -125,6 +125,7 @@
LoadAlternateHTMLString(String htmlString, String baseURL, String unreachableURL, WebKit::WebContextUserMessageEncoder userData) Variadic
LoadPlainTextString(String string, WebKit::WebContextUserMessageEncoder userData) Variadic
LoadWebArchiveData(IPC::DataReference webArchiveData, WebKit::WebContextUserMessageEncoder userData) Variadic
+ NavigateToURLWithSimulatedClick(String url, WebCore::IntPoint documentPoint, WebCore::IntPoint screenPoint)
Reload(uint64_t navigationID, bool reloadFromOrigin, WebKit::SandboxExtension::Handle sandboxExtensionHandle)
StopLoading()