2 * Copyright (C) 2009 Google 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 are
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
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.
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.
31 #ifndef WebPluginContainerImpl_h
32 #define WebPluginContainerImpl_h
34 #include "WebPluginContainer.h"
35 #include "core/plugins/PluginView.h"
36 #include "platform/Widget.h"
38 #include "wtf/OwnPtr.h"
39 #include "wtf/PassRefPtr.h"
40 #include "wtf/text/WTFString.h"
41 #include "wtf/Vector.h"
47 class HTMLPlugInElement;
51 class PlatformGestureEvent;
53 class ResourceResponse;
61 struct WebPrintParams;
65 class WebPluginLoadObserver;
66 class WebExternalTextureLayer;
68 class WebPluginContainerImpl FINAL : public WebCore::PluginView, public WebPluginContainer {
70 static PassRefPtr<WebPluginContainerImpl> create(WebCore::HTMLPlugInElement* element, WebPlugin* webPlugin)
72 return adoptRef(new WebPluginContainerImpl(element, webPlugin));
76 virtual WebLayer* platformLayer() const OVERRIDE;
77 virtual NPObject* scriptableObject() OVERRIDE;
78 virtual bool getFormValue(String&) OVERRIDE;
79 virtual bool supportsKeyboardFocus() const OVERRIDE;
80 virtual bool supportsInputMethod() const OVERRIDE;
81 virtual bool canProcessDrag() const OVERRIDE;
82 virtual bool wantsWheelEvents() OVERRIDE;
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; }
97 virtual void eventListenersRemoved() OVERRIDE;
99 // WebPluginContainer methods
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;
117 // This cannot be null.
118 virtual WebPlugin* plugin() OVERRIDE { return m_webPlugin; }
119 virtual void setPlugin(WebPlugin*) OVERRIDE;
121 virtual float deviceScaleFactor() OVERRIDE;
122 virtual float pageScaleFactor() OVERRIDE;
123 virtual float pageZoomFactor() OVERRIDE;
125 virtual void setWebLayer(WebLayer*);
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.
142 // Copy the selected text.
145 // Pass the edit command to the plugin.
146 bool executeEditCommand(const WebString& name);
147 bool executeEditCommand(const WebString& name, const WebString& value);
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;
155 void willDestroyPluginLoadObserver(WebPluginLoadObserver*);
157 ScrollbarGroup* scrollbarGroup();
159 void willStartLiveResize();
160 void willEndLiveResize();
162 bool paintCustomOverhangArea(WebCore::GraphicsContext*, const WebCore::IntRect&, const WebCore::IntRect&, const WebCore::IntRect&);
165 WebPluginContainerImpl(WebCore::HTMLPlugInElement* element, WebPlugin* webPlugin);
166 virtual ~WebPluginContainerImpl();
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*);
175 void synthesizeMouseEventIfPossible(WebCore::TouchEvent*);
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);
187 WebCore::HTMLPlugInElement* m_element;
188 WebPlugin* m_webPlugin;
189 Vector<WebPluginLoadObserver*> m_pluginLoadObservers;
191 WebLayer* m_webLayer;
193 // The associated scrollbar group object, created lazily. Used for Pepper
195 OwnPtr<ScrollbarGroup> m_scrollbarGroup;
197 TouchEventRequestType m_touchEventRequestType;
198 bool m_wantsWheelEvents;
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);