Changeset 64291 in webkit


Ignore:
Timestamp:
Jul 29, 2010 10:48:48 AM (14 years ago)
Author:
tonikitoo@webkit.org
Message:

2010-07-29 Antonio Gomes <tonikitoo@webkit.org>

Reviewed by Kenneth Christiansen.

[Qt] Factor out LauncherWindow class out of main.cpp (QtTestBrowser)
https://bugs.webkit.org/show_bug.cgi?id=43170

Moving LauncherWindow class out of main.cpp to its own .cpp and .h files:
launcherwindow.{cpp|h}

No behavior change.

Also changed all global static variables (named "gXXX") from main.cpp to
static public variables of the LauncherWindow class.

  • QtTestBrowser/QtTestBrowser.pro:
  • QtTestBrowser/launcherwindow.cpp: Added.
  • QtTestBrowser/launcherwindow.h: Added.
  • QtTestBrowser/main.cpp: (LauncherApplication::handleUserOptions): (main):
Location:
trunk/WebKitTools
Files:
1 added
3 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/WebKitTools/ChangeLog

    r64290 r64291  
     12010-07-29  Antonio Gomes  <tonikitoo@webkit.org>
     2
     3        Reviewed by Kenneth Christiansen.
     4
     5        [Qt] Factor out LauncherWindow class out of main.cpp (QtTestBrowser)
     6        https://bugs.webkit.org/show_bug.cgi?id=43170
     7
     8        Moving LauncherWindow class out of main.cpp to its own .cpp and .h files:
     9        launcherwindow.{cpp|h}
     10
     11        No behavior change.
     12
     13        Also changed all global static variables (named "gXXX") from main.cpp to
     14        static public variables of the LauncherWindow class.
     15
     16        * QtTestBrowser/QtTestBrowser.pro:
     17        * QtTestBrowser/launcherwindow.cpp: Added.
     18        * QtTestBrowser/launcherwindow.h: Added.
     19        * QtTestBrowser/main.cpp:
     20        (LauncherApplication::handleUserOptions):
     21        (main):
     22
    1232010-07-29  Martin Robinson  <mrobinson@igalia.com>
    224
  • trunk/WebKitTools/QtTestBrowser/QtTestBrowser.pro

    r62247 r64291  
    33SOURCES += \
    44    locationedit.cpp \
     5    launcherwindow.cpp \
    56    main.cpp \
    67    mainwindow.cpp \
     
    1314HEADERS += \
    1415    locationedit.h \
     16    launcherwindow.h \
    1517    mainwindow.h \
    1618    urlloader.h \
  • trunk/WebKitTools/QtTestBrowser/launcherwindow.cpp

    r64290 r64291  
    11/*
    2  * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
     2 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
    33 * Copyright (C) 2009 Girish Ramakrishnan <girish@forwardbias.in>
    44 * Copyright (C) 2006 George Staikos <staikos@kde.org>
     
    3131 */
    3232
    33 #include <QtGui>
    34 #include <QtNetwork/QNetworkRequest>
     33#include "launcherwindow.h"
     34
     35bool LauncherWindow::gUseGraphicsView = false;
     36bool LauncherWindow::gUseCompositing = true;
     37bool LauncherWindow::gCacheWebView = false;
     38bool LauncherWindow::gShowFrameRate = false;
     39bool LauncherWindow::gResizesToContents = false;
     40bool LauncherWindow::gUseTiledBackingStore = false;
     41QGraphicsView::ViewportUpdateMode LauncherWindow::gViewportUpdateMode = QGraphicsView::MinimalViewportUpdate;
     42QUrl LauncherWindow::gInspectorUrl;
     43
     44#if defined(Q_WS_MAEMO_5) || defined(Q_WS_S60)
     45bool LauncherWindow::gUseFrameFlattening = true;
     46#else
     47bool LauncherWindow::gUseFrameFlattening = false;
     48#endif
    3549
    3650#if defined(QT_CONFIGURED_WITH_OPENGL)
    37 #include <QtOpenGL/QGLWidget>
    38 #endif
    39 
    40 #if !defined(QT_NO_PRINTER)
    41 #include <QPrintPreviewDialog>
    42 #endif
    43 
    44 #ifndef QT_NO_UITOOLS
    45 #include <QtUiTools/QUiLoader>
    46 #endif
    47 
    48 #include <QDebug>
    49 
    50 #include <cstdio>
    51 #include <qevent.h>
    52 #include <qwebelement.h>
    53 #include <qwebframe.h>
    54 #include <qwebinspector.h>
    55 #include <qwebsettings.h>
    56 
    57 #ifdef Q_WS_MAEMO_5
    58 #include <qx11info_x11.h>
    59 #endif
    60 
    61 #include "mainwindow.h"
    62 #include "urlloader.h"
    63 #include "utils.h"
    64 #include "webinspector.h"
    65 #include "webpage.h"
    66 #include "webview.h"
    67 #include "../../WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.h"
    68 
    69 #ifdef Q_WS_MAEMO_5
    70 #include <X11/Xatom.h>
    71 #include <X11/Xlib.h>
    72 #undef KeyPress
    73 #endif
    74 
    75 static const int gExitClickArea = 80;
    76 static bool gUseGraphicsView = false;
    77 static bool gUseCompositing = true;
    78 static bool gCacheWebView = false;
    79 static bool gShowFrameRate = false;
    80 static QGraphicsView::ViewportUpdateMode gViewportUpdateMode = QGraphicsView::MinimalViewportUpdate;
    81 static QUrl gInspectorUrl;
    82 static bool gResizesToContents = false;
    83 static bool gUseTiledBackingStore = false;
    84 
    85 #if defined(Q_WS_MAEMO_5) || defined(Q_WS_S60)
    86 static bool gUseFrameFlattening = true;
    87 #else
    88 static bool gUseFrameFlattening = false;
    89 #endif
    90 
    91 #if defined(QT_CONFIGURED_WITH_OPENGL)
    92 static bool gUseQGLWidgetViewport = false;
    93 #endif
    94 
    95 class LauncherWindow : public MainWindow {
    96     Q_OBJECT
    97 
    98 public:
    99     LauncherWindow(LauncherWindow* other = 0, bool shareScene = false);
    100     virtual ~LauncherWindow();
    101 
    102     virtual void keyPressEvent(QKeyEvent* event);
    103     void grabZoomKeys(bool grab);
    104 
    105 #if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
    106     void sendTouchEvent();
    107 #endif
    108 
    109     bool eventFilter(QObject* obj, QEvent* event);
    110 
    111 protected slots:
    112     void loadStarted();
    113     void loadFinished();
    114 
    115     void showLinkHover(const QString &link, const QString &toolTip);
    116 
    117     void zoomIn();
    118     void zoomOut();
    119     void resetZoom();
    120     void toggleZoomTextOnly(bool on);
    121     void zoomAnimationFinished();
    122 
    123     void print();
    124     void screenshot();
    125 
    126     void setEditable(bool on);
    127 
    128     /* void dumpPlugins() */
    129     void dumpHtml();
    130 
    131     void selectElements();
    132 
    133     void setTouchMocking(bool on);
    134     void toggleAcceleratedCompositing(bool toggle);
    135     void toggleTiledBackingStore(bool toggle);
    136     void toggleResizesToContents(bool toggle);
    137 
    138     void toggleWebGL(bool toggle);
    139     void initializeView(bool useGraphicsView = false);
    140     void toggleSpatialNavigation(bool b);
    141     void toggleFullScreenMode(bool enable);
    142     void showFPS(bool enable);
    143     void changeViewportUpdateMode(int mode);
    144     void toggleFrameFlattening(bool toggle);
    145     void toggleInterruptingJavaScriptEnabled(bool enable);
    146     void toggleJavascriptCanOpenWindows(bool enable);
    147 
    148 #if defined(QT_CONFIGURED_WITH_OPENGL)
    149     void toggleQGLWidgetViewport(bool enable);
    150 #endif
    151 
    152     void showUserAgentDialog();
    153 
    154 public slots:
    155     LauncherWindow* newWindow();
    156     LauncherWindow* cloneWindow();
    157     void updateFPS(int fps);
    158 
    159 signals:
    160     void enteredFullScreenMode(bool on);
    161 
    162 private:
    163     void createChrome();
    164     void applyZoom();
    165 
    166 private:
    167     QVector<int> m_zoomLevels;
    168     int m_currentZoom;
    169 
    170     QWidget* m_view;
    171     WebInspector* m_inspector;
    172 
    173     QAction* m_formatMenuAction;
    174     QAction* m_flipAnimated;
    175     QAction* m_flipYAnimated;
    176 
    177 #if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
    178     QPropertyAnimation* m_zoomAnimation;
    179     QList<QTouchEvent::TouchPoint> m_touchPoints;
    180     bool m_touchMocking;
    181 #endif
    182 
    183     void init(bool useGraphicsView = false);
    184     bool isGraphicsBased() const;
    185     void applyPrefs(LauncherWindow* other = 0);
    186 };
     51bool LauncherWindow::gUseQGLWidgetViewport = false;
     52#endif
    18753
    18854LauncherWindow::LauncherWindow(LauncherWindow* other, bool shareScene)
     
    1010876}
    1011877
    1012 QWebPage* WebPage::createWindow(QWebPage::WebWindowType type)
    1013 {
    1014     LauncherWindow* mw = new LauncherWindow;
    1015     if (type == WebModalDialog)
    1016         mw->setWindowModality(Qt::ApplicationModal);
    1017     mw->show();
    1018     return mw->page();
    1019 }
    1020 
    1021 QObject* WebPage::createPlugin(const QString &classId, const QUrl&, const QStringList&, const QStringList&)
    1022 {
    1023     if (classId == "alien_QLabel") {
    1024         QLabel* l = new QLabel;
    1025         l->winId();
    1026         return l;
    1027     }
    1028 
    1029 #ifndef QT_NO_UITOOLS
    1030     QUiLoader loader;
    1031     return loader.createWidget(classId, view());
    1032 #else
    1033     Q_UNUSED(classId);
    1034     return 0;
    1035 #endif
    1036 }
    1037 
    1038 
    1039 int launcherMain(const QApplication& app)
    1040 {
    1041 #ifndef NDEBUG
    1042     int retVal = app.exec();
    1043     DumpRenderTreeSupportQt::garbageCollectorCollect();
    1044     QWebSettings::clearMemoryCaches();
    1045     return retVal;
    1046 #else
    1047     return app.exec();
    1048 #endif
    1049 }
    1050 
    1051 class LauncherApplication : public QApplication {
    1052     Q_OBJECT
    1053 
    1054 public:
    1055     LauncherApplication(int& argc, char** argv);
    1056     QStringList urls() const { return m_urls; }
    1057     bool isRobotized() const { return m_isRobotized; }
    1058 
    1059 private:
    1060     void handleUserOptions();
    1061     void applyDefaultSettings();
    1062 
    1063 private:
    1064     bool m_isRobotized;
    1065     QStringList m_urls;
    1066 };
    1067 
    1068 void LauncherApplication::applyDefaultSettings()
    1069 {
    1070     QWebSettings::setMaximumPagesInCache(4);
    1071 
    1072     QWebSettings::setObjectCacheCapacities((16*1024*1024) / 8, (16*1024*1024) / 8, 16*1024*1024);
    1073 
    1074     QWebSettings::globalSettings()->setAttribute(QWebSettings::PluginsEnabled, true);
    1075     QWebSettings::globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
    1076     QWebSettings::enablePersistentStorage();
    1077 }
    1078 
    1079 LauncherApplication::LauncherApplication(int& argc, char** argv)
    1080     : QApplication(argc, argv, QApplication::GuiServer)
    1081     , m_isRobotized(false)
    1082 {
    1083     // To allow QWebInspector's configuration persistence
    1084     setOrganizationName("Nokia");
    1085     setApplicationName("QtTestBrowser");
    1086     setApplicationVersion("0.1");
    1087 
    1088     applyDefaultSettings();
    1089 
    1090     handleUserOptions();
    1091 }
    1092 
    1093 static void requiresGraphicsView(const QString& option)
    1094 {
    1095     if (gUseGraphicsView)
    1096         return;
    1097     appQuit(1, QString("%1 only works in combination with the -graphicsbased option").arg(option));
    1098 }
    1099 
    1100 void LauncherApplication::handleUserOptions()
    1101 {
    1102     QStringList args = arguments();
    1103     QFileInfo program(args.at(0));
    1104     QString programName("QtTestBrowser");
    1105     if (program.exists())
    1106         programName = program.baseName();
    1107 
    1108     QList<QString> updateModes(enumToKeys(QGraphicsView::staticMetaObject,
    1109             "ViewportUpdateMode", "ViewportUpdate"));
    1110 
    1111     if (args.contains("-help")) {
    1112         qDebug() << "Usage:" << programName.toLatin1().data()
    1113              << "[-graphicsbased]"
    1114              << "[-no-compositing]"
    1115              << QString("[-viewport-update-mode %1]").arg(formatKeys(updateModes)).toLatin1().data()
    1116              << "[-cache-webview]"
    1117              << "[-show-fps]"
    1118              << "[-r list]"
    1119              << "[-inspector-url location]"
    1120              << "[-tiled-backing-store]"
    1121              << "[-resizes-to-contents]"
    1122              << "URLs";
    1123         appQuit(0);
    1124     }
    1125 
    1126     if (args.contains("-graphicsbased"))
    1127         gUseGraphicsView = true;
    1128 
    1129     if (args.contains("-no-compositing")) {
    1130         requiresGraphicsView("-no-compositing");
    1131         gUseCompositing = false;
    1132     }
    1133 
    1134     if (args.contains("-show-fps")) {
    1135         requiresGraphicsView("-show-fps");
    1136         gShowFrameRate = true;
    1137     }
    1138 
    1139     if (args.contains("-cache-webview")) {
    1140         requiresGraphicsView("-cache-webview");
    1141         gCacheWebView = true;
    1142     }
    1143 
    1144     if (args.contains("-tiled-backing-store")) {
    1145         requiresGraphicsView("-tiled-backing-store");
    1146         gUseTiledBackingStore = true;
    1147     }
    1148 
    1149     if (args.contains("-resizes-to-contents")) {
    1150         requiresGraphicsView("-resizes-to-contents");
    1151         gResizesToContents = true;
    1152     }
    1153 
    1154     QString arg1("-viewport-update-mode");
    1155     int modeIndex = args.indexOf(arg1);
    1156     if (modeIndex != -1) {
    1157         requiresGraphicsView(arg1);
    1158 
    1159         QString mode = takeOptionValue(&args, modeIndex);
    1160         if (mode.isEmpty())
    1161             appQuit(1, QString("%1 needs a value of one of [%2]").arg(arg1).arg(formatKeys(updateModes)));
    1162         int idx = updateModes.indexOf(mode);
    1163         if (idx == -1)
    1164             appQuit(1, QString("%1 value has to be one of [%2]").arg(arg1).arg(formatKeys(updateModes)));
    1165 
    1166         gViewportUpdateMode = static_cast<QGraphicsView::ViewportUpdateMode>(idx);
    1167     }
    1168 
    1169     QString inspectorUrlArg("-inspector-url");
    1170     int inspectorUrlIndex = args.indexOf(inspectorUrlArg);
    1171     if (inspectorUrlIndex != -1)
    1172        gInspectorUrl = takeOptionValue(&args, inspectorUrlIndex);
    1173 
    1174     int robotIndex = args.indexOf("-r");
    1175     if (robotIndex != -1) {
    1176         QString listFile = takeOptionValue(&args, robotIndex);
    1177         if (listFile.isEmpty())
    1178             appQuit(1, "-r needs a list file to start in robotized mode");
    1179         if (!QFile::exists(listFile))
    1180             appQuit(1, "The list file supplied to -r does not exist.");
    1181 
    1182         m_isRobotized = true;
    1183         m_urls = QStringList(listFile);
    1184         return;
    1185     }
    1186 
    1187     int lastArg = args.lastIndexOf(QRegExp("^-.*"));
    1188     m_urls = (lastArg != -1) ? args.mid(++lastArg) : args.mid(1);
    1189 }
    1190 
    1191 
    1192 int main(int argc, char **argv)
    1193 {
    1194     LauncherApplication app(argc, argv);
    1195 
    1196     if (app.isRobotized()) {
    1197         LauncherWindow* window = new LauncherWindow();
    1198         UrlLoader loader(window->page()->mainFrame(), app.urls().at(0));
    1199         QObject::connect(window->page()->mainFrame(), SIGNAL(loadFinished(bool)), &loader, SLOT(loadNext()));
    1200         loader.loadNext();
    1201         window->show();
    1202         return launcherMain(app);
    1203     }
    1204 
    1205     QStringList urls = app.urls();
    1206 
    1207     if (urls.isEmpty()) {
    1208         QString defaultUrl = QString("file://%1/%2").arg(QDir::homePath()).arg(QLatin1String("index.html"));
    1209         if (QDir(defaultUrl).exists())
    1210             urls.append(defaultUrl);
    1211         else
    1212             urls.append("");
    1213     }
    1214 
    1215     LauncherWindow* window = 0;
    1216     foreach (QString url, urls) {
    1217         LauncherWindow* newWindow;
    1218         if (!window)
    1219             newWindow = window = new LauncherWindow();
    1220         else
    1221             newWindow = window->newWindow();
    1222 
    1223         newWindow->load(url);
    1224     }
    1225 
    1226     window->show();
    1227     return launcherMain(app);
    1228 }
    1229 
    1230 #include "main.moc"
     878
  • trunk/WebKitTools/QtTestBrowser/main.cpp

    r64217 r64291  
    3131 */
    3232
    33 #include <QtGui>
    34 #include <QtNetwork/QNetworkRequest>
    35 
    36 #if defined(QT_CONFIGURED_WITH_OPENGL)
    37 #include <QtOpenGL/QGLWidget>
    38 #endif
    39 
    40 #if !defined(QT_NO_PRINTER)
    41 #include <QPrintPreviewDialog>
    42 #endif
    43 
    44 #ifndef QT_NO_UITOOLS
    45 #include <QtUiTools/QUiLoader>
    46 #endif
    47 
    48 #include <QDebug>
    49 
    50 #include <cstdio>
    51 #include <qevent.h>
    52 #include <qwebelement.h>
    53 #include <qwebframe.h>
    54 #include <qwebinspector.h>
    55 #include <qwebsettings.h>
    56 
    57 #ifdef Q_WS_MAEMO_5
    58 #include <qx11info_x11.h>
    59 #endif
    60 
    61 #include "mainwindow.h"
     33#include "launcherwindow.h"
    6234#include "urlloader.h"
    63 #include "utils.h"
    64 #include "webinspector.h"
    65 #include "webpage.h"
    66 #include "webview.h"
    67 #include "../../WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.h"
    68 
    69 #ifdef Q_WS_MAEMO_5
    70 #include <X11/Xatom.h>
    71 #include <X11/Xlib.h>
    72 #undef KeyPress
    73 #endif
    74 
    75 static const int gExitClickArea = 80;
    76 static bool gUseGraphicsView = false;
    77 static bool gUseCompositing = true;
    78 static bool gCacheWebView = false;
    79 static bool gShowFrameRate = false;
    80 static QGraphicsView::ViewportUpdateMode gViewportUpdateMode = QGraphicsView::MinimalViewportUpdate;
    81 static QUrl gInspectorUrl;
    82 static bool gResizesToContents = false;
    83 static bool gUseTiledBackingStore = false;
    84 
    85 #if defined(Q_WS_MAEMO_5) || defined(Q_WS_S60)
    86 static bool gUseFrameFlattening = true;
    87 #else
    88 static bool gUseFrameFlattening = false;
    89 #endif
    90 
    91 #if defined(QT_CONFIGURED_WITH_OPENGL)
    92 static bool gUseQGLWidgetViewport = false;
    93 #endif
    94 
    95 class LauncherWindow : public MainWindow {
    96     Q_OBJECT
    97 
    98 public:
    99     LauncherWindow(LauncherWindow* other = 0, bool shareScene = false);
    100     virtual ~LauncherWindow();
    101 
    102     virtual void keyPressEvent(QKeyEvent* event);
    103     void grabZoomKeys(bool grab);
    104 
    105 #if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
    106     void sendTouchEvent();
    107 #endif
    108 
    109     bool eventFilter(QObject* obj, QEvent* event);
    110 
    111 protected slots:
    112     void loadStarted();
    113     void loadFinished();
    114 
    115     void showLinkHover(const QString &link, const QString &toolTip);
    116 
    117     void zoomIn();
    118     void zoomOut();
    119     void resetZoom();
    120     void toggleZoomTextOnly(bool on);
    121     void zoomAnimationFinished();
    122 
    123     void print();
    124     void screenshot();
    125 
    126     void setEditable(bool on);
    127 
    128     /* void dumpPlugins() */
    129     void dumpHtml();
    130 
    131     void selectElements();
    132 
    133     void setTouchMocking(bool on);
    134     void toggleAcceleratedCompositing(bool toggle);
    135     void toggleTiledBackingStore(bool toggle);
    136     void toggleResizesToContents(bool toggle);
    137 
    138     void toggleWebGL(bool toggle);
    139     void initializeView(bool useGraphicsView = false);
    140     void toggleSpatialNavigation(bool b);
    141     void toggleFullScreenMode(bool enable);
    142     void showFPS(bool enable);
    143     void changeViewportUpdateMode(int mode);
    144     void toggleFrameFlattening(bool toggle);
    145     void toggleInterruptingJavaScriptEnabled(bool enable);
    146     void toggleJavascriptCanOpenWindows(bool enable);
    147 
    148 #if defined(QT_CONFIGURED_WITH_OPENGL)
    149     void toggleQGLWidgetViewport(bool enable);
    150 #endif
    151 
    152     void showUserAgentDialog();
    153 
    154 public slots:
    155     LauncherWindow* newWindow();
    156     LauncherWindow* cloneWindow();
    157     void updateFPS(int fps);
    158 
    159 signals:
    160     void enteredFullScreenMode(bool on);
    161 
    162 private:
    163     void createChrome();
    164     void applyZoom();
    165 
    166 private:
    167     QVector<int> m_zoomLevels;
    168     int m_currentZoom;
    169 
    170     QWidget* m_view;
    171     WebInspector* m_inspector;
    172 
    173     QAction* m_formatMenuAction;
    174     QAction* m_flipAnimated;
    175     QAction* m_flipYAnimated;
    176 
    177 #if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
    178     QPropertyAnimation* m_zoomAnimation;
    179     QList<QTouchEvent::TouchPoint> m_touchPoints;
    180     bool m_touchMocking;
    181 #endif
    182 
    183     void init(bool useGraphicsView = false);
    184     bool isGraphicsBased() const;
    185     void applyPrefs(LauncherWindow* other = 0);
    186 };
    187 
    188 LauncherWindow::LauncherWindow(LauncherWindow* other, bool shareScene)
    189     : MainWindow()
    190     , m_currentZoom(100)
    191     , m_view(0)
    192     , m_inspector(0)
    193     , m_formatMenuAction(0)
    194     , m_flipAnimated(0)
    195     , m_flipYAnimated(0)
    196 #if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
    197     , m_zoomAnimation(0)
    198 #endif
    199 {
    200     if (other) {
    201         init(other->isGraphicsBased());
    202         applyPrefs(other);
    203         if (shareScene && other->isGraphicsBased()) {
    204             QGraphicsView* otherView = static_cast<QGraphicsView*>(other->m_view);
    205             static_cast<QGraphicsView*>(m_view)->setScene(otherView->scene());
    206         }
    207     } else {
    208         init(gUseGraphicsView);
    209         applyPrefs();
    210     }
    211 
    212     createChrome();
    213 }
    214 
    215 LauncherWindow::~LauncherWindow()
    216 {
    217     grabZoomKeys(false);
    218 }
    219 
    220 void LauncherWindow::init(bool useGraphicsView)
    221 {
    222     QSplitter* splitter = new QSplitter(Qt::Vertical, this);
    223     setCentralWidget(splitter);
    224 
    225 #if defined(Q_WS_S60)
    226     setWindowState(Qt::WindowMaximized);
    227 #else
    228     setWindowState(Qt::WindowNoState);
    229     resize(800, 600);
    230 #endif
    231 
    232     initializeView(useGraphicsView);
    233 
    234     connect(page(), SIGNAL(loadStarted()), this, SLOT(loadStarted()));
    235     connect(page(), SIGNAL(loadFinished(bool)), this, SLOT(loadFinished()));
    236     connect(page(), SIGNAL(linkHovered(const QString&, const QString&, const QString&)),
    237             this, SLOT(showLinkHover(const QString&, const QString&)));
    238     connect(this, SIGNAL(enteredFullScreenMode(bool)), this, SLOT(toggleFullScreenMode(bool)));
    239 
    240     m_inspector = new WebInspector(splitter);
    241 #ifndef QT_NO_PROPERTIES
    242     if (!gInspectorUrl.isEmpty())
    243         m_inspector->setProperty("_q_inspectorUrl", gInspectorUrl);
    244 #endif
    245     m_inspector->setPage(page());
    246     m_inspector->hide();
    247     connect(this, SIGNAL(destroyed()), m_inspector, SLOT(deleteLater()));
    248 
    249     // the zoom values are chosen to be like in Mozilla Firefox 3
    250     m_zoomLevels << 30 << 50 << 67 << 80 << 90;
    251     m_zoomLevels << 100;
    252     m_zoomLevels << 110 << 120 << 133 << 150 << 170 << 200 << 240 << 300;
    253 
    254     grabZoomKeys(true);
    255 }
    256 
    257 bool LauncherWindow::isGraphicsBased() const
    258 {
    259     return bool(qobject_cast<QGraphicsView*>(m_view));
    260 }
    261 
    262 inline void applySetting(QWebSettings::WebAttribute type, QWebSettings* settings, QWebSettings* other, bool defaultValue)
    263 {
    264     settings->setAttribute(type, other ? other->testAttribute(type) : defaultValue);
    265 }
    266 
    267 void LauncherWindow::applyPrefs(LauncherWindow* source)
    268 {
    269     QWebSettings* other = source ? source->page()->settings() : 0;
    270     QWebSettings* settings = page()->settings();
    271 
    272     applySetting(QWebSettings::AcceleratedCompositingEnabled, settings, other, gUseCompositing);
    273     applySetting(QWebSettings::TiledBackingStoreEnabled, settings, other, gUseTiledBackingStore);
    274     applySetting(QWebSettings::WebGLEnabled, settings, other, false);
    275     applySetting(QWebSettings::FrameFlatteningEnabled, settings, other, gUseFrameFlattening);
    276 
    277     if (!isGraphicsBased())
    278         return;
    279 
    280     WebViewGraphicsBased* view = static_cast<WebViewGraphicsBased*>(m_view);
    281     WebViewGraphicsBased* otherView = source ? qobject_cast<WebViewGraphicsBased*>(source->m_view) : 0;
    282 
    283     view->setViewportUpdateMode(otherView ? otherView->viewportUpdateMode() : gViewportUpdateMode);
    284     view->setFrameRateMeasurementEnabled(otherView ? otherView->frameRateMeasurementEnabled() : gShowFrameRate);
    285 
    286     if (otherView)
    287         view->setItemCacheMode(otherView->itemCacheMode());
    288     else
    289         view->setItemCacheMode(gCacheWebView ? QGraphicsItem::DeviceCoordinateCache : QGraphicsItem::NoCache);
    290 }
    291 
    292 void LauncherWindow::keyPressEvent(QKeyEvent* event)
    293 {
    294 #ifdef Q_WS_MAEMO_5
    295     switch (event->key()) {
    296     case Qt::Key_F7:
    297         zoomIn();
    298         event->accept();
    299         break;
    300     case Qt::Key_F8:
    301         zoomOut();
    302         event->accept();
    303         break;
    304     }
    305 #endif
    306     MainWindow::keyPressEvent(event);
    307 }
    308 
    309 void LauncherWindow::grabZoomKeys(bool grab)
    310 {
    311 #ifdef Q_WS_MAEMO_5
    312     if (!winId()) {
    313         qWarning("Can't grab keys unless we have a window id");
    314         return;
    315     }
    316 
    317     Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
    318     if (!atom) {
    319         qWarning("Unable to obtain _HILDON_ZOOM_KEY_ATOM");
    320         return;
    321     }
    322 
    323     unsigned long val = (grab) ? 1 : 0;
    324     XChangeProperty(QX11Info::display(), winId(), atom, XA_INTEGER, 32, PropModeReplace, reinterpret_cast<unsigned char*>(&val), 1);
    325 #endif
    326 }
    327 
    328 #if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
    329 void LauncherWindow::sendTouchEvent()
    330 {
    331     if (m_touchPoints.isEmpty())
    332         return;
    333 
    334     QEvent::Type type = QEvent::TouchUpdate;
    335     if (m_touchPoints.size() == 1) {
    336         if (m_touchPoints[0].state() == Qt::TouchPointReleased)
    337             type = QEvent::TouchEnd;
    338         else if (m_touchPoints[0].state() == Qt::TouchPointPressed)
    339             type = QEvent::TouchBegin;
    340     }
    341 
    342     QTouchEvent touchEv(type);
    343     touchEv.setTouchPoints(m_touchPoints);
    344     QCoreApplication::sendEvent(page(), &touchEv);
    345 
    346     // After sending the event, remove all touchpoints that were released
    347     if (m_touchPoints[0].state() == Qt::TouchPointReleased)
    348         m_touchPoints.removeAt(0);
    349     if (m_touchPoints.size() > 1 && m_touchPoints[1].state() == Qt::TouchPointReleased)
    350         m_touchPoints.removeAt(1);
    351 }
    352 #endif // QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
    353 
    354 bool LauncherWindow::eventFilter(QObject* obj, QEvent* event)
    355 {
    356     // If click pos is the bottom right corner (square with size defined by gExitClickArea)
    357     // and the window is on FullScreen, the window must return to its original state.
    358     if (event->type() == QEvent::MouseButtonRelease) {
    359         QMouseEvent* ev = static_cast<QMouseEvent*>(event);
    360         if (windowState() == Qt::WindowFullScreen
    361             && ev->pos().x() > (width() - gExitClickArea)
    362             && ev->pos().y() > (height() - gExitClickArea)) {
    363 
    364             emit enteredFullScreenMode(false);
    365         }
    366     }
    367 
    368 #if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
    369     if (!m_touchMocking)
    370         return QObject::eventFilter(obj, event);
    371 
    372     if (event->type() == QEvent::MouseButtonPress
    373         || event->type() == QEvent::MouseButtonRelease
    374         || event->type() == QEvent::MouseButtonDblClick
    375         || event->type() == QEvent::MouseMove) {
    376 
    377         QMouseEvent* ev = static_cast<QMouseEvent*>(event);
    378         if (ev->type() == QEvent::MouseMove
    379             && !(ev->buttons() & Qt::LeftButton))
    380             return false;
    381 
    382         QTouchEvent::TouchPoint touchPoint;
    383         touchPoint.setState(Qt::TouchPointMoved);
    384         if ((ev->type() == QEvent::MouseButtonPress
    385              || ev->type() == QEvent::MouseButtonDblClick))
    386             touchPoint.setState(Qt::TouchPointPressed);
    387         else if (ev->type() == QEvent::MouseButtonRelease)
    388             touchPoint.setState(Qt::TouchPointReleased);
    389 
    390         touchPoint.setId(0);
    391         touchPoint.setScreenPos(ev->globalPos());
    392         touchPoint.setPos(ev->pos());
    393         touchPoint.setPressure(1);
    394 
    395         // If the point already exists, update it. Otherwise create it.
    396         if (m_touchPoints.size() > 0 && !m_touchPoints[0].id())
    397             m_touchPoints[0] = touchPoint;
    398         else if (m_touchPoints.size() > 1 && !m_touchPoints[1].id())
    399             m_touchPoints[1] = touchPoint;
    400         else
    401             m_touchPoints.append(touchPoint);
    402 
    403         sendTouchEvent();
    404     } else if (event->type() == QEvent::KeyPress
    405         && static_cast<QKeyEvent*>(event)->key() == Qt::Key_F
    406         && static_cast<QKeyEvent*>(event)->modifiers() == Qt::ControlModifier) {
    407 
    408         // If the keyboard point is already pressed, release it.
    409         // Otherwise create it and append to m_touchPoints.
    410         if (m_touchPoints.size() > 0 && m_touchPoints[0].id() == 1) {
    411             m_touchPoints[0].setState(Qt::TouchPointReleased);
    412             sendTouchEvent();
    413         } else if (m_touchPoints.size() > 1 && m_touchPoints[1].id() == 1) {
    414             m_touchPoints[1].setState(Qt::TouchPointReleased);
    415             sendTouchEvent();
    416         } else {
    417             QTouchEvent::TouchPoint touchPoint;
    418             touchPoint.setState(Qt::TouchPointPressed);
    419             touchPoint.setId(1);
    420             touchPoint.setScreenPos(QCursor::pos());
    421             touchPoint.setPos(m_view->mapFromGlobal(QCursor::pos()));
    422             touchPoint.setPressure(1);
    423             m_touchPoints.append(touchPoint);
    424             sendTouchEvent();
    425 
    426             // After sending the event, change the touchpoint state to stationary
    427             m_touchPoints.last().setState(Qt::TouchPointStationary);
    428         }
    429     }
    430 #endif // QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
    431 
    432     return false;
    433 }
    434 
    435 void LauncherWindow::loadStarted()
    436 {
    437     m_view->setFocus(Qt::OtherFocusReason);
    438 }
    439 
    440 void LauncherWindow::loadFinished()
    441 {
    442     QUrl url = page()->mainFrame()->url();
    443     setAddressUrl(url.toString(QUrl::RemoveUserInfo));
    444     addCompleterEntry(url);
    445 }
    446 
    447 void LauncherWindow::showLinkHover(const QString &link, const QString &toolTip)
    448 {
    449 #ifndef Q_WS_MAEMO_5
    450     statusBar()->showMessage(link);
    451 #endif
    452 #ifndef QT_NO_TOOLTIP
    453     if (!toolTip.isEmpty())
    454         QToolTip::showText(QCursor::pos(), toolTip);
    455 #endif
    456 }
    457 
    458 void LauncherWindow::zoomAnimationFinished()
    459 {
    460     if (!isGraphicsBased())
    461         return;
    462     QGraphicsWebView* view = static_cast<WebViewGraphicsBased*>(m_view)->graphicsWebView();
    463     view->setTiledBackingStoreFrozen(false);
    464 }
    465 
    466 void LauncherWindow::applyZoom()
    467 {
    468 #if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
    469     if (isGraphicsBased() && page()->settings()->testAttribute(QWebSettings::TiledBackingStoreEnabled)) {
    470         QGraphicsWebView* view = static_cast<WebViewGraphicsBased*>(m_view)->graphicsWebView();
    471         view->setTiledBackingStoreFrozen(true);
    472         if (!m_zoomAnimation) {
    473             m_zoomAnimation = new QPropertyAnimation(view, "scale");
    474             m_zoomAnimation->setStartValue(view->scale());
    475             connect(m_zoomAnimation, SIGNAL(finished()), this, SLOT(zoomAnimationFinished()));
    476         } else {
    477             m_zoomAnimation->stop();
    478             m_zoomAnimation->setStartValue(m_zoomAnimation->currentValue());
    479         }
    480 
    481         m_zoomAnimation->setDuration(300);
    482         m_zoomAnimation->setEndValue(qreal(m_currentZoom) / 100.);
    483         m_zoomAnimation->start();
    484         return;
    485     }
    486 #endif
    487     page()->mainFrame()->setZoomFactor(qreal(m_currentZoom) / 100.0);
    488 }
    489 
    490 void LauncherWindow::zoomIn()
    491 {
    492     int i = m_zoomLevels.indexOf(m_currentZoom);
    493     Q_ASSERT(i >= 0);
    494     if (i < m_zoomLevels.count() - 1)
    495         m_currentZoom = m_zoomLevels[i + 1];
    496 
    497     applyZoom();
    498 }
    499 
    500 void LauncherWindow::zoomOut()
    501 {
    502     int i = m_zoomLevels.indexOf(m_currentZoom);
    503     Q_ASSERT(i >= 0);
    504     if (i > 0)
    505         m_currentZoom = m_zoomLevels[i - 1];
    506 
    507     applyZoom();
    508 }
    509 
    510 void LauncherWindow::resetZoom()
    511 {
    512     m_currentZoom = 100;
    513     page()->mainFrame()->setZoomFactor(1.0);
    514 }
    515 
    516 void LauncherWindow::toggleZoomTextOnly(bool b)
    517 {
    518     page()->settings()->setAttribute(QWebSettings::ZoomTextOnly, b);
    519 }
    520 
    521 void LauncherWindow::print()
    522 {
    523 #if !defined(QT_NO_PRINTER)
    524     QPrintPreviewDialog dlg(this);
    525     connect(&dlg, SIGNAL(paintRequested(QPrinter*)),
    526             page()->mainFrame(), SLOT(print(QPrinter*)));
    527     dlg.exec();
    528 #endif
    529 }
    530 
    531 void LauncherWindow::screenshot()
    532 {
    533     QPixmap pixmap = QPixmap::grabWidget(m_view);
    534     QLabel* label = new QLabel;
    535     label->setAttribute(Qt::WA_DeleteOnClose);
    536     label->setWindowTitle("Screenshot - Preview");
    537     label->setPixmap(pixmap);
    538     label->show();
    539 
    540     QString fileName = QFileDialog::getSaveFileName(label, "Screenshot");
    541     if (!fileName.isEmpty()) {
    542         pixmap.save(fileName, "png");
    543         label->setWindowTitle(QString("Screenshot - Saved at %1").arg(fileName));
    544     }
    545 }
    546 
    547 void LauncherWindow::setEditable(bool on)
    548 {
    549     page()->setContentEditable(on);
    550     m_formatMenuAction->setVisible(on);
    551 }
    552 
    553 /*
    554 void LauncherWindow::dumpPlugins() {
    555     QList<QWebPluginInfo> plugins = QWebSettings::pluginDatabase()->plugins();
    556     foreach (const QWebPluginInfo plugin, plugins) {
    557         qDebug() << "Plugin:" << plugin.name();
    558         foreach (const QWebPluginInfo::MimeType mime, plugin.mimeTypes()) {
    559             qDebug() << "   " << mime.name;
    560         }
    561     }
    562 }
    563 */
    564 
    565 void LauncherWindow::dumpHtml()
    566 {
    567     qDebug() << "HTML: " << page()->mainFrame()->toHtml();
    568 }
    569 
    570 void LauncherWindow::selectElements()
    571 {
    572     bool ok;
    573     QString str = QInputDialog::getText(this, "Select elements", "Choose elements",
    574                                         QLineEdit::Normal, "a", &ok);
    575 
    576     if (ok && !str.isEmpty()) {
    577         QWebElementCollection result =  page()->mainFrame()->findAllElements(str);
    578         foreach (QWebElement e, result)
    579             e.setStyleProperty("background-color", "yellow");
    580 #ifndef Q_WS_MAEMO_5
    581         statusBar()->showMessage(QString("%1 element(s) selected").arg(result.count()), 5000);
    582 #endif
    583     }
    584 }
    585 
    586 void LauncherWindow::setTouchMocking(bool on)
    587 {
    588 #if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
    589     m_touchMocking = on;
    590 #endif
    591 }
    592 
    593 void LauncherWindow::toggleAcceleratedCompositing(bool toggle)
    594 {
    595     gUseCompositing = toggle;
    596     page()->settings()->setAttribute(QWebSettings::AcceleratedCompositingEnabled, toggle);
    597 }
    598 
    599 void LauncherWindow::toggleTiledBackingStore(bool toggle)
    600 {
    601     page()->settings()->setAttribute(QWebSettings::TiledBackingStoreEnabled, toggle);
    602 }
    603 
    604 void LauncherWindow::toggleResizesToContents(bool toggle)
    605 {
    606     static_cast<WebViewGraphicsBased*>(m_view)->setResizesToContents(toggle);
    607 }
    608 
    609 void LauncherWindow::toggleWebGL(bool toggle)
    610 {
    611     page()->settings()->setAttribute(QWebSettings::WebGLEnabled, toggle);
    612 }
    613 
    614 void LauncherWindow::initializeView(bool useGraphicsView)
    615 {
    616     delete m_view;
    617 
    618     QSplitter* splitter = static_cast<QSplitter*>(centralWidget());
    619 
    620     if (!useGraphicsView) {
    621         WebViewTraditional* view = new WebViewTraditional(splitter);
    622         view->setPage(page());
    623 
    624         view->installEventFilter(this);
    625 
    626         m_view = view;
    627     } else {
    628         WebViewGraphicsBased* view = new WebViewGraphicsBased(splitter);
    629         view->setPage(page());
    630 
    631         if (m_flipAnimated)
    632             connect(m_flipAnimated, SIGNAL(triggered()), view, SLOT(animatedFlip()));
    633 
    634         if (m_flipYAnimated)
    635             connect(m_flipYAnimated, SIGNAL(triggered()), view, SLOT(animatedYFlip()));
    636 
    637         connect(view, SIGNAL(currentFPSUpdated(int)), this, SLOT(updateFPS(int)));
    638 
    639         view->installEventFilter(this);
    640         // The implementation of QAbstractScrollArea::eventFilter makes us need
    641         // to install the event filter also on the viewport of a QGraphicsView.
    642         view->viewport()->installEventFilter(this);
    643 
    644         m_view = view;
    645     }
    646 
    647 #if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
    648     m_touchMocking = false;
    649 #endif
    650 }
    651 
    652 void LauncherWindow::toggleSpatialNavigation(bool b)
    653 {
    654     page()->settings()->setAttribute(QWebSettings::SpatialNavigationEnabled, b);
    655 }
    656 
    657 void LauncherWindow::toggleFullScreenMode(bool enable)
    658 {
    659     if (enable)
    660         setWindowState(Qt::WindowFullScreen);
    661     else {
    662 #if defined(Q_WS_S60)
    663         setWindowState(Qt::WindowMaximized);
    664 #else
    665         setWindowState(Qt::WindowNoState);
    666 #endif
    667     }
    668 }
    669 
    670 void LauncherWindow::showFPS(bool enable)
    671 {
    672     if (!isGraphicsBased())
    673         return;
    674 
    675     gShowFrameRate = enable;
    676     WebViewGraphicsBased* view = static_cast<WebViewGraphicsBased*>(m_view);
    677     view->setFrameRateMeasurementEnabled(enable);
    678 
    679     if (!enable) {
    680 #if defined(Q_WS_MAEMO_5) && defined(Q_WS_S60)
    681         setWindowTitle("");
    682 #else
    683         statusBar()->clearMessage();
    684 #endif
    685     }
    686 }
    687 
    688 void LauncherWindow::changeViewportUpdateMode(int mode)
    689 {
    690     gViewportUpdateMode = QGraphicsView::ViewportUpdateMode(mode);
    691 
    692     if (!isGraphicsBased())
    693         return;
    694 
    695     WebViewGraphicsBased* view = static_cast<WebViewGraphicsBased*>(m_view);
    696     view->setViewportUpdateMode(gViewportUpdateMode);
    697 }
    698 
    699 void LauncherWindow::toggleFrameFlattening(bool toggle)
    700 {
    701     gUseFrameFlattening = toggle;
    702     page()->settings()->setAttribute(QWebSettings::FrameFlatteningEnabled, toggle);
    703 }
    704 
    705 void LauncherWindow::toggleInterruptingJavaScriptEnabled(bool enable)
    706 {
    707     page()->setInterruptingJavaScriptEnabled(enable);
    708 }
    709 
    710 void LauncherWindow::toggleJavascriptCanOpenWindows(bool enable)
    711 {
    712     page()->settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, enable);
    713 }
    714 
    715 #if defined(QT_CONFIGURED_WITH_OPENGL)
    716 void LauncherWindow::toggleQGLWidgetViewport(bool enable)
    717 {
    718     if (!isGraphicsBased())
    719         return;
    720 
    721     gUseQGLWidgetViewport = enable;
    722     WebViewGraphicsBased* view = static_cast<WebViewGraphicsBased*>(m_view);
    723 
    724     view->setViewport(enable ? new QGLWidget() : 0);
    725 }
    726 #endif
    727 
    728 void LauncherWindow::showUserAgentDialog()
    729 {
    730     QStringList items;
    731     QFile file(":/useragentlist.txt");
    732     if (file.open(QIODevice::ReadOnly)) {
    733          while (!file.atEnd())
    734             items << file.readLine().trimmed();
    735         file.close();
    736     }
    737 
    738     QSettings settings;
    739     QString customUserAgent = settings.value("CustomUserAgent").toString();
    740     if (!items.contains(customUserAgent) && !customUserAgent.isEmpty())
    741         items << customUserAgent;
    742 
    743     QDialog* dialog = new QDialog(this);
    744     dialog->resize(size().width() * 0.7, dialog->size().height());
    745     dialog->setMaximumHeight(dialog->size().height());
    746     dialog->setWindowTitle("Change User Agent");
    747 
    748     QVBoxLayout* layout = new QVBoxLayout(dialog);
    749     dialog->setLayout(layout);
    750 
    751     QComboBox* combo = new QComboBox(dialog);
    752     combo->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength);
    753     combo->setEditable(true);
    754     combo->insertItems(0, items);
    755     layout->addWidget(combo);
    756 
    757     int index = combo->findText(page()->userAgentForUrl(QUrl()));
    758     combo->setCurrentIndex(index);
    759 
    760     QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
    761             | QDialogButtonBox::Cancel, Qt::Horizontal, dialog);
    762     connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept()));
    763     connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject()));
    764     layout->addWidget(buttonBox);
    765 
    766     if (dialog->exec() && !combo->currentText().isEmpty()) {
    767         page()->setUserAgent(combo->currentText());
    768         if (!items.contains(combo->currentText()))
    769             settings.setValue("CustomUserAgent", combo->currentText());
    770     }
    771 
    772     delete dialog;
    773 }
    774 
    775 LauncherWindow* LauncherWindow::newWindow()
    776 {
    777     LauncherWindow* mw = new LauncherWindow(this, false);
    778     mw->show();
    779     return mw;
    780 }
    781 
    782 LauncherWindow* LauncherWindow::cloneWindow()
    783 {
    784     LauncherWindow* mw = new LauncherWindow(this, true);
    785     mw->show();
    786     return mw;
    787 }
    788 
    789 void LauncherWindow::updateFPS(int fps)
    790 {
    791     QString fpsStatusText = QString("Current FPS: %1").arg(fps);
    792 
    793 #if defined(Q_WS_MAEMO_5) && defined(Q_WS_S60)
    794     setWindowTitle(fpsStatusText);
    795 #else
    796     statusBar()->showMessage(fpsStatusText);
    797 #endif
    798 }
    799 
    800 void LauncherWindow::createChrome()
    801 {
    802     QMenu* fileMenu = menuBar()->addMenu("&File");
    803     fileMenu->addAction("New Window", this, SLOT(newWindow()), QKeySequence::New);
    804     fileMenu->addAction(tr("Open File..."), this, SLOT(openFile()), QKeySequence::Open);
    805     fileMenu->addAction(tr("Open Location..."), this, SLOT(openLocation()), QKeySequence(Qt::CTRL | Qt::Key_L));
    806     fileMenu->addAction("Close Window", this, SLOT(close()), QKeySequence::Close);
    807     fileMenu->addSeparator();
    808     fileMenu->addAction("Take Screen Shot...", this, SLOT(screenshot()));
    809     fileMenu->addAction(tr("Print..."), this, SLOT(print()), QKeySequence::Print);
    810     fileMenu->addSeparator();
    811     fileMenu->addAction("Quit", QApplication::instance(), SLOT(closeAllWindows()), QKeySequence(Qt::CTRL | Qt::Key_Q));
    812 
    813     QMenu* editMenu = menuBar()->addMenu("&Edit");
    814     editMenu->addAction(page()->action(QWebPage::Undo));
    815     editMenu->addAction(page()->action(QWebPage::Redo));
    816     editMenu->addSeparator();
    817     editMenu->addAction(page()->action(QWebPage::Cut));
    818     editMenu->addAction(page()->action(QWebPage::Copy));
    819     editMenu->addAction(page()->action(QWebPage::Paste));
    820     editMenu->addSeparator();
    821     QAction* setEditable = editMenu->addAction("Set Editable", this, SLOT(setEditable(bool)));
    822     setEditable->setCheckable(true);
    823 
    824     QMenu* viewMenu = menuBar()->addMenu("&View");
    825     viewMenu->addAction(page()->action(QWebPage::Stop));
    826     viewMenu->addAction(page()->action(QWebPage::Reload));
    827     viewMenu->addSeparator();
    828     QAction* zoomIn = viewMenu->addAction("Zoom &In", this, SLOT(zoomIn()));
    829     QAction* zoomOut = viewMenu->addAction("Zoom &Out", this, SLOT(zoomOut()));
    830     QAction* resetZoom = viewMenu->addAction("Reset Zoom", this, SLOT(resetZoom()));
    831     QAction* zoomTextOnly = viewMenu->addAction("Zoom Text Only", this, SLOT(toggleZoomTextOnly(bool)));
    832     zoomTextOnly->setCheckable(true);
    833     zoomTextOnly->setChecked(false);
    834     viewMenu->addSeparator();
    835     viewMenu->addAction("Dump HTML", this, SLOT(dumpHtml()));
    836     // viewMenu->addAction("Dump plugins", this, SLOT(dumpPlugins()));
    837 
    838     QMenu* formatMenu = new QMenu("F&ormat", this);
    839     m_formatMenuAction = menuBar()->addMenu(formatMenu);
    840     m_formatMenuAction->setVisible(false);
    841     formatMenu->addAction(page()->action(QWebPage::ToggleBold));
    842     formatMenu->addAction(page()->action(QWebPage::ToggleItalic));
    843     formatMenu->addAction(page()->action(QWebPage::ToggleUnderline));
    844     QMenu* writingMenu = formatMenu->addMenu(tr("Writing Direction"));
    845     writingMenu->addAction(page()->action(QWebPage::SetTextDirectionDefault));
    846     writingMenu->addAction(page()->action(QWebPage::SetTextDirectionLeftToRight));
    847     writingMenu->addAction(page()->action(QWebPage::SetTextDirectionRightToLeft));
    848 
    849     zoomIn->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Plus));
    850     zoomOut->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Minus));
    851     resetZoom->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_0));
    852 
    853     QMenu* windowMenu = menuBar()->addMenu("&Window");
    854     QAction* toggleFullScreen = windowMenu->addAction("Toggle FullScreen", this, SIGNAL(enteredFullScreenMode(bool)));
    855     toggleFullScreen->setCheckable(true);
    856     toggleFullScreen->setChecked(false);
    857 
    858     // when exit fullscreen mode by clicking on the exit area (bottom right corner) we must
    859     // uncheck the Toggle FullScreen action
    860     toggleFullScreen->connect(this, SIGNAL(enteredFullScreenMode(bool)), SLOT(setChecked(bool)));
    861 
    862     QMenu* toolsMenu = menuBar()->addMenu("&Develop");
    863 
    864     QWebSettings* settings = page()->settings();
    865 
    866     QMenu* graphicsViewMenu = toolsMenu->addMenu("QGraphicsView");
    867     QAction* toggleGraphicsView = graphicsViewMenu->addAction("Toggle use of QGraphicsView", this, SLOT(initializeView(bool)));
    868     toggleGraphicsView->setCheckable(true);
    869     toggleGraphicsView->setChecked(isGraphicsBased());
    870 
    871     QAction* toggleWebGL = toolsMenu->addAction("Toggle WebGL", this, SLOT(toggleWebGL(bool)));
    872     toggleWebGL->setCheckable(true);
    873     toggleWebGL->setChecked(settings->testAttribute(QWebSettings::WebGLEnabled));
    874 
    875     QAction* spatialNavigationAction = toolsMenu->addAction("Toggle Spatial Navigation", this, SLOT(toggleSpatialNavigation(bool)));
    876     spatialNavigationAction->setCheckable(true);
    877     spatialNavigationAction->setShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_S));
    878 
    879     QAction* toggleFrameFlattening = toolsMenu->addAction("Toggle Frame Flattening", this, SLOT(toggleFrameFlattening(bool)));
    880     toggleFrameFlattening->setCheckable(true);
    881     toggleFrameFlattening->setChecked(settings->testAttribute(QWebSettings::FrameFlatteningEnabled));
    882 
    883 #if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
    884     QAction* touchMockAction = toolsMenu->addAction("Toggle multitouch mocking", this, SLOT(setTouchMocking(bool)));
    885     touchMockAction->setCheckable(true);
    886     touchMockAction->setShortcut(QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_T));
    887 #endif
    888 
    889     toolsMenu->addSeparator();
    890 
    891     QAction* toggleInterruptingJavaScripteEnabled = toolsMenu->addAction("Enable interrupting js scripts", this, SLOT(toggleInterruptingJavaScriptEnabled(bool)));
    892     toggleInterruptingJavaScripteEnabled->setCheckable(true);
    893     toggleInterruptingJavaScripteEnabled->setChecked(false);
    894 
    895     QAction* toggleJavascriptCanOpenWindows = toolsMenu->addAction("Enable js popup windows", this, SLOT(toggleJavascriptCanOpenWindows(bool)));
    896     toggleJavascriptCanOpenWindows->setCheckable(true);
    897     toggleJavascriptCanOpenWindows->setChecked(false);
    898 
    899     toolsMenu->addSeparator();
    900 
    901     QAction* userAgentAction = toolsMenu->addAction("Change User Agent", this, SLOT(showUserAgentDialog()));
    902     userAgentAction->setShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_U));
    903 
    904     toolsMenu->addAction("Select Elements...", this, SLOT(selectElements()));
    905 
    906     QAction* showInspectorAction = toolsMenu->addAction("Show Web Inspector", m_inspector, SLOT(setVisible(bool)), QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_I));
    907     showInspectorAction->setCheckable(true);
    908     showInspectorAction->connect(m_inspector, SIGNAL(visibleChanged(bool)), SLOT(setChecked(bool)));
    909 
    910     // GraphicsView sub menu.
    911     QAction* toggleAcceleratedCompositing = graphicsViewMenu->addAction("Toggle Accelerated Compositing", this, SLOT(toggleAcceleratedCompositing(bool)));
    912     toggleAcceleratedCompositing->setCheckable(true);
    913     toggleAcceleratedCompositing->setChecked(settings->testAttribute(QWebSettings::AcceleratedCompositingEnabled));
    914     toggleAcceleratedCompositing->setEnabled(isGraphicsBased());
    915     toggleAcceleratedCompositing->connect(toggleGraphicsView, SIGNAL(toggled(bool)), SLOT(setEnabled(bool)));
    916 
    917     QAction* toggleResizesToContents = graphicsViewMenu->addAction("Toggle Resizes To Contents Mode", this, SLOT(toggleResizesToContents(bool)));
    918     toggleResizesToContents->setCheckable(true);
    919     toggleResizesToContents->setChecked(false);
    920     toggleResizesToContents->setEnabled(isGraphicsBased());
    921     toggleResizesToContents->connect(toggleGraphicsView, SIGNAL(toggled(bool)), SLOT(setEnabled(bool)));
    922 
    923     QAction* toggleTiledBackingStore = graphicsViewMenu->addAction("Toggle Tiled Backing Store", this, SLOT(toggleTiledBackingStore(bool)));
    924     toggleTiledBackingStore->setCheckable(true);
    925     toggleTiledBackingStore->setChecked(false);
    926     toggleTiledBackingStore->setEnabled(isGraphicsBased());
    927     toggleTiledBackingStore->connect(toggleGraphicsView, SIGNAL(toggled(bool)), SLOT(setEnabled(bool)));
    928 
    929 #if defined(QT_CONFIGURED_WITH_OPENGL)
    930     QAction* toggleQGLWidgetViewport = graphicsViewMenu->addAction("Toggle use of QGLWidget Viewport", this, SLOT(toggleQGLWidgetViewport(bool)));
    931     toggleQGLWidgetViewport->setCheckable(true);
    932     toggleQGLWidgetViewport->setChecked(gUseQGLWidgetViewport);
    933     toggleQGLWidgetViewport->setEnabled(isGraphicsBased());
    934     toggleQGLWidgetViewport->connect(toggleGraphicsView, SIGNAL(toggled(bool)), SLOT(setEnabled(bool)));
    935 #endif
    936 
    937     QMenu* viewportUpdateMenu = graphicsViewMenu->addMenu("Change Viewport Update Mode");
    938     viewportUpdateMenu->setEnabled(isGraphicsBased());
    939     viewportUpdateMenu->connect(toggleGraphicsView, SIGNAL(toggled(bool)), SLOT(setEnabled(bool)));
    940 
    941     QAction* fullUpdate = viewportUpdateMenu->addAction("FullViewportUpdate");
    942     fullUpdate->setCheckable(true);
    943     fullUpdate->setChecked((gViewportUpdateMode == QGraphicsView::FullViewportUpdate) ? true : false);
    944 
    945     QAction* minimalUpdate = viewportUpdateMenu->addAction("MinimalViewportUpdate");
    946     minimalUpdate->setCheckable(true);
    947     minimalUpdate->setChecked((gViewportUpdateMode == QGraphicsView::MinimalViewportUpdate) ? true : false);
    948 
    949     QAction* smartUpdate = viewportUpdateMenu->addAction("SmartViewportUpdate");
    950     smartUpdate->setCheckable(true);
    951     smartUpdate->setChecked((gViewportUpdateMode == QGraphicsView::SmartViewportUpdate) ? true : false);
    952 
    953     QAction* boundingRectUpdate = viewportUpdateMenu->addAction("BoundingRectViewportUpdate");
    954     boundingRectUpdate->setCheckable(true);
    955     boundingRectUpdate->setChecked((gViewportUpdateMode == QGraphicsView::BoundingRectViewportUpdate) ? true : false);
    956 
    957     QAction* noUpdate = viewportUpdateMenu->addAction("NoViewportUpdate");
    958     noUpdate->setCheckable(true);
    959     noUpdate->setChecked((gViewportUpdateMode == QGraphicsView::NoViewportUpdate) ? true : false);
    960 
    961     QSignalMapper* signalMapper = new QSignalMapper(viewportUpdateMenu);
    962     signalMapper->setMapping(fullUpdate, QGraphicsView::FullViewportUpdate);
    963     signalMapper->setMapping(minimalUpdate, QGraphicsView::MinimalViewportUpdate);
    964     signalMapper->setMapping(smartUpdate, QGraphicsView::SmartViewportUpdate);
    965     signalMapper->setMapping(boundingRectUpdate, QGraphicsView::BoundingRectViewportUpdate);
    966     signalMapper->setMapping(noUpdate, QGraphicsView::NoViewportUpdate);
    967 
    968     connect(fullUpdate, SIGNAL(triggered()), signalMapper, SLOT(map()));
    969     connect(minimalUpdate, SIGNAL(triggered()), signalMapper, SLOT(map()));
    970     connect(smartUpdate, SIGNAL(triggered()), signalMapper, SLOT(map()));
    971     connect(boundingRectUpdate, SIGNAL(triggered()), signalMapper, SLOT(map()));
    972     connect(noUpdate, SIGNAL(triggered()), signalMapper, SLOT(map()));
    973 
    974     connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(changeViewportUpdateMode(int)));
    975 
    976     QActionGroup* viewportUpdateModeActions = new QActionGroup(viewportUpdateMenu);
    977     viewportUpdateModeActions->addAction(fullUpdate);
    978     viewportUpdateModeActions->addAction(minimalUpdate);
    979     viewportUpdateModeActions->addAction(smartUpdate);
    980     viewportUpdateModeActions->addAction(boundingRectUpdate);
    981     viewportUpdateModeActions->addAction(noUpdate);
    982 
    983     graphicsViewMenu->addSeparator();
    984 
    985     m_flipAnimated = graphicsViewMenu->addAction("Animated Flip");
    986     m_flipAnimated->connect(toggleGraphicsView, SIGNAL(toggled(bool)), SLOT(setEnabled(bool)));
    987     m_flipAnimated->setEnabled(isGraphicsBased());
    988 
    989     m_flipYAnimated = graphicsViewMenu->addAction("Animated Y-Flip");
    990     m_flipYAnimated->connect(toggleGraphicsView, SIGNAL(toggled(bool)), SLOT(setEnabled(bool)));
    991     m_flipYAnimated->setEnabled(isGraphicsBased());
    992 
    993     if (isGraphicsBased()) {
    994         WebViewGraphicsBased* view = static_cast<WebViewGraphicsBased*>(m_view);
    995         connect(m_flipAnimated, SIGNAL(triggered()), view, SLOT(animatedFlip()));
    996         connect(m_flipYAnimated, SIGNAL(triggered()), view, SLOT(animatedYFlip()));
    997     }
    998 
    999     QAction* cloneWindow = graphicsViewMenu->addAction("Clone Window", this, SLOT(cloneWindow()));
    1000     cloneWindow->connect(toggleGraphicsView, SIGNAL(toggled(bool)), SLOT(setEnabled(bool)));
    1001     cloneWindow->setEnabled(isGraphicsBased());
    1002 
    1003     graphicsViewMenu->addSeparator();
    1004 
    1005     QAction* showFPS = graphicsViewMenu->addAction("Show FPS", this, SLOT(showFPS(bool)));
    1006     showFPS->setCheckable(true);
    1007     showFPS->setEnabled(isGraphicsBased());
    1008     showFPS->connect(toggleGraphicsView, SIGNAL(toggled(bool)), SLOT(setEnabled(bool)));
    1009     showFPS->setChecked(gShowFrameRate);
    1010 }
    101135
    101236QWebPage* WebPage::createWindow(QWebPage::WebWindowType type)
     
    103559#endif
    103660}
    1037 
    103861
    103962int launcherMain(const QApplication& app)
     
    1093116static void requiresGraphicsView(const QString& option)
    1094117{
    1095     if (gUseGraphicsView)
     118    if (LauncherWindow::gUseGraphicsView)
    1096119        return;
    1097120    appQuit(1, QString("%1 only works in combination with the -graphicsbased option").arg(option));
     
    1125148
    1126149    if (args.contains("-graphicsbased"))
    1127         gUseGraphicsView = true;
     150        LauncherWindow::gUseGraphicsView = true;
    1128151
    1129152    if (args.contains("-no-compositing")) {
    1130153        requiresGraphicsView("-no-compositing");
    1131         gUseCompositing = false;
     154        LauncherWindow::gUseCompositing = false;
    1132155    }
    1133156
    1134157    if (args.contains("-show-fps")) {
    1135158        requiresGraphicsView("-show-fps");
    1136         gShowFrameRate = true;
     159        LauncherWindow::gShowFrameRate = true;
    1137160    }
    1138161
    1139162    if (args.contains("-cache-webview")) {
    1140163        requiresGraphicsView("-cache-webview");
    1141         gCacheWebView = true;
     164        LauncherWindow::gCacheWebView = true;
    1142165    }
    1143166
    1144167    if (args.contains("-tiled-backing-store")) {
    1145168        requiresGraphicsView("-tiled-backing-store");
    1146         gUseTiledBackingStore = true;
     169        LauncherWindow::gUseTiledBackingStore = true;
    1147170    }
    1148171
    1149172    if (args.contains("-resizes-to-contents")) {
    1150173        requiresGraphicsView("-resizes-to-contents");
    1151         gResizesToContents = true;
     174        LauncherWindow::gResizesToContents = true;
    1152175    }
    1153176
     
    1164187            appQuit(1, QString("%1 value has to be one of [%2]").arg(arg1).arg(formatKeys(updateModes)));
    1165188
    1166         gViewportUpdateMode = static_cast<QGraphicsView::ViewportUpdateMode>(idx);
     189        LauncherWindow::gViewportUpdateMode = static_cast<QGraphicsView::ViewportUpdateMode>(idx);
    1167190    }
    1168191
     
    1170193    int inspectorUrlIndex = args.indexOf(inspectorUrlArg);
    1171194    if (inspectorUrlIndex != -1)
    1172        gInspectorUrl = takeOptionValue(&args, inspectorUrlIndex);
     195       LauncherWindow::gInspectorUrl = takeOptionValue(&args, inspectorUrlIndex);
    1173196
    1174197    int robotIndex = args.indexOf("-r");
Note: See TracChangeset for help on using the changeset viewer.