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