tizen beta release
[profile/ivi/webkit-efl.git] / Tools / DumpRenderTree / chromium / TestWebPlugin.h
1 /*
2  * Copyright (C) 2011 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
6  * are met:
7  *
8  * 1.  Redistributions of source code must retain the above copyright
9  *     notice, this list of conditions and the following disclaimer.
10  * 2.  Redistributions in binary form must reproduce the above copyright
11  *     notice, this list of conditions and the following disclaimer in the
12  *     documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #ifndef TestWebPlugin_h
27 #define TestWebPlugin_h
28
29 #include "WebPlugin.h"
30 #include "WebRect.h"
31
32 namespace WebKit {
33 class WebGraphicsContext3D;
34 }
35
36 // A fake implemention of WebKit::WebPlugin for testing purposes.
37 //
38 // It uses WebGraphicsContext3D to paint a scene consisiting of a primitive
39 // over a background. The primitive and background can be customized using
40 // the following plugin parameters:
41 // primitive: none (default), triangle.
42 // background-color: black (default), red, green, blue.
43 // primitive-color: black (default), red, green, blue.
44 // opacity: [0.0 - 1.0]. Default is 1.0.
45 class TestWebPlugin : public WebKit::WebPlugin {
46 public:
47     TestWebPlugin(WebKit::WebFrame*, const WebKit::WebPluginParams&);
48     virtual ~TestWebPlugin();
49
50     static const WebKit::WebString& mimeType();
51
52     // WebPlugin methods:
53     virtual bool initialize(WebKit::WebPluginContainer*);
54     virtual void destroy();
55     virtual NPObject* scriptableObject() { return 0; }
56     virtual void paint(WebKit::WebCanvas*, const WebKit::WebRect&) { }
57     virtual void updateGeometry(const WebKit::WebRect& frameRect,
58                                 const WebKit::WebRect& clipRect,
59                                 const WebKit::WebVector<WebKit::WebRect>& cutOutsRects,
60                                 bool isVisible);
61     virtual void updateFocus(bool) { }
62     virtual void updateVisibility(bool) { }
63     virtual bool acceptsInputEvents() { return false; }
64     virtual bool handleInputEvent(const WebKit::WebInputEvent&, WebKit::WebCursorInfo&) { return false; }
65     virtual void didReceiveResponse(const WebKit::WebURLResponse&) { }
66     virtual void didReceiveData(const char* data, int dataLength) { }
67     virtual void didFinishLoading() { }
68     virtual void didFailLoading(const WebKit::WebURLError&) { }
69     virtual void didFinishLoadingFrameRequest(const WebKit::WebURL&, void* notifyData) { }
70     virtual void didFailLoadingFrameRequest(const WebKit::WebURL&, void* notifyData, const WebKit::WebURLError&) { }
71
72 private:
73     enum Primitive {
74         PrimitiveNone,
75         PrimitiveTriangle
76     };
77
78     struct Scene {
79         Primitive primitive;
80         unsigned backgroundColor[3];
81         unsigned primitiveColor[3];
82         float opacity;
83
84         unsigned vbo;
85         unsigned program;
86         int colorLocation;
87         int positionLocation;
88
89         Scene()
90             : primitive(PrimitiveNone)
91             , opacity(1.0f) // Fully opaque.
92             , vbo(0)
93             , program(0)
94             , colorLocation(-1)
95             , positionLocation(-1)
96         {
97             backgroundColor[0] = backgroundColor[1] = backgroundColor[2] = 0;
98             primitiveColor[0] = primitiveColor[1] = primitiveColor[2] = 0;
99         }
100     };
101
102     // Functions for parsing plugin parameters.
103     Primitive parsePrimitive(const WebKit::WebString&);
104     void parseColor(const WebKit::WebString&, unsigned color[3]);
105     float parseOpacity(const WebKit::WebString&);
106
107     // Functions for loading and drawing scene.
108     bool initScene();
109     void drawScene();
110     void destroyScene();
111     bool initProgram();
112     bool initPrimitive();
113     void drawPrimitive();
114     unsigned loadShader(unsigned type, const WTF::CString& source);
115     unsigned loadProgram(const WTF::CString& vertexSource,
116                          const WTF::CString& fragmentSource);
117
118     WebKit::WebFrame* m_frame;
119     WebKit::WebPluginContainer* m_container;
120
121     WebKit::WebRect m_rect;
122     WebKit::WebGraphicsContext3D* m_context;
123     Scene m_scene;
124 };
125
126 #endif // TestPepperPlugin_h