1 /* 2 * Copyright (C) 2009 Google Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above 11 * copyright notice, this list of conditions and the following disclaimer 12 * in the documentation and/or other materials provided with the 13 * distribution. 14 * * Neither the name of Google Inc. nor the names of its 15 * contributors may be used to endorse or promote products derived from 16 * this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #ifndef WebPluginContainerImpl_h 32 #define WebPluginContainerImpl_h 33 34 #include "WebPluginContainer.h" 35 #include "core/platform/Widget.h" 36 #include "core/plugins/PluginView.h" 37 38 #include "wtf/OwnPtr.h" 39 #include "wtf/PassRefPtr.h" 40 #include "wtf/text/WTFString.h" 41 #include "wtf/Vector.h" 42 43 struct NPObject; 44 45 namespace WebCore { 46 class GestureEvent; 47 class HTMLPlugInElement; 48 class IntRect; 49 class KeyboardEvent; 50 class MouseEvent; 51 class PlatformGestureEvent; 52 class ResourceError; 53 class ResourceResponse; 54 class TouchEvent; 55 class WheelEvent; 56 } 57 58 namespace WebKit { 59 60 struct WebPrintParams; 61 62 class ScrollbarGroup; 63 class WebPlugin; 64 class WebPluginLoadObserver; 65 class WebExternalTextureLayer; 66 67 class WebPluginContainerImpl : public WebCore::PluginView, public WebPluginContainer { 68 public: 69 static PassRefPtr<WebPluginContainerImpl> create(WebCore::HTMLPlugInElement* element, WebPlugin* webPlugin) 70 { 71 return adoptRef(new WebPluginContainerImpl(element, webPlugin)); 72 } 73 74 // PluginView methods 75 virtual WebLayer* platformLayer() const OVERRIDE; 76 virtual NPObject* scriptableObject() OVERRIDE; 77 virtual bool getFormValue(String&) OVERRIDE; 78 virtual bool supportsKeyboardFocus() const OVERRIDE; 79 virtual bool canProcessDrag() const OVERRIDE; 80 virtual bool wantsWheelEvents() OVERRIDE; 81 82 // Widget methods 83 virtual void setFrameRect(const WebCore::IntRect&); 84 virtual void paint(WebCore::GraphicsContext*, const WebCore::IntRect&); 85 virtual void invalidateRect(const WebCore::IntRect&); 86 virtual void setFocus(bool); 87 virtual void show(); 88 virtual void hide(); 89 virtual void handleEvent(WebCore::Event*); 90 virtual void frameRectsChanged(); 91 virtual void setParentVisible(bool); 92 virtual void setParent(WebCore::ScrollView*); 93 virtual void widgetPositionsUpdated(); 94 virtual void clipRectChanged() OVERRIDE; 95 virtual bool isPluginContainer() const { return true; } 96 97 // WebPluginContainer methods 98 virtual WebElement element(); 99 virtual void invalidate(); 100 virtual void invalidateRect(const WebRect&); 101 virtual void scrollRect(int dx, int dy, const WebRect&); 102 virtual void reportGeometry(); 103 virtual void allowScriptObjects(); 104 virtual void clearScriptObjects(); 105 virtual NPObject* scriptableObjectForElement(); 106 virtual WebString executeScriptURL(const WebURL&, bool popupsAllowed); 107 virtual void loadFrameRequest(const WebURLRequest&, const WebString& target, bool notifyNeeded, void* notifyData); 108 virtual void zoomLevelChanged(double zoomLevel); 109 virtual bool isRectTopmost(const WebRect&); 110 virtual void requestTouchEventType(TouchEventRequestType); 111 virtual void setWantsWheelEvents(bool); 112 virtual WebPoint windowToLocalPoint(const WebPoint&); 113 virtual WebPoint localToWindowPoint(const WebPoint&); 114 115 // This cannot be null. 116 WebPlugin* plugin() { return m_webPlugin; } 117 void setPlugin(WebPlugin*); 118 119 virtual float deviceScaleFactor(); 120 virtual float pageScaleFactor(); 121 virtual float pageZoomFactor(); 122 123 virtual void setWebLayer(WebLayer*); 124 125 // Printing interface. The plugin can support custom printing 126 // (which means it controls the layout, number of pages etc). 127 // Whether the plugin supports its own paginated print. The other print 128 // interface methods are called only if this method returns true. 129 bool supportsPaginatedPrint() const; 130 // If the plugin content should not be scaled to the printable area of 131 // the page, then this method should return true. 132 bool isPrintScalingDisabled() const; 133 // Sets up printing at the specified WebPrintParams. Returns the number of pages to be printed at these settings. 134 int printBegin(const WebPrintParams&) const; 135 // Prints the page specified by pageNumber (0-based index) into the supplied canvas. 136 bool printPage(int pageNumber, WebCore::GraphicsContext* gc); 137 // Ends the print operation. 138 void printEnd(); 139 140 // Copy the selected text. 141 void copy(); 142 143 // Pass the edit command to the plugin. 144 bool executeEditCommand(const WebString& name); 145 bool executeEditCommand(const WebString& name, const WebString& value); 146 147 // Resource load events for the plugin's source data: 148 virtual void didReceiveResponse(const WebCore::ResourceResponse&) OVERRIDE; 149 virtual void didReceiveData(const char *data, int dataLength) OVERRIDE; 150 virtual void didFinishLoading() OVERRIDE; 151 virtual void didFailLoading(const WebCore::ResourceError&) OVERRIDE; 152 153 void willDestroyPluginLoadObserver(WebPluginLoadObserver*); 154 155 ScrollbarGroup* scrollbarGroup(); 156 157 void willStartLiveResize(); 158 void willEndLiveResize(); 159 160 bool paintCustomOverhangArea(WebCore::GraphicsContext*, const WebCore::IntRect&, const WebCore::IntRect&, const WebCore::IntRect&); 161 162 private: 163 WebPluginContainerImpl(WebCore::HTMLPlugInElement* element, WebPlugin* webPlugin); 164 ~WebPluginContainerImpl(); 165 166 void handleMouseEvent(WebCore::MouseEvent*); 167 void handleDragEvent(WebCore::MouseEvent*); 168 void handleWheelEvent(WebCore::WheelEvent*); 169 void handleKeyboardEvent(WebCore::KeyboardEvent*); 170 void handleTouchEvent(WebCore::TouchEvent*); 171 void handleGestureEvent(WebCore::GestureEvent*); 172 173 void synthesizeMouseEventIfPossible(WebCore::TouchEvent*); 174 175 void focusPlugin(); 176 177 void calculateGeometry(const WebCore::IntRect& frameRect, 178 WebCore::IntRect& windowRect, 179 WebCore::IntRect& clipRect, 180 Vector<WebCore::IntRect>& cutOutRects); 181 WebCore::IntRect windowClipRect() const; 182 void windowCutOutRects(const WebCore::IntRect& frameRect, 183 Vector<WebCore::IntRect>& cutOutRects); 184 185 WebCore::HTMLPlugInElement* m_element; 186 WebPlugin* m_webPlugin; 187 Vector<WebPluginLoadObserver*> m_pluginLoadObservers; 188 189 WebLayer* m_webLayer; 190 191 // The associated scrollbar group object, created lazily. Used for Pepper 192 // scrollbars. 193 OwnPtr<ScrollbarGroup> m_scrollbarGroup; 194 195 TouchEventRequestType m_touchEventRequestType; 196 bool m_wantsWheelEvents; 197 }; 198 199 } // namespace WebKit 200 201 #endif 202