summaryrefslogtreecommitdiff
path: root/Source/WebKit2/WebProcess/Plugins/PDF
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2012-11-29 12:18:48 +0100
committerSimon Hausmann <simon.hausmann@digia.com>2012-11-29 12:18:57 +0100
commit4c01d0526ba4dd8cff0c0ff22a6f0ab5eb973064 (patch)
treebed2fe914fe0f7ec70abfb47d2d84af8a3604d09 /Source/WebKit2/WebProcess/Plugins/PDF
parent01485457c9a5da3f1121015afd25bb53af77662e (diff)
downloadqtwebkit-4c01d0526ba4dd8cff0c0ff22a6f0ab5eb973064.tar.gz
Imported WebKit commit c60cfe0fc09efd257aa0111d7b133b02deb8a63e (http://svn.webkit.org/repository/webkit/trunk@136119)
New snapshot that includes the fix for installing the QtWebProcess into libexec Change-Id: I01344e079cbdac5678c4cba6ffcc05f4597cf0d7 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'Source/WebKit2/WebProcess/Plugins/PDF')
-rw-r--r--Source/WebKit2/WebProcess/Plugins/PDF/PDFAnnotationTextWidgetDetails.h31
-rw-r--r--Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.h7
-rw-r--r--Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm101
-rw-r--r--Source/WebKit2/WebProcess/Plugins/PDF/PDFPluginTextAnnotation.mm5
4 files changed, 120 insertions, 24 deletions
diff --git a/Source/WebKit2/WebProcess/Plugins/PDF/PDFAnnotationTextWidgetDetails.h b/Source/WebKit2/WebProcess/Plugins/PDF/PDFAnnotationTextWidgetDetails.h
new file mode 100644
index 000000000..8656ff466
--- /dev/null
+++ b/Source/WebKit2/WebProcess/Plugins/PDF/PDFAnnotationTextWidgetDetails.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2012 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <PDFKit/PDFKit.h>
+
+@interface PDFAnnotationTextWidget (Details)
+- (BOOL)isMultiline;
+- (BOOL)isReadOnly;
+@end
diff --git a/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.h b/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.h
index a1233fabe..132c28774 100644
--- a/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.h
+++ b/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.h
@@ -94,11 +94,16 @@ private:
virtual void setScrollOffset(const WebCore::IntPoint&) OVERRIDE;
virtual void invalidateScrollbarRect(WebCore::Scrollbar*, const WebCore::IntRect&) OVERRIDE;
virtual void invalidateScrollCornerRect(const WebCore::IntRect&) OVERRIDE;
+ virtual WebCore::IntPoint currentMousePosition() const { return m_lastMousePositionInPluginCoordinates; }
NSEvent *nsEventForWebMouseEvent(const WebMouseEvent&);
+ WebCore::IntPoint convertFromPluginToPDFView(const WebCore::IntPoint&) const;
+ WebCore::IntPoint convertFromRootViewToPlugin(const WebCore::IntPoint&) const;
bool supportsForms();
+ void updatePageAndDeviceScaleFactors();
+
RetainPtr<CALayer> m_containerLayer;
RetainPtr<CALayer> m_contentLayer;
RetainPtr<CALayer> m_horizontalScrollbarLayer;
@@ -110,8 +115,8 @@ private:
RefPtr<WebCore::Element> m_annotationContainer;
WebCore::AffineTransform m_rootViewToPluginTransform;
- WebCore::IntPoint m_lastMousePoint;
WebMouseEvent m_lastMouseEvent;
+ WebCore::IntPoint m_lastMousePositionInPluginCoordinates;
RetainPtr<WKPDFLayerControllerDelegate> m_pdfLayerControllerDelegate;
};
diff --git a/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm b/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm
index 716b24e15..f50fb8c0e 100644
--- a/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm
+++ b/Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm
@@ -30,6 +30,7 @@
#import "ArgumentCoders.h"
#import "DataReference.h"
+#import "PDFAnnotationTextWidgetDetails.h"
#import "PDFKitImports.h"
#import "PDFLayerControllerDetails.h"
#import "PDFPluginAnnotation.h"
@@ -303,7 +304,7 @@ void PDFPlugin::pdfDocumentDidLoad()
[m_pdfLayerController.get() setFrameSize:size()];
m_pdfLayerController.get().document = document.get();
- [m_pdfLayerController.get() setDeviceScaleFactor:controller()->contentsScaleFactor()];
+ updatePageAndDeviceScaleFactors();
if (handlesPageScaleFactor())
pluginView()->setPageScaleFactor([m_pdfLayerController.get() contentScaleFactor], IntPoint());
@@ -316,9 +317,18 @@ void PDFPlugin::pdfDocumentDidLoad()
runScriptsInPDFDocument();
}
-void PDFPlugin::contentsScaleFactorChanged(float contentsScaleFactor)
+void PDFPlugin::updatePageAndDeviceScaleFactors()
{
- [m_pdfLayerController.get() setDeviceScaleFactor:contentsScaleFactor];
+ double newScaleFactor = controller()->contentsScaleFactor();
+ if (!handlesPageScaleFactor())
+ newScaleFactor *= webFrame()->page()->pageScaleFactor();
+
+ [m_pdfLayerController.get() setDeviceScaleFactor:newScaleFactor];
+}
+
+void PDFPlugin::contentsScaleFactorChanged(float)
+{
+ updatePageAndDeviceScaleFactors();
}
void PDFPlugin::calculateSizes()
@@ -405,6 +415,16 @@ PlatformLayer* PDFPlugin::pluginLayer()
return m_containerLayer.get();
}
+IntPoint PDFPlugin::convertFromRootViewToPlugin(const IntPoint& point) const
+{
+ return m_rootViewToPluginTransform.mapPoint(point);
+}
+
+IntPoint PDFPlugin::convertFromPluginToPDFView(const IntPoint& point) const
+{
+ return IntPoint(point.x(), size().height() - point.y());
+}
+
void PDFPlugin::geometryDidChange(const IntSize& pluginSize, const IntRect&, const AffineTransform& pluginToRootViewTransform)
{
if (size() == pluginSize && pluginView()->pageScaleFactor() == [m_pdfLayerController.get() contentScaleFactor])
@@ -422,10 +442,14 @@ void PDFPlugin::geometryDidChange(const IntSize& pluginSize, const IntRect&, con
if (handlesPageScaleFactor()) {
CGFloat magnification = pluginView()->pageScaleFactor() - [m_pdfLayerController.get() contentScaleFactor];
- // FIXME: Instead of m_lastMousePoint, we should use the zoom origin from PluginView::setPageScaleFactor.
+ // FIXME: Instead of m_lastMousePositionInPluginCoordinates, we should use the zoom origin from PluginView::setPageScaleFactor.
if (magnification)
- [m_pdfLayerController.get() magnifyWithMagnification:magnification atPoint:m_lastMousePoint immediately:NO];
- }
+ [m_pdfLayerController.get() magnifyWithMagnification:magnification atPoint:convertFromPluginToPDFView(m_lastMousePositionInPluginCoordinates) immediately:NO];
+ } else {
+ // If we don't handle page scale ourselves, we need to respect our parent page's
+ // scale, which may have changed.
+ updatePageAndDeviceScaleFactors();
+ }
calculateSizes();
updateScrollbars();
@@ -493,13 +517,9 @@ static NSEventType eventTypeFromWebEvent(const WebEvent& event)
NSEvent *PDFPlugin::nsEventForWebMouseEvent(const WebMouseEvent& event)
{
- IntPoint mousePosition = event.position();
+ m_lastMousePositionInPluginCoordinates = convertFromRootViewToPlugin(event.position());
- IntPoint positionInPDFView(mousePosition);
- positionInPDFView = m_rootViewToPluginTransform.mapPoint(positionInPDFView);
- positionInPDFView.setY(size().height() - positionInPDFView.y());
-
- m_lastMousePoint = positionInPDFView;
+ IntPoint positionInPDFViewCoordinates(convertFromPluginToPDFView(m_lastMousePositionInPluginCoordinates));
NSEventType eventType = eventTypeFromWebEvent(event);
@@ -508,27 +528,59 @@ NSEvent *PDFPlugin::nsEventForWebMouseEvent(const WebMouseEvent& event)
NSUInteger modifierFlags = modifierFlagsFromWebEvent(event);
- return [NSEvent mouseEventWithType:eventType location:positionInPDFView modifierFlags:modifierFlags timestamp:0 windowNumber:0 context:nil eventNumber:0 clickCount:event.clickCount() pressure:0];
+ return [NSEvent mouseEventWithType:eventType location:positionInPDFViewCoordinates modifierFlags:modifierFlags timestamp:0 windowNumber:0 context:nil eventNumber:0 clickCount:event.clickCount() pressure:0];
}
bool PDFPlugin::handleMouseEvent(const WebMouseEvent& event)
{
+ PlatformMouseEvent platformEvent = platform(event);
+ IntPoint mousePosition = convertFromRootViewToPlugin(event.position());
+
m_lastMouseEvent = event;
- IntPoint mousePosition = event.position();
+ RefPtr<Scrollbar> targetScrollbar;
+ RefPtr<Scrollbar> targetScrollbarForLastMousePosition;
- // FIXME: Forward mouse events to the appropriate scrollbar.
- if (IntRect(m_verticalScrollbarLayer.get().frame).contains(mousePosition)
- || IntRect(m_horizontalScrollbarLayer.get().frame).contains(mousePosition)
- || IntRect(m_scrollCornerLayer.get().frame).contains(mousePosition))
+ if (m_verticalScrollbarLayer) {
+ IntRect verticalScrollbarFrame(m_verticalScrollbarLayer.get().frame);
+ if (verticalScrollbarFrame.contains(mousePosition))
+ targetScrollbar = verticalScrollbar();
+ if (verticalScrollbarFrame.contains(m_lastMousePositionInPluginCoordinates))
+ targetScrollbarForLastMousePosition = verticalScrollbar();
+ }
+
+ if (m_horizontalScrollbarLayer) {
+ IntRect horizontalScrollbarFrame(m_horizontalScrollbarLayer.get().frame);
+ if (horizontalScrollbarFrame.contains(mousePosition))
+ targetScrollbar = horizontalScrollbar();
+ if (horizontalScrollbarFrame.contains(m_lastMousePositionInPluginCoordinates))
+ targetScrollbarForLastMousePosition = horizontalScrollbar();
+ }
+
+ if (m_scrollCornerLayer && IntRect(m_scrollCornerLayer.get().frame).contains(mousePosition))
return false;
+ // Right-clicks and Control-clicks always call handleContextMenuEvent as well.
+ if (event.button() == WebMouseEvent::RightButton || (event.button() == WebMouseEvent::LeftButton && event.controlKey()))
+ return true;
+
NSEvent *nsEvent = nsEventForWebMouseEvent(event);
switch (event.type()) {
case WebEvent::MouseMove:
mouseMovedInContentArea();
+ if (targetScrollbar) {
+ if (!targetScrollbarForLastMousePosition) {
+ targetScrollbar->mouseEntered();
+ return true;
+ }
+ return targetScrollbar->mouseMoved(platformEvent);
+ }
+
+ if (!targetScrollbar && targetScrollbarForLastMousePosition)
+ targetScrollbarForLastMousePosition->mouseExited();
+
switch (event.button()) {
case WebMouseEvent::LeftButton:
[m_pdfLayerController.get() mouseDragged:nsEvent];
@@ -543,6 +595,9 @@ bool PDFPlugin::handleMouseEvent(const WebMouseEvent& event)
case WebEvent::MouseDown:
switch (event.button()) {
case WebMouseEvent::LeftButton:
+ if (targetScrollbar)
+ return targetScrollbar->mouseDown(platformEvent);
+
[m_pdfLayerController.get() mouseDown:nsEvent];
return true;
case WebMouseEvent::RightButton:
@@ -555,6 +610,9 @@ bool PDFPlugin::handleMouseEvent(const WebMouseEvent& event)
case WebEvent::MouseUp:
switch (event.button()) {
case WebMouseEvent::LeftButton:
+ if (targetScrollbar)
+ return targetScrollbar->mouseUp(platformEvent);
+
[m_pdfLayerController.get() mouseUp:nsEvent];
return true;
case WebMouseEvent::RightButton:
@@ -574,7 +632,7 @@ bool PDFPlugin::handleContextMenuEvent(const WebMouseEvent& event)
NSMenu *nsMenu = [m_pdfLayerController.get() menuForEvent:nsEventForWebMouseEvent(event)];
FrameView* frameView = webFrame()->coreFrame()->view();
- IntPoint point = frameView->contentsToScreen(IntRect(event.position(), IntSize())).location();
+ IntPoint point = frameView->contentsToScreen(IntRect(frameView->windowToContents(event.position()), IntSize())).location();
if (nsMenu) {
WKPopupContextMenu(nsMenu, point);
return true;
@@ -672,6 +730,11 @@ void PDFPlugin::setActiveAnnotation(PDFAnnotation *annotation)
m_activeAnnotation->commit();
if (annotation) {
+ if ([annotation isKindOfClass:pdfAnnotationTextWidgetClass()] && static_cast<PDFAnnotationTextWidget *>(annotation).isReadOnly) {
+ m_activeAnnotation = 0;
+ return;
+ }
+
m_activeAnnotation = PDFPluginAnnotation::create(annotation, m_pdfLayerController.get(), this);
m_activeAnnotation->attach(m_annotationContainer.get());
} else
diff --git a/Source/WebKit2/WebProcess/Plugins/PDF/PDFPluginTextAnnotation.mm b/Source/WebKit2/WebProcess/Plugins/PDF/PDFPluginTextAnnotation.mm
index b5df3732d..f69a5d598 100644
--- a/Source/WebKit2/WebProcess/Plugins/PDF/PDFPluginTextAnnotation.mm
+++ b/Source/WebKit2/WebProcess/Plugins/PDF/PDFPluginTextAnnotation.mm
@@ -28,6 +28,7 @@
#import "config.h"
#import "PDFPluginTextAnnotation.h"
+#import "PDFAnnotationTextWidgetDetails.h"
#import "PDFKitImports.h"
#import "PDFLayerControllerDetails.h"
#import <PDFKit/PDFKit.h>
@@ -40,10 +41,6 @@
#import <WebCore/HTMLTextAreaElement.h>
#import <WebCore/Page.h>
-@interface PDFAnnotationTextWidget (Details)
-- (BOOL)isMultiline;
-@end
-
using namespace WebCore;
namespace WebKit {