blob: 1b0a2b97c40bf5785ef7050a2c885640c6a65382 [file] [log] [blame]
Ben Murdoche69819b2013-07-17 14:56:49 +01001/*
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 Murdoche69819b2013-07-17 14:56:49 +010035#include "core/plugins/PluginView.h"
Torne (Richard Coles)1e202182013-10-18 15:46:42 +010036#include "platform/Widget.h"
Ben Murdoche69819b2013-07-17 14:56:49 +010037
38#include "wtf/OwnPtr.h"
39#include "wtf/PassRefPtr.h"
40#include "wtf/text/WTFString.h"
41#include "wtf/Vector.h"
42
43struct NPObject;
44
45namespace WebCore {
46class GestureEvent;
47class HTMLPlugInElement;
48class IntRect;
49class KeyboardEvent;
50class MouseEvent;
51class PlatformGestureEvent;
52class ResourceError;
53class ResourceResponse;
54class TouchEvent;
55class WheelEvent;
Torne (Richard Coles)8abfc582013-09-12 12:10:38 +010056class Widget;
Ben Murdoche69819b2013-07-17 14:56:49 +010057}
58
Torne (Richard Coles)51b29062013-11-28 11:56:03 +000059namespace blink {
Ben Murdoche69819b2013-07-17 14:56:49 +010060
61struct WebPrintParams;
62
63class ScrollbarGroup;
64class WebPlugin;
65class WebPluginLoadObserver;
66class WebExternalTextureLayer;
67
Torne (Richard Coles)09380292014-02-21 12:17:33 +000068class WebPluginContainerImpl FINAL : public WebCore::PluginView, public WebPluginContainer {
Ben Murdoche69819b2013-07-17 14:56:49 +010069public:
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)a854de02013-12-18 16:25:25 +000080 virtual bool supportsInputMethod() const OVERRIDE;
Ben Murdoche69819b2013-07-17 14:56:49 +010081 virtual bool canProcessDrag() const OVERRIDE;
82 virtual bool wantsWheelEvents() OVERRIDE;
83
84 // Widget methods
Torne (Richard Coles)09380292014-02-21 12:17:33 +000085 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)c0e19a62013-08-30 15:15:11 +010097 virtual void eventListenersRemoved() OVERRIDE;
Ben Murdoche69819b2013-07-17 14:56:49 +010098
99 // WebPluginContainer methods
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000100 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 Murdoche69819b2013-07-17 14:56:49 +0100116
117 // This cannot be null.
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000118 virtual WebPlugin* plugin() OVERRIDE { return m_webPlugin; }
119 virtual void setPlugin(WebPlugin*) OVERRIDE;
Ben Murdoche69819b2013-07-17 14:56:49 +0100120
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000121 virtual float deviceScaleFactor() OVERRIDE;
122 virtual float pageScaleFactor() OVERRIDE;
123 virtual float pageZoomFactor() OVERRIDE;
Ben Murdoche69819b2013-07-17 14:56:49 +0100124
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
164private:
165 WebPluginContainerImpl(WebCore::HTMLPlugInElement* element, WebPlugin* webPlugin);
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000166 virtual ~WebPluginContainerImpl();
Ben Murdoche69819b2013-07-17 14:56:49 +0100167
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)09380292014-02-21 12:17:33 +0000201DEFINE_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.
204DEFINE_TYPE_CASTS(WebPluginContainerImpl, WebPluginContainer, container, true, true);
Torne (Richard Coles)8abfc582013-09-12 12:10:38 +0100205
Torne (Richard Coles)51b29062013-11-28 11:56:03 +0000206} // namespace blink
Ben Murdoche69819b2013-07-17 14:56:49 +0100207
208#endif