Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 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" |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 35 | #include "core/plugins/PluginView.h" |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 36 | #include "platform/Widget.h" |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 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; |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 56 | class Widget; |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 57 | } |
| 58 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 59 | namespace blink { |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 60 | |
| 61 | struct WebPrintParams; |
| 62 | |
| 63 | class ScrollbarGroup; |
| 64 | class WebPlugin; |
| 65 | class WebPluginLoadObserver; |
| 66 | class WebExternalTextureLayer; |
| 67 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 68 | class WebPluginContainerImpl FINAL : public WebCore::PluginView, public WebPluginContainer { |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 69 | public: |
| 70 | static PassRefPtr<WebPluginContainerImpl> create(WebCore::HTMLPlugInElement* element, WebPlugin* webPlugin) |
| 71 | { |
| 72 | return adoptRef(new WebPluginContainerImpl(element, webPlugin)); |
| 73 | } |
| 74 | |
| 75 | // PluginView methods |
| 76 | virtual WebLayer* platformLayer() const OVERRIDE; |
| 77 | virtual NPObject* scriptableObject() OVERRIDE; |
| 78 | virtual bool getFormValue(String&) OVERRIDE; |
| 79 | virtual bool supportsKeyboardFocus() const OVERRIDE; |
Torne (Richard Coles) | a854de0 | 2013-12-18 16:25:25 +0000 | [diff] [blame] | 80 | virtual bool supportsInputMethod() const OVERRIDE; |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 81 | virtual bool canProcessDrag() const OVERRIDE; |
| 82 | virtual bool wantsWheelEvents() OVERRIDE; |
| 83 | |
| 84 | // Widget methods |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 85 | virtual void setFrameRect(const WebCore::IntRect&) OVERRIDE; |
| 86 | virtual void paint(WebCore::GraphicsContext*, const WebCore::IntRect&) OVERRIDE; |
| 87 | virtual void invalidateRect(const WebCore::IntRect&) OVERRIDE; |
| 88 | virtual void setFocus(bool) OVERRIDE; |
| 89 | virtual void show() OVERRIDE; |
| 90 | virtual void hide() OVERRIDE; |
| 91 | virtual void handleEvent(WebCore::Event*) OVERRIDE; |
| 92 | virtual void frameRectsChanged() OVERRIDE; |
| 93 | virtual void setParentVisible(bool) OVERRIDE; |
| 94 | virtual void setParent(WebCore::Widget*) OVERRIDE; |
| 95 | virtual void widgetPositionsUpdated() OVERRIDE; |
| 96 | virtual bool isPluginContainer() const OVERRIDE { return true; } |
Torne (Richard Coles) | c0e19a6 | 2013-08-30 15:15:11 +0100 | [diff] [blame] | 97 | virtual void eventListenersRemoved() OVERRIDE; |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 98 | |
| 99 | // WebPluginContainer methods |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 100 | virtual WebElement element() OVERRIDE; |
| 101 | virtual void invalidate() OVERRIDE; |
| 102 | virtual void invalidateRect(const WebRect&) OVERRIDE; |
| 103 | virtual void scrollRect(int dx, int dy, const WebRect&) OVERRIDE; |
| 104 | virtual void reportGeometry() OVERRIDE; |
| 105 | virtual void allowScriptObjects() OVERRIDE; |
| 106 | virtual void clearScriptObjects() OVERRIDE; |
| 107 | virtual NPObject* scriptableObjectForElement() OVERRIDE; |
| 108 | virtual WebString executeScriptURL(const WebURL&, bool popupsAllowed) OVERRIDE; |
| 109 | virtual void loadFrameRequest(const WebURLRequest&, const WebString& target, bool notifyNeeded, void* notifyData) OVERRIDE; |
| 110 | virtual void zoomLevelChanged(double zoomLevel) OVERRIDE; |
| 111 | virtual bool isRectTopmost(const WebRect&) OVERRIDE; |
| 112 | virtual void requestTouchEventType(TouchEventRequestType) OVERRIDE; |
| 113 | virtual void setWantsWheelEvents(bool) OVERRIDE; |
| 114 | virtual WebPoint windowToLocalPoint(const WebPoint&) OVERRIDE; |
| 115 | virtual WebPoint localToWindowPoint(const WebPoint&) OVERRIDE; |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 116 | |
| 117 | // This cannot be null. |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 118 | virtual WebPlugin* plugin() OVERRIDE { return m_webPlugin; } |
| 119 | virtual void setPlugin(WebPlugin*) OVERRIDE; |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 120 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 121 | virtual float deviceScaleFactor() OVERRIDE; |
| 122 | virtual float pageScaleFactor() OVERRIDE; |
| 123 | virtual float pageZoomFactor() OVERRIDE; |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 124 | |
| 125 | virtual void setWebLayer(WebLayer*); |
| 126 | |
| 127 | // Printing interface. The plugin can support custom printing |
| 128 | // (which means it controls the layout, number of pages etc). |
| 129 | // Whether the plugin supports its own paginated print. The other print |
| 130 | // interface methods are called only if this method returns true. |
| 131 | bool supportsPaginatedPrint() const; |
| 132 | // If the plugin content should not be scaled to the printable area of |
| 133 | // the page, then this method should return true. |
| 134 | bool isPrintScalingDisabled() const; |
| 135 | // Sets up printing at the specified WebPrintParams. Returns the number of pages to be printed at these settings. |
| 136 | int printBegin(const WebPrintParams&) const; |
| 137 | // Prints the page specified by pageNumber (0-based index) into the supplied canvas. |
| 138 | bool printPage(int pageNumber, WebCore::GraphicsContext* gc); |
| 139 | // Ends the print operation. |
| 140 | void printEnd(); |
| 141 | |
| 142 | // Copy the selected text. |
| 143 | void copy(); |
| 144 | |
| 145 | // Pass the edit command to the plugin. |
| 146 | bool executeEditCommand(const WebString& name); |
| 147 | bool executeEditCommand(const WebString& name, const WebString& value); |
| 148 | |
| 149 | // Resource load events for the plugin's source data: |
| 150 | virtual void didReceiveResponse(const WebCore::ResourceResponse&) OVERRIDE; |
| 151 | virtual void didReceiveData(const char *data, int dataLength) OVERRIDE; |
| 152 | virtual void didFinishLoading() OVERRIDE; |
| 153 | virtual void didFailLoading(const WebCore::ResourceError&) OVERRIDE; |
| 154 | |
| 155 | void willDestroyPluginLoadObserver(WebPluginLoadObserver*); |
| 156 | |
| 157 | ScrollbarGroup* scrollbarGroup(); |
| 158 | |
| 159 | void willStartLiveResize(); |
| 160 | void willEndLiveResize(); |
| 161 | |
| 162 | bool paintCustomOverhangArea(WebCore::GraphicsContext*, const WebCore::IntRect&, const WebCore::IntRect&, const WebCore::IntRect&); |
| 163 | |
| 164 | private: |
| 165 | WebPluginContainerImpl(WebCore::HTMLPlugInElement* element, WebPlugin* webPlugin); |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 166 | virtual ~WebPluginContainerImpl(); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 167 | |
| 168 | void handleMouseEvent(WebCore::MouseEvent*); |
| 169 | void handleDragEvent(WebCore::MouseEvent*); |
| 170 | void handleWheelEvent(WebCore::WheelEvent*); |
| 171 | void handleKeyboardEvent(WebCore::KeyboardEvent*); |
| 172 | void handleTouchEvent(WebCore::TouchEvent*); |
| 173 | void handleGestureEvent(WebCore::GestureEvent*); |
| 174 | |
| 175 | void synthesizeMouseEventIfPossible(WebCore::TouchEvent*); |
| 176 | |
| 177 | void focusPlugin(); |
| 178 | |
| 179 | void calculateGeometry(const WebCore::IntRect& frameRect, |
| 180 | WebCore::IntRect& windowRect, |
| 181 | WebCore::IntRect& clipRect, |
| 182 | Vector<WebCore::IntRect>& cutOutRects); |
| 183 | WebCore::IntRect windowClipRect() const; |
| 184 | void windowCutOutRects(const WebCore::IntRect& frameRect, |
| 185 | Vector<WebCore::IntRect>& cutOutRects); |
| 186 | |
| 187 | WebCore::HTMLPlugInElement* m_element; |
| 188 | WebPlugin* m_webPlugin; |
| 189 | Vector<WebPluginLoadObserver*> m_pluginLoadObservers; |
| 190 | |
| 191 | WebLayer* m_webLayer; |
| 192 | |
| 193 | // The associated scrollbar group object, created lazily. Used for Pepper |
| 194 | // scrollbars. |
| 195 | OwnPtr<ScrollbarGroup> m_scrollbarGroup; |
| 196 | |
| 197 | TouchEventRequestType m_touchEventRequestType; |
| 198 | bool m_wantsWheelEvents; |
| 199 | }; |
| 200 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 201 | DEFINE_TYPE_CASTS(WebPluginContainerImpl, WebCore::Widget, widget, widget->isPluginContainer(), widget.isPluginContainer()); |
| 202 | // Unlike Widget, we need not worry about object type for container. |
| 203 | // WebPluginContainerImpl is the only subclass of WebPluginContainer. |
| 204 | DEFINE_TYPE_CASTS(WebPluginContainerImpl, WebPluginContainer, container, true, true); |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 205 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 206 | } // namespace blink |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 207 | |
| 208 | #endif |