initial import
[vuplus_webkit] / Tools / QtTestBrowser / launcherwindow.h
1 /*
2  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
3  * Copyright (C) 2009 Girish Ramakrishnan <girish@forwardbias.in>
4  * Copyright (C) 2006 George Staikos <staikos@kde.org>
5  * Copyright (C) 2006 Dirk Mueller <mueller@kde.org>
6  * Copyright (C) 2006 Zack Rusin <zack@kde.org>
7  * Copyright (C) 2006 Simon Hausmann <hausmann@kde.org>
8  *
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
21  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
28  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #ifndef launcherwindow_h
34 #define launcherwindow_h
35
36 #include <QtGui>
37 #include <QtNetwork/QNetworkRequest>
38
39 #if defined(QT_CONFIGURED_WITH_OPENGL)
40 #include <QtOpenGL/QGLWidget>
41 #endif
42
43 #if !defined(QT_NO_PRINTER)
44 #include <QPrintPreviewDialog>
45 #endif
46
47 #ifndef QT_NO_UITOOLS
48 #include <QtUiTools/QUiLoader>
49 #endif
50
51 #include <QDebug>
52
53 #include <cstdio>
54 #include <qevent.h>
55 #include <qwebelement.h>
56 #include <qwebframe.h>
57 #include <qwebinspector.h>
58 #include <qwebsettings.h>
59
60 #ifdef Q_WS_MAEMO_5
61 #include <qx11info_x11.h>
62 #endif
63
64 #include "DumpRenderTreeSupportQt.h"
65 #include "mainwindow.h"
66 #include "urlloader.h"
67 #include "utils.h"
68 #include "webinspector.h"
69 #include "webpage.h"
70 #include "webview.h"
71
72 #ifdef Q_WS_MAEMO_5
73 #include <X11/Xatom.h>
74 #include <X11/Xlib.h>
75 #undef KeyPress
76 #endif
77
78 class QPropertyAnimation;
79
80 class WindowOptions {
81 public:
82     WindowOptions()
83         : useGraphicsView(false)
84         , useDiskCache(false)
85         , useCompositing(true)
86         , useTiledBackingStore(false)
87         , useWebGL(false)
88 #if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
89         , useFrameFlattening(true)
90 #else
91         , useFrameFlattening(false)
92 #endif
93         , cacheWebView(false)
94         , showFrameRate(false)
95         , resizesToContents(false)
96         , viewportUpdateMode(QGraphicsView::MinimalViewportUpdate)
97         , useLocalStorage(false)
98         , useOfflineStorageDatabase(false)
99         , useOfflineWebApplicationCache(false)
100         , useDiskCookies(true)
101         , offlineStorageDefaultQuotaSize(0)
102 #if defined(QT_CONFIGURED_WITH_OPENGL)
103         , useQGLWidgetViewport(false)
104 #endif
105 #if defined(Q_WS_X11)
106         , useTestFonts(false)
107 #endif
108         , printLoadedUrls(false)
109 #if defined(Q_OS_SYMBIAN)
110         , startMaximized(true)
111 #else
112         , startMaximized(false)
113 #endif
114     {
115     }
116
117     bool useGraphicsView;
118     bool useDiskCache;
119     bool useCompositing;
120     bool useTiledBackingStore;
121     bool useWebGL;
122     bool useFrameFlattening;
123     bool cacheWebView;
124     bool showFrameRate;
125     bool resizesToContents;
126     QGraphicsView::ViewportUpdateMode viewportUpdateMode;
127     bool useLocalStorage;
128     bool useOfflineStorageDatabase;
129     bool useOfflineWebApplicationCache;
130     bool useDiskCookies;
131     quint64 offlineStorageDefaultQuotaSize;
132 #if defined(QT_CONFIGURED_WITH_OPENGL)
133     bool useQGLWidgetViewport;
134 #endif
135 #if defined(Q_WS_X11)
136     bool useTestFonts;
137 #endif
138     bool printLoadedUrls;
139     QUrl inspectorUrl;
140     quint16 remoteInspectorPort;
141     bool startMaximized;
142 };
143
144 class LauncherWindow : public MainWindow {
145     Q_OBJECT
146
147 public:
148     LauncherWindow(WindowOptions* data = 0, QGraphicsScene* sharedScene = 0);
149     virtual ~LauncherWindow();
150
151     virtual void keyPressEvent(QKeyEvent* event);
152     void grabZoomKeys(bool grab);
153
154     void sendTouchEvent();
155
156     bool eventFilter(QObject* obj, QEvent* event);
157
158 protected slots:
159     void loadStarted();
160     void loadFinished();
161
162     void showLinkHover(const QString &link, const QString &toolTip);
163
164     void zoomIn();
165     void zoomOut();
166     void resetZoom();
167     void toggleZoomTextOnly(bool on);
168     void zoomAnimationFinished();
169
170     void print();
171     void screenshot();
172
173     void setEditable(bool on);
174
175     /* void dumpPlugins() */
176     void dumpHtml();
177
178     void loadURLListFromFile();
179
180     void setDiskCache(bool enable);
181     void setTouchMocking(bool on);
182     void toggleWebView(bool graphicsBased);
183     void toggleAcceleratedCompositing(bool toggle);
184     void toggleTiledBackingStore(bool toggle);
185     void toggleResizesToContents(bool toggle);
186     void toggleWebGL(bool toggle);
187     void toggleSpatialNavigation(bool b);
188     void toggleFullScreenMode(bool enable);
189     void toggleFrameFlattening(bool toggle);
190     void toggleInterruptingJavaScriptEnabled(bool enable);
191     void toggleJavascriptCanOpenWindows(bool enable);
192     void toggleAutoLoadImages(bool enable);
193     void setUseDiskCookies(bool enable);
194     void clearCookies();
195     void togglePlugins(bool enable);
196     void toggleLocalStorage(bool toggle);
197     void toggleOfflineStorageDatabase(bool toggle);
198     void toggleOfflineWebApplicationCache(bool toggle);
199     void setOfflineStorageDefaultQuota();
200 #ifndef QT_NO_LINEEDIT
201     void showFindBar();
202     void find(int mode);
203 #endif
204 #if defined(QT_CONFIGURED_WITH_OPENGL)
205     void toggleQGLWidgetViewport(bool enable);
206 #endif
207
208     void changeViewportUpdateMode(int mode);
209     void animatedFlip();
210     void animatedYFlip();
211     void selectElements();
212     void showFPS(bool enable);
213     void showUserAgentDialog();
214
215     void printURL(const QUrl&);
216 #if !defined(QT_NO_FILEDIALOG) && !defined(QT_NO_MESSAGEBOX)
217     void downloadRequest(const QNetworkRequest&);
218     void fileDownloadFinished();
219 #endif
220
221 public slots:
222     LauncherWindow* newWindow();
223     LauncherWindow* cloneWindow();
224     void updateFPS(int fps);
225
226 signals:
227     void enteredFullScreenMode(bool on);
228
229 private:
230     void init();
231     void initializeView();
232     void createChrome();
233     void applyPrefs();
234     void applyZoom();
235
236     bool isGraphicsBased() const;
237
238 private:
239     static QVector<int> m_zoomLevels;
240     int m_currentZoom;
241
242     UrlLoader* m_urlLoader;
243
244     QWidget* m_view;
245     WebInspector* m_inspector;
246
247     WindowOptions m_windowOptions;
248
249     QAction* m_formatMenuAction;
250
251     QPropertyAnimation* m_zoomAnimation;
252 #if !defined(QT_NO_FILEDIALOG) && !defined(QT_NO_MESSAGEBOX)
253     QNetworkReply* m_reply;
254 #endif
255     QList<QTouchEvent::TouchPoint> m_touchPoints;
256     bool m_touchMocking;
257
258     QString m_inputUrl;
259 #ifndef QT_NO_LINEEDIT
260     QToolBar* m_findBar;
261     QLineEdit* m_lineEdit;
262     int m_findFlag;
263     static const int s_findNormalFlag = 0;
264 #endif
265 };
266
267 #endif