• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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:
WindowOptions()82     WindowOptions()
83         : useGraphicsView(false)
84         , useCompositing(true)
85         , useTiledBackingStore(false)
86         , useWebGL(false)
87 #if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
88         , useFrameFlattening(true)
89 #else
90         , useFrameFlattening(false)
91 #endif
92         , cacheWebView(false)
93         , showFrameRate(false)
94         , resizesToContents(false)
95         , viewportUpdateMode(QGraphicsView::MinimalViewportUpdate)
96         , useLocalStorage(false)
97         , useOfflineStorageDatabase(false)
98         , useOfflineWebApplicationCache(false)
99         , offlineStorageDefaultQuotaSize(0)
100 #if defined(QT_CONFIGURED_WITH_OPENGL)
101         , useQGLWidgetViewport(false)
102 #endif
103 #if defined(Q_WS_X11)
104         , useTestFonts(false)
105 #endif
106         , printLoadedUrls(false)
107 #if defined(Q_OS_SYMBIAN)
108         , startMaximized(true)
109 #else
110         , startMaximized(false)
111 #endif
112     {
113     }
114 
115     bool useGraphicsView;
116     bool useCompositing;
117     bool useTiledBackingStore;
118     bool useWebGL;
119     bool useFrameFlattening;
120     bool cacheWebView;
121     bool showFrameRate;
122     bool resizesToContents;
123     QGraphicsView::ViewportUpdateMode viewportUpdateMode;
124     bool useLocalStorage;
125     bool useOfflineStorageDatabase;
126     bool useOfflineWebApplicationCache;
127     quint64 offlineStorageDefaultQuotaSize;
128 #if defined(QT_CONFIGURED_WITH_OPENGL)
129     bool useQGLWidgetViewport;
130 #endif
131 #if defined(Q_WS_X11)
132     bool useTestFonts;
133 #endif
134     bool printLoadedUrls;
135     QUrl inspectorUrl;
136     quint16 remoteInspectorPort;
137     bool startMaximized;
138 };
139 
140 class LauncherWindow : public MainWindow {
141     Q_OBJECT
142 
143 public:
144     LauncherWindow(WindowOptions* data = 0, QGraphicsScene* sharedScene = 0);
145     virtual ~LauncherWindow();
146 
147     virtual void keyPressEvent(QKeyEvent* event);
148     void grabZoomKeys(bool grab);
149 
150     void sendTouchEvent();
151 
152     bool eventFilter(QObject* obj, QEvent* event);
153 
154 protected slots:
155     void loadStarted();
156     void loadFinished();
157 
158     void showLinkHover(const QString &link, const QString &toolTip);
159 
160     void zoomIn();
161     void zoomOut();
162     void resetZoom();
163     void toggleZoomTextOnly(bool on);
164     void zoomAnimationFinished();
165 
166     void print();
167     void screenshot();
168 
169     void setEditable(bool on);
170 
171     /* void dumpPlugins() */
172     void dumpHtml();
173 
174     void loadURLListFromFile();
175 
176     void setTouchMocking(bool on);
177     void toggleWebView(bool graphicsBased);
178     void toggleAcceleratedCompositing(bool toggle);
179     void toggleTiledBackingStore(bool toggle);
180     void toggleResizesToContents(bool toggle);
181     void toggleWebGL(bool toggle);
182     void toggleSpatialNavigation(bool b);
183     void toggleFullScreenMode(bool enable);
184     void toggleFrameFlattening(bool toggle);
185     void toggleInterruptingJavaScriptEnabled(bool enable);
186     void toggleJavascriptCanOpenWindows(bool enable);
187     void toggleAutoLoadImages(bool enable);
188     void togglePlugins(bool enable);
189     void toggleLocalStorage(bool toggle);
190     void toggleOfflineStorageDatabase(bool toggle);
191     void toggleOfflineWebApplicationCache(bool toggle);
192     void setOfflineStorageDefaultQuota();
193 
194 #if defined(QT_CONFIGURED_WITH_OPENGL)
195     void toggleQGLWidgetViewport(bool enable);
196 #endif
197 
198     void changeViewportUpdateMode(int mode);
199     void animatedFlip();
200     void animatedYFlip();
201     void selectElements();
202     void showFPS(bool enable);
203     void showUserAgentDialog();
204 
205     void printURL(const QUrl&);
206 
207 public slots:
208     LauncherWindow* newWindow();
209     LauncherWindow* cloneWindow();
210     void updateFPS(int fps);
211 
212 signals:
213     void enteredFullScreenMode(bool on);
214 
215 private:
216     void init();
217     void initializeView();
218     void createChrome();
219     void applyPrefs();
220     void applyZoom();
221 
222     bool isGraphicsBased() const;
223 
224 private:
225     static QVector<int> m_zoomLevels;
226     int m_currentZoom;
227 
228     UrlLoader* m_urlLoader;
229 
230     QWidget* m_view;
231     WebInspector* m_inspector;
232 
233     WindowOptions m_windowOptions;
234 
235     QAction* m_formatMenuAction;
236 
237     QPropertyAnimation* m_zoomAnimation;
238     QList<QTouchEvent::TouchPoint> m_touchPoints;
239     bool m_touchMocking;
240 
241     QString m_inputUrl;
242 };
243 
244 #endif
245