Title: [110885] trunk/Source/WebKit2
- Revision
- 110885
- Author
- [email protected]
- Date
- 2012-03-15 14:16:05 -0700 (Thu, 15 Mar 2012)
Log Message
Can't swipe to go back/forward when the current page is a PDF document
https://bugs.webkit.org/show_bug.cgi?id=81194
<rdar://problem/6954125>
Reviewed by Sam Weinig.
Override -[PDFViewScrollView scrollWheel:] and have the new implementation call
-[WKPDFView forwardScrollWheelEvent:] when the PDF is pinned to either the left or right side.
WKPDFView will then call PDFController::forwardScrollWheelEvent which checks if we can go back or forward,
and passes the event along to the WKView which ends up triggering the swiping machinery in Safari.
* UIProcess/API/mac/PDFViewController.h:
* UIProcess/API/mac/PDFViewController.mm:
(-[WKPDFView forwardScrollWheelEvent:]):
(WebKit):
(WebKit::PDFViewController::forwardScrollWheelEvent):
(WebKit::findEnclosingWKPDFView):
(WebKit::PDFViewScrollView_scrollWheel):
(WebKit::PDFViewController::pdfKitBundle):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::didCommitLoadForFrame):
Modified Paths
Diff
Modified: trunk/Source/WebKit2/ChangeLog (110884 => 110885)
--- trunk/Source/WebKit2/ChangeLog 2012-03-15 21:07:49 UTC (rev 110884)
+++ trunk/Source/WebKit2/ChangeLog 2012-03-15 21:16:05 UTC (rev 110885)
@@ -1,3 +1,27 @@
+2012-03-14 Anders Carlsson <[email protected]>
+
+ Can't swipe to go back/forward when the current page is a PDF document
+ https://bugs.webkit.org/show_bug.cgi?id=81194
+ <rdar://problem/6954125>
+
+ Reviewed by Sam Weinig.
+
+ Override -[PDFViewScrollView scrollWheel:] and have the new implementation call
+ -[WKPDFView forwardScrollWheelEvent:] when the PDF is pinned to either the left or right side.
+ WKPDFView will then call PDFController::forwardScrollWheelEvent which checks if we can go back or forward,
+ and passes the event along to the WKView which ends up triggering the swiping machinery in Safari.
+
+ * UIProcess/API/mac/PDFViewController.h:
+ * UIProcess/API/mac/PDFViewController.mm:
+ (-[WKPDFView forwardScrollWheelEvent:]):
+ (WebKit):
+ (WebKit::PDFViewController::forwardScrollWheelEvent):
+ (WebKit::findEnclosingWKPDFView):
+ (WebKit::PDFViewScrollView_scrollWheel):
+ (WebKit::PDFViewController::pdfKitBundle):
+ * UIProcess/WebPageProxy.cpp:
+ (WebKit::WebPageProxy::didCommitLoadForFrame):
+
2012-03-15 Brady Eidson <[email protected]>
<rdar://problem/11036900> and https://bugs.webkit.org/show_bug.cgi?id=81079
Modified: trunk/Source/WebKit2/UIProcess/API/mac/PDFViewController.h (110884 => 110885)
--- trunk/Source/WebKit2/UIProcess/API/mac/PDFViewController.h 2012-03-15 21:07:49 UTC (rev 110884)
+++ trunk/Source/WebKit2/UIProcess/API/mac/PDFViewController.h 2012-03-15 21:16:05 UTC (rev 110885)
@@ -62,6 +62,8 @@
static Class pdfPreviewViewClass();
+ bool forwardScrollWheelEvent(NSEvent *);
+
NSPrintOperation *makePrintOperation(NSPrintInfo *);
void openPDFInFinder();
void savePDFToDownloadsFolder();
Modified: trunk/Source/WebKit2/UIProcess/API/mac/PDFViewController.mm (110884 => 110885)
--- trunk/Source/WebKit2/UIProcess/API/mac/PDFViewController.mm 2012-03-15 21:07:49 UTC (rev 110884)
+++ trunk/Source/WebKit2/UIProcess/API/mac/PDFViewController.mm 2012-03-15 21:16:05 UTC (rev 110885)
@@ -36,6 +36,7 @@
#import "WebPreferences.h"
#import <PDFKit/PDFKit.h>
#import <WebCore/LocalizedStrings.h>
+#import <objc/runtime.h>
#import <wtf/text/CString.h>
#import <wtf/text/WTFString.h>
@@ -114,6 +115,7 @@
- (PDFView *)pdfView;
- (void)setDocument:(PDFDocument *)pdfDocument;
+- (BOOL)forwardScrollWheelEvent:(NSEvent *)wheelEvent;
- (void)_applyPDFPreferences;
- (PDFSelection *)_nextMatchFor:(NSString *)string direction:(BOOL)forward caseSensitive:(BOOL)caseFlag wrap:(BOOL)wrapFlag fromSelection:(PDFSelection *)initialSelection startInSelection:(BOOL)startInSelection;
@end
@@ -383,6 +385,11 @@
_pdfViewController->print();
}
+- (BOOL)forwardScrollWheelEvent:(NSEvent *)wheelEvent
+{
+ return _pdfViewController->forwardScrollWheelEvent(wheelEvent);
+}
+
@end
namespace WebKit {
@@ -486,7 +493,52 @@
return pdfPreviewViewClass;
}
+
+bool PDFViewController::forwardScrollWheelEvent(NSEvent *wheelEvent)
+{
+ CGFloat deltaX = [wheelEvent deltaX];
+ if ((deltaX > 0 && !page()->canGoBack()) || (deltaX < 0 && !page()->canGoForward()))
+ return false;
+
+ [m_wkView scrollWheel:wheelEvent];
+ return true;
+}
+
+static IMP oldPDFViewScrollView_scrollWheel;
+
+static WKPDFView *findEnclosingWKPDFView(NSView *view)
+{
+ for (NSView *superview = [view superview]; superview; superview = [superview superview]) {
+ if ([superview isKindOfClass:[WKPDFView class]])
+ return static_cast<WKPDFView *>(superview);
+ }
+
+ return nil;
+}
+
+static void PDFViewScrollView_scrollWheel(NSScrollView* self, SEL _cmd, NSEvent *wheelEvent)
+{
+ CGFloat deltaX = [wheelEvent deltaX];
+ CGFloat deltaY = [wheelEvent deltaY];
+
+ NSSize contentsSize = [[self documentView] bounds].size;
+ NSRect visibleRect = [self documentVisibleRect];
+
+ // We only want to forward the wheel events if the horizontal delta is non-zero,
+ // and only if we're pinned to either the left or right side.
+ // We also never want to forward momentum scroll events.
+ if ([wheelEvent momentumPhase] == NSEventPhaseNone && deltaX && fabsf(deltaY) < fabsf(deltaX)
+ && ((deltaX > 0 && visibleRect.origin.x <= 0) || (deltaX < 0 && contentsSize.width <= NSMaxX(visibleRect)))) {
+ if (WKPDFView *pdfView = findEnclosingWKPDFView(self)) {
+ if ([pdfView forwardScrollWheelEvent:wheelEvent])
+ return;
+ }
+ }
+
+ oldPDFViewScrollView_scrollWheel(self, _cmd, wheelEvent);
+}
+
NSBundle* PDFViewController::pdfKitBundle()
{
static NSBundle *pdfKitBundle;
@@ -502,6 +554,12 @@
pdfKitBundle = [NSBundle bundleWithPath:pdfKitPath];
if (![pdfKitBundle load])
LOG_ERROR("Couldn't load PDFKit.framework");
+
+ if (Class pdfViewScrollViewClass = [pdfKitBundle classNamed:@"PDFViewScrollView"]) {
+ if (Method scrollWheel = class_getInstanceMethod(pdfViewScrollViewClass, @selector(scrollWheel:)))
+ oldPDFViewScrollView_scrollWheel = method_setImplementation(scrollWheel, reinterpret_cast<IMP>(PDFViewScrollView_scrollWheel));
+ }
+
return pdfKitBundle;
}
Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (110884 => 110885)
--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp 2012-03-15 21:07:49 UTC (rev 110884)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp 2012-03-15 21:16:05 UTC (rev 110885)
@@ -1826,6 +1826,13 @@
if (frame->isMainFrame()) {
m_mainFrameHasCustomRepresentation = frameHasCustomRepresentation;
+
+ if (m_mainFrameHasCustomRepresentation) {
+ // Always assume that the main frame is pinned here, since the custom representation view will handle
+ // any wheel events and dispatch them to the WKView when necessary.
+ m_mainFrameIsPinnedToLeftSide = true;
+ m_mainFrameIsPinnedToRightSide = true;
+ }
m_pageClient->didCommitLoadForMainFrame(frameHasCustomRepresentation);
}
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes