2 * Copyright (C) 2011, 2012 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
29 #if ENABLE(PDFKIT_PLUGIN)
32 #include "SimplePDFPlugin.h"
34 #include <WebCore/AffineTransform.h>
35 #include <WebCore/ScrollableArea.h>
36 #include <wtf/RetainPtr.h>
38 typedef const struct OpaqueJSContext* JSContextRef;
39 typedef struct OpaqueJSValue* JSObjectRef;
40 typedef const struct OpaqueJSValue* JSValueRef;
42 OBJC_CLASS PDFAnnotation;
43 OBJC_CLASS PDFLayerController;
44 OBJC_CLASS WKPDFLayerControllerDelegate;
53 class PDFPluginAnnotation;
57 class PDFPlugin : public SimplePDFPlugin {
59 static PassRefPtr<PDFPlugin> create(WebFrame*);
62 void paintControlForLayerInContext(CALayer *, CGContextRef);
63 void setActiveAnnotation(PDFAnnotation *);
65 using ScrollableArea::notifyScrollPositionChanged;
66 void notifyContentScaleFactorChanged(CGFloat scaleFactor);
68 void clickedLink(NSURL *);
70 void writeItemsToPasteboard(NSArray *items, NSArray *types);
71 void showDefinitionForAttributedString(NSAttributedString *, CGPoint);
74 explicit PDFPlugin(WebFrame*);
76 virtual void updateScrollbars() OVERRIDE;
77 virtual PassRefPtr<WebCore::Scrollbar> createScrollbar(WebCore::ScrollbarOrientation) OVERRIDE;
78 virtual void destroyScrollbar(WebCore::ScrollbarOrientation) OVERRIDE;
79 virtual void pdfDocumentDidLoad() OVERRIDE;
80 virtual void calculateSizes() OVERRIDE;
82 virtual void destroy() OVERRIDE;
83 virtual void paint(WebCore::GraphicsContext*, const WebCore::IntRect& dirtyRectInWindowCoordinates) OVERRIDE;
84 virtual PassRefPtr<ShareableBitmap> snapshot() OVERRIDE;
85 virtual PlatformLayer* pluginLayer() OVERRIDE;
86 virtual void geometryDidChange(const WebCore::IntSize& pluginSize, const WebCore::IntRect& clipRect, const WebCore::AffineTransform& pluginToRootViewTransform) OVERRIDE;
87 virtual void contentsScaleFactorChanged(float) OVERRIDE;
88 virtual bool handleMouseEvent(const WebMouseEvent&) OVERRIDE;
89 virtual bool handleContextMenuEvent(const WebMouseEvent&) OVERRIDE;
90 virtual bool handleKeyboardEvent(const WebKeyboardEvent&) OVERRIDE;
91 virtual bool handleEditingCommand(const String& commandName, const String& argument) OVERRIDE;
92 virtual bool isEditingCommandEnabled(const String&) OVERRIDE;
93 virtual bool handlesPageScaleFactor() OVERRIDE;
95 // ScrollableArea functions.
96 virtual void setScrollOffset(const WebCore::IntPoint&) OVERRIDE;
97 virtual void invalidateScrollbarRect(WebCore::Scrollbar*, const WebCore::IntRect&) OVERRIDE;
98 virtual void invalidateScrollCornerRect(const WebCore::IntRect&) OVERRIDE;
99 virtual WebCore::IntPoint lastKnownMousePosition() const OVERRIDE { return m_lastMousePositionInPluginCoordinates; }
101 NSEvent *nsEventForWebMouseEvent(const WebMouseEvent&);
102 WebCore::IntPoint convertFromPluginToPDFView(const WebCore::IntPoint&) const;
103 WebCore::IntPoint convertFromRootViewToPlugin(const WebCore::IntPoint&) const;
105 bool supportsForms();
106 bool isFullFramePlugin();
108 void updatePageAndDeviceScaleFactors();
110 WebCore::IntPoint convertFromPDFViewToRootView(const WebCore::IntPoint&) const;
112 RetainPtr<CALayer> m_containerLayer;
113 RetainPtr<CALayer> m_contentLayer;
114 RetainPtr<CALayer> m_horizontalScrollbarLayer;
115 RetainPtr<CALayer> m_verticalScrollbarLayer;
116 RetainPtr<CALayer> m_scrollCornerLayer;
117 RetainPtr<PDFLayerController> m_pdfLayerController;
119 RefPtr<PDFPluginAnnotation> m_activeAnnotation;
120 RefPtr<WebCore::Element> m_annotationContainer;
122 WebCore::AffineTransform m_rootViewToPluginTransform;
123 WebMouseEvent m_lastMouseEvent;
124 WebCore::IntPoint m_lastMousePositionInPluginCoordinates;
126 RetainPtr<WKPDFLayerControllerDelegate> m_pdfLayerControllerDelegate;
129 } // namespace WebKit
131 #endif // ENABLE(PDFKIT_PLUGIN)
133 #endif // PDFPlugin_h