initial import
[vuplus_webkit] / Source / WebKit / chromium / src / WebPluginContainerImpl.h
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 "PluginViewBase.h"
35 #include "WebPluginContainer.h"
36 #include "Widget.h"
37
38 #include <wtf/OwnPtr.h>
39 #include <wtf/PassRefPtr.h>
40 #include <wtf/Vector.h>
41
42 struct NPObject;
43
44 namespace WebCore {
45 class HTMLPlugInElement;
46 class IntRect;
47 class KeyboardEvent;
48 class LayerChromium;
49 class MouseEvent;
50 class PluginLayerChromium;
51 class ResourceError;
52 class ResourceResponse;
53 class WheelEvent;
54
55 #if ENABLE(GESTURE_EVENTS)
56 class PlatformGestureEvent;
57 #endif
58 }
59
60 namespace WebKit {
61
62 class ScrollbarGroup;
63 class WebPlugin;
64 class WebPluginLoadObserver;
65
66 class WebPluginContainerImpl : public WebCore::PluginViewBase, public WebPluginContainer {
67 public:
68     static PassRefPtr<WebPluginContainerImpl> create(WebCore::HTMLPlugInElement* element, WebPlugin* webPlugin)
69     {
70         return adoptRef(new WebPluginContainerImpl(element, webPlugin));
71     }
72
73     // Widget methods
74     virtual void setFrameRect(const WebCore::IntRect&);
75     virtual void paint(WebCore::GraphicsContext*, const WebCore::IntRect&);
76     virtual void invalidateRect(const WebCore::IntRect&);
77     virtual void setFocus(bool);
78     virtual void show();
79     virtual void hide();
80     virtual void handleEvent(WebCore::Event*);
81     virtual void frameRectsChanged();
82     virtual void setParentVisible(bool);
83     virtual void setParent(WebCore::ScrollView*);
84     virtual void widgetPositionsUpdated();
85     virtual bool isPluginContainer() const { return true; }
86
87     // WebPluginContainer methods
88     virtual WebElement element();
89     virtual void invalidate();
90     virtual void invalidateRect(const WebRect&);
91     virtual void scrollRect(int dx, int dy, const WebRect&);
92     virtual void reportGeometry();
93     virtual void setBackingTextureId(unsigned);
94     virtual void commitBackingTexture();
95     virtual void clearScriptObjects();
96     virtual NPObject* scriptableObjectForElement();
97     virtual WebString executeScriptURL(const WebURL&, bool popupsAllowed);
98     virtual void loadFrameRequest(const WebURLRequest&, const WebString& target, bool notifyNeeded, void* notifyData);
99     virtual void zoomLevelChanged(double zoomLevel);    
100
101     // This cannot be null.
102     WebPlugin* plugin() { return m_webPlugin; }
103     void setPlugin(WebPlugin* plugin) { m_webPlugin = plugin; }
104
105     // Printing interface. The plugin can support custom printing
106     // (which means it controls the layout, number of pages etc).
107     // Whether the plugin supports its own paginated print. The other print
108     // interface methods are called only if this method returns true.
109     bool supportsPaginatedPrint() const;
110     // Sets up printing at the given print rect and printer DPI. printableArea
111     // is in points (a point is 1/72 of an inch).Returns the number of pages to
112     // be printed at these settings.
113     int printBegin(const WebCore::IntRect& printableArea, int printerDPI) const;
114     // Prints the page specified by pageNumber (0-based index) into the supplied canvas.
115     bool printPage(int pageNumber, WebCore::GraphicsContext* gc);
116     // Ends the print operation.
117     void printEnd();
118
119     // Copy the selected text.
120     void copy();
121
122     // Resource load events for the plugin's source data:
123     void didReceiveResponse(const WebCore::ResourceResponse&);
124     void didReceiveData(const char *data, int dataLength);
125     void didFinishLoading();
126     void didFailLoading(const WebCore::ResourceError&);
127
128     NPObject* scriptableObject();
129
130     void willDestroyPluginLoadObserver(WebPluginLoadObserver*);
131
132 #if USE(ACCELERATED_COMPOSITING)
133     virtual WebCore::LayerChromium* platformLayer() const;
134 #endif
135
136     ScrollbarGroup* scrollbarGroup();
137
138     void willStartLiveResize();
139     void willEndLiveResize();
140
141     bool paintCustomOverhangArea(WebCore::GraphicsContext*, const WebCore::IntRect&, const WebCore::IntRect&, const WebCore::IntRect&);
142
143 #if ENABLE(GESTURE_EVENTS)
144     bool handleGestureEvent(const WebCore::PlatformGestureEvent&);
145 #endif
146
147 private:
148     WebPluginContainerImpl(WebCore::HTMLPlugInElement* element, WebPlugin* webPlugin);
149     ~WebPluginContainerImpl();
150
151     void handleMouseEvent(WebCore::MouseEvent*);
152     void handleWheelEvent(WebCore::WheelEvent*);
153     void handleKeyboardEvent(WebCore::KeyboardEvent*);
154
155     void calculateGeometry(const WebCore::IntRect& frameRect,
156                            WebCore::IntRect& windowRect,
157                            WebCore::IntRect& clipRect,
158                            Vector<WebCore::IntRect>& cutOutRects);
159     WebCore::IntRect windowClipRect() const;
160     void windowCutOutRects(const WebCore::IntRect& frameRect,
161                            Vector<WebCore::IntRect>& cutOutRects);
162
163     WebCore::HTMLPlugInElement* m_element;
164     WebPlugin* m_webPlugin;
165     Vector<WebPluginLoadObserver*> m_pluginLoadObservers;
166
167 #if USE(ACCELERATED_COMPOSITING)
168     RefPtr<WebCore::PluginLayerChromium> m_platformLayer;
169 #endif
170
171     // The associated scrollbar group object, created lazily. Used for Pepper
172     // scrollbars.
173     OwnPtr<ScrollbarGroup> m_scrollbarGroup;
174 };
175
176 } // namespace WebKit
177
178 #endif