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/FindOptions.h>
36 #include <WebCore/ScrollableArea.h>
37 #include <wtf/RetainPtr.h>
39 typedef const struct OpaqueJSContext* JSContextRef;
40 typedef struct OpaqueJSValue* JSObjectRef;
41 typedef const struct OpaqueJSValue* JSValueRef;
43 OBJC_CLASS PDFAnnotation;
44 OBJC_CLASS PDFLayerController;
45 OBJC_CLASS PDFSelection;
46 OBJC_CLASS WKPDFLayerControllerDelegate;
59 class PDFPluginAnnotation;
63 class PDFPlugin : public SimplePDFPlugin {
65 static PassRefPtr<PDFPlugin> create(WebFrame*);
68 void paintControlForLayerInContext(CALayer *, CGContextRef);
69 void setActiveAnnotation(PDFAnnotation *);
71 using ScrollableArea::notifyScrollPositionChanged;
72 void notifyContentScaleFactorChanged(CGFloat scaleFactor);
73 void notifyDisplayModeChanged(int);
75 void notifySelectionChanged(PDFSelection *);
77 void clickedLink(NSURL *);
79 void openWithNativeApplication();
80 void writeItemsToPasteboard(NSArray *items, NSArray *types);
81 void showDefinitionForAttributedString(NSAttributedString *, CGPoint);
82 void performWebSearch(NSString *);
84 void focusNextAnnotation();
85 void focusPreviousAnnotation();
88 explicit PDFPlugin(WebFrame*);
90 virtual void updateScrollbars() OVERRIDE;
91 virtual PassRefPtr<WebCore::Scrollbar> createScrollbar(WebCore::ScrollbarOrientation) OVERRIDE;
92 virtual void destroyScrollbar(WebCore::ScrollbarOrientation) OVERRIDE;
93 virtual void pdfDocumentDidLoad() OVERRIDE;
94 virtual void calculateSizes() OVERRIDE;
96 virtual void destroy() OVERRIDE;
97 virtual void paint(WebCore::GraphicsContext*, const WebCore::IntRect& dirtyRectInWindowCoordinates) OVERRIDE;
98 virtual PassRefPtr<ShareableBitmap> snapshot() OVERRIDE;
99 virtual PlatformLayer* pluginLayer() OVERRIDE;
100 virtual void geometryDidChange(const WebCore::IntSize& pluginSize, const WebCore::IntRect& clipRect, const WebCore::AffineTransform& pluginToRootViewTransform) OVERRIDE;
101 virtual void contentsScaleFactorChanged(float) OVERRIDE;
102 virtual bool handleMouseEvent(const WebMouseEvent&) OVERRIDE;
103 virtual bool handleContextMenuEvent(const WebMouseEvent&) OVERRIDE;
104 virtual bool handleKeyboardEvent(const WebKeyboardEvent&) OVERRIDE;
105 virtual bool handleEditingCommand(const String& commandName, const String& argument) OVERRIDE;
106 virtual bool isEditingCommandEnabled(const String&) OVERRIDE;
107 virtual bool handlesPageScaleFactor() OVERRIDE;
109 virtual unsigned countFindMatches(const String& target, WebCore::FindOptions, unsigned maxMatchCount) OVERRIDE;
110 virtual bool findString(const String& target, WebCore::FindOptions, unsigned maxMatchCount) OVERRIDE;
112 PDFSelection *nextMatchForString(const String& target, BOOL searchForward, BOOL caseSensitive, BOOL wrapSearch, PDFSelection *initialSelection, BOOL startInSelection);
114 virtual bool performDictionaryLookupAtLocation(const WebCore::FloatPoint&) OVERRIDE;
115 virtual String getSelectionString() const OVERRIDE;
117 virtual bool handleWheelEvent(const WebWheelEvent& event) OVERRIDE;
119 // ScrollableArea functions.
120 virtual void setScrollOffset(const WebCore::IntPoint&) OVERRIDE;
121 virtual void invalidateScrollbarRect(WebCore::Scrollbar*, const WebCore::IntRect&) OVERRIDE;
122 virtual void invalidateScrollCornerRect(const WebCore::IntRect&) OVERRIDE;
123 virtual WebCore::IntPoint lastKnownMousePosition() const OVERRIDE { return m_lastMousePositionInPluginCoordinates; }
125 NSEvent *nsEventForWebMouseEvent(const WebMouseEvent&);
126 WebCore::IntPoint convertFromPluginToPDFView(const WebCore::IntPoint&) const;
127 WebCore::IntPoint convertFromRootViewToPlugin(const WebCore::IntPoint&) const;
129 bool supportsForms();
130 bool isFullFramePlugin();
132 void updatePageAndDeviceScaleFactors();
134 WebCore::IntPoint convertFromPDFViewToRootView(const WebCore::IntPoint&) const;
136 RetainPtr<CALayer> m_containerLayer;
137 RetainPtr<CALayer> m_contentLayer;
138 RetainPtr<CALayer> m_horizontalScrollbarLayer;
139 RetainPtr<CALayer> m_verticalScrollbarLayer;
140 RetainPtr<CALayer> m_scrollCornerLayer;
141 RetainPtr<PDFLayerController> m_pdfLayerController;
143 RefPtr<PDFPluginAnnotation> m_activeAnnotation;
144 RefPtr<WebCore::Element> m_annotationContainer;
146 WebCore::AffineTransform m_rootViewToPluginTransform;
147 WebMouseEvent m_lastMouseEvent;
148 WebCore::IntPoint m_lastMousePositionInPluginCoordinates;
150 String m_temporaryPDFUUID;
152 String m_lastFoundString;
154 RetainPtr<WKPDFLayerControllerDelegate> m_pdfLayerControllerDelegate;
157 } // namespace WebKit
159 #endif // ENABLE(PDFKIT_PLUGIN)
161 #endif // PDFPlugin_h