diff options
author | Kristian Monsen <kristianm@google.com> | 2010-05-21 16:53:46 +0100 |
---|---|---|
committer | Kristian Monsen <kristianm@google.com> | 2010-05-25 10:24:15 +0100 |
commit | 6c2af9490927c3c5959b5cb07461b646f8b32f6c (patch) | |
tree | f7111b9b22befab472616c1d50ec94eb50f1ec8c /WebKitTools/QtLauncher | |
parent | a149172322a9067c14e8b474a53e63649aa17cad (diff) | |
download | external_webkit-6c2af9490927c3c5959b5cb07461b646f8b32f6c.zip external_webkit-6c2af9490927c3c5959b5cb07461b646f8b32f6c.tar.gz external_webkit-6c2af9490927c3c5959b5cb07461b646f8b32f6c.tar.bz2 |
Merge WebKit at r59636: Initial merge by git
Change-Id: I59b289c4e6b18425f06ce41cc9d34c522515de91
Diffstat (limited to 'WebKitTools/QtLauncher')
-rw-r--r-- | WebKitTools/QtLauncher/QtLauncher.pro | 58 | ||||
-rw-r--r-- | WebKitTools/QtLauncher/QtLauncher.qrc | 5 | ||||
-rw-r--r-- | WebKitTools/QtLauncher/fpstimer.cpp | 77 | ||||
-rw-r--r-- | WebKitTools/QtLauncher/fpstimer.h | 54 | ||||
-rw-r--r-- | WebKitTools/QtLauncher/locationedit.cpp | 80 | ||||
-rw-r--r-- | WebKitTools/QtLauncher/locationedit.h | 54 | ||||
-rw-r--r-- | WebKitTools/QtLauncher/main.cpp | 1209 | ||||
-rw-r--r-- | WebKitTools/QtLauncher/mainwindow.cpp | 163 | ||||
-rw-r--r-- | WebKitTools/QtLauncher/mainwindow.h | 70 | ||||
-rw-r--r-- | WebKitTools/QtLauncher/urlloader.cpp | 83 | ||||
-rw-r--r-- | WebKitTools/QtLauncher/urlloader.h | 58 | ||||
-rw-r--r-- | WebKitTools/QtLauncher/useragentlist.txt | 9 | ||||
-rw-r--r-- | WebKitTools/QtLauncher/utils.cpp | 92 | ||||
-rw-r--r-- | WebKitTools/QtLauncher/utils.h | 52 | ||||
-rw-r--r-- | WebKitTools/QtLauncher/webinspector.h | 56 | ||||
-rw-r--r-- | WebKitTools/QtLauncher/webpage.cpp | 120 | ||||
-rw-r--r-- | WebKitTools/QtLauncher/webpage.h | 66 | ||||
-rw-r--r-- | WebKitTools/QtLauncher/webview.cpp | 205 | ||||
-rw-r--r-- | WebKitTools/QtLauncher/webview.h | 126 |
19 files changed, 0 insertions, 2637 deletions
diff --git a/WebKitTools/QtLauncher/QtLauncher.pro b/WebKitTools/QtLauncher/QtLauncher.pro deleted file mode 100644 index a91cee9..0000000 --- a/WebKitTools/QtLauncher/QtLauncher.pro +++ /dev/null @@ -1,58 +0,0 @@ -TEMPLATE = app - -SOURCES += \ - locationedit.cpp \ - main.cpp \ - mainwindow.cpp \ - urlloader.cpp \ - utils.cpp \ - webpage.cpp \ - webview.cpp \ - fpstimer.cpp \ - -HEADERS += \ - locationedit.h \ - mainwindow.h \ - urlloader.h \ - utils.h \ - webinspector.h \ - webpage.h \ - webview.h \ - fpstimer.h \ - -CONFIG -= app_bundle -CONFIG += uitools - -isEmpty(OUTPUT_DIR): OUTPUT_DIR = ../.. -include(../../WebKit.pri) - -DESTDIR = $$OUTPUT_DIR/bin - -QT += network -macx:QT+=xml - -linux-* { - # From Creator's src/rpath.pri: - # Do the rpath by hand since it's not possible to use ORIGIN in QMAKE_RPATHDIR - # this expands to $ORIGIN (after qmake and make), it does NOT read a qmake var. - QMAKE_RPATHDIR = \$\$ORIGIN/../lib $$QMAKE_RPATHDIR - MY_RPATH = $$join(QMAKE_RPATHDIR, ":") - - QMAKE_LFLAGS += -Wl,-z,origin \'-Wl,-rpath,$${MY_RPATH}\' - QMAKE_RPATHDIR = -} else { - QMAKE_RPATHDIR = $$OUTPUT_DIR/lib $$QMAKE_RPATHDIR -} - -symbian { - TARGET.UID3 = 0xA000E543 - TARGET.CAPABILITY = ReadUserData WriteUserData NetworkServices -} - -contains(QT_CONFIG, opengl) { - QT += opengl - DEFINES += QT_CONFIGURED_WITH_OPENGL -} - -RESOURCES += \ - QtLauncher.qrc diff --git a/WebKitTools/QtLauncher/QtLauncher.qrc b/WebKitTools/QtLauncher/QtLauncher.qrc deleted file mode 100644 index ffe77b0..0000000 --- a/WebKitTools/QtLauncher/QtLauncher.qrc +++ /dev/null @@ -1,5 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file>useragentlist.txt</file> - </qresource> -</RCC> diff --git a/WebKitTools/QtLauncher/fpstimer.cpp b/WebKitTools/QtLauncher/fpstimer.cpp deleted file mode 100644 index 3b72cef..0000000 --- a/WebKitTools/QtLauncher/fpstimer.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "fpstimer.h" - -#include <QDateTime> -#include <QTimerEvent> - -// We save a maximum of 10000 frames, and purge 2000 at a time -#define MAX_FRAMES_SAVED 10000 -#define FRAMES_TO_PURGE_WHEN_FULL 2000 -// 60 FPS -#define FPS_MEASURE_INTERVAL 1000 / 60 - -FpsTimer::FpsTimer(QObject* parent) - : QObject(parent) -{ -} - -int FpsTimer::numFrames(int spanMillis) -{ - const QTime now = QTime::currentTime(); - - int count = 0; - for (int i = m_frames.length() - 1; i >= 0; --i, ++count) { - int msecs = m_frames[i].msecsTo(now); - if (msecs < 0) - msecs += 24 * 60 * 60 * 1000; - if (msecs > spanMillis) - break; - } - return count; -} - -void FpsTimer::start() -{ - m_timer = startTimer(FPS_MEASURE_INTERVAL); -} - -void FpsTimer::stop() -{ - killTimer(m_timer); - m_frames.clear(); -} - -void FpsTimer::timerEvent(QTimerEvent* event) -{ - if (event->timerId() != m_timer) - return; - m_frames.append(QTime::currentTime()); - if (m_frames.length() > MAX_FRAMES_SAVED) - m_frames.erase(m_frames.begin(), m_frames.begin() + FRAMES_TO_PURGE_WHEN_FULL); -} diff --git a/WebKitTools/QtLauncher/fpstimer.h b/WebKitTools/QtLauncher/fpstimer.h deleted file mode 100644 index 66d38eb..0000000 --- a/WebKitTools/QtLauncher/fpstimer.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef fpsmeasure_h -#define fpsmeasure_h - -#include <QObject> -#include <QSet> -#include <QTime> - -class FpsTimer : public QObject { - Q_OBJECT - -public: - FpsTimer(QObject* parent = 0); - int numFrames(int spanMillis = 1000); - -public Q_SLOTS: - void start(); - void stop(); - -protected slots: - virtual void timerEvent(QTimerEvent*); - -private: - int m_timer; - QList<QTime> m_frames; -}; - -#endif // FPSMEASURE_H diff --git a/WebKitTools/QtLauncher/locationedit.cpp b/WebKitTools/QtLauncher/locationedit.cpp deleted file mode 100644 index a97f148..0000000 --- a/WebKitTools/QtLauncher/locationedit.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "locationedit.h" - -LocationEdit::LocationEdit(QWidget* parent) - : QLineEdit(parent) - , m_progress(0) -{ - m_clearTimer.setSingleShot(true); - connect(&m_clearTimer, SIGNAL(timeout()), this, SLOT(reset())); -} - -void LocationEdit::setProgress(int progress) -{ - m_clearTimer.stop(); - m_progress = progress; - update(); -} - -void LocationEdit::reset() -{ - setProgress(0); -} - -void LocationEdit::paintEvent(QPaintEvent* ev) -{ - QColor backgroundColor = QApplication::palette().color(QPalette::Base); - QColor progressColor = QColor(120, 180, 240); - QPalette p = palette(); - - if (!m_progress) - p.setBrush(QPalette::Base, backgroundColor); - else { - QLinearGradient gradient(0, 0, width(), 0); - gradient.setColorAt(0, progressColor); - gradient.setColorAt(((double) m_progress) / 100, progressColor); - if (m_progress != 100) - gradient.setColorAt((double) m_progress / 100 + 0.001, backgroundColor); - p.setBrush(QPalette::Base, gradient); - } - setPalette(p); - - QLineEdit::paintEvent(ev); - - if (m_progress == 100) - m_clearTimer.start(100); -} - -void LocationEdit::focusInEvent(QFocusEvent* ev) -{ - QLineEdit::focusInEvent(ev); -#ifdef Q_WS_MAEMO_5 - QTimer::singleShot(0, this, SLOT(selectAll())); -#endif -} diff --git a/WebKitTools/QtLauncher/locationedit.h b/WebKitTools/QtLauncher/locationedit.h deleted file mode 100644 index e82920c..0000000 --- a/WebKitTools/QtLauncher/locationedit.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef locationedit_h -#define locationedit_h - -#include <QtGui> - -class LocationEdit : public QLineEdit { - Q_OBJECT - -public: - LocationEdit(QWidget* parent = 0); - -public slots: - void setProgress(int progress); - -private slots: - void reset(); - -protected: - virtual void paintEvent(QPaintEvent*); - virtual void focusInEvent(QFocusEvent*); - -private: - int m_progress; - QTimer m_clearTimer; -}; - -#endif diff --git a/WebKitTools/QtLauncher/main.cpp b/WebKitTools/QtLauncher/main.cpp deleted file mode 100644 index 748936b..0000000 --- a/WebKitTools/QtLauncher/main.cpp +++ /dev/null @@ -1,1209 +0,0 @@ -/* - * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies) - * Copyright (C) 2009 Girish Ramakrishnan <girish@forwardbias.in> - * Copyright (C) 2006 George Staikos <staikos@kde.org> - * Copyright (C) 2006 Dirk Mueller <mueller@kde.org> - * Copyright (C) 2006 Zack Rusin <zack@kde.org> - * Copyright (C) 2006 Simon Hausmann <hausmann@kde.org> - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <QtGui> -#include <QtNetwork/QNetworkRequest> - -#if defined(QT_CONFIGURED_WITH_OPENGL) -#include <QtOpenGL/QGLWidget> -#endif - -#if !defined(QT_NO_PRINTER) -#include <QPrintPreviewDialog> -#endif - -#ifndef QT_NO_UITOOLS -#include <QtUiTools/QUiLoader> -#endif - -#include <QDebug> - -#include <cstdio> -#include <qevent.h> -#include <qwebelement.h> -#include <qwebframe.h> -#include <qwebinspector.h> -#include <qwebsettings.h> - -#ifdef Q_WS_MAEMO_5 -#include <qx11info_x11.h> -#endif - -#include "mainwindow.h" -#include "urlloader.h" -#include "utils.h" -#include "webinspector.h" -#include "webpage.h" -#include "webview.h" -#include "../../WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.h" - -#ifdef Q_WS_MAEMO_5 -#include <X11/Xatom.h> -#include <X11/Xlib.h> -#undef KeyPress -#endif - -static const int gExitClickArea = 80; -static bool gUseGraphicsView = false; -static bool gUseCompositing = true; -static bool gCacheWebView = false; -static bool gShowFrameRate = false; -static QGraphicsView::ViewportUpdateMode gViewportUpdateMode = QGraphicsView::MinimalViewportUpdate; -static QUrl gInspectorUrl; -static bool gResizesToContents = false; -static bool gUseTiledBackingStore = false; - -#if defined(Q_WS_MAEMO_5) || defined(Q_WS_S60) -static bool gUseFrameFlattening = true; -#else -static bool gUseFrameFlattening = false; -#endif - -#if defined(QT_CONFIGURED_WITH_OPENGL) -static bool gUseQGLWidgetViewport = false; -#endif - - -class LauncherWindow : public MainWindow { - Q_OBJECT - -public: - LauncherWindow(LauncherWindow* other = 0, bool shareScene = false); - virtual ~LauncherWindow(); - - virtual void keyPressEvent(QKeyEvent* event); - void grabZoomKeys(bool grab); - -#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0) - void sendTouchEvent(); -#endif - - bool eventFilter(QObject* obj, QEvent* event); - -protected slots: - void loadStarted(); - void loadFinished(); - - void showLinkHover(const QString &link, const QString &toolTip); - - void zoomIn(); - void zoomOut(); - void resetZoom(); - void toggleZoomTextOnly(bool on); - void zoomAnimationFinished(); - - void print(); - void screenshot(); - - void setEditable(bool on); - - /* void dumpPlugins() */ - void dumpHtml(); - - void selectElements(); - - void setTouchMocking(bool on); - void toggleAcceleratedCompositing(bool toggle); - void toggleTiledBackingStore(bool toggle); - void toggleResizesToContents(bool toggle); - - void toggleWebGL(bool toggle); - void initializeView(bool useGraphicsView = false); - void toggleSpatialNavigation(bool b); - void toggleFullScreenMode(bool enable); - void showFPS(bool enable); - void changeViewportUpdateMode(int mode); - void toggleFrameFlattening(bool toggle); - void toggleInterruptingJavaScriptEnabled(bool enable); - -#if defined(QT_CONFIGURED_WITH_OPENGL) - void toggleQGLWidgetViewport(bool enable); -#endif - - void showUserAgentDialog(); - -public slots: - LauncherWindow* newWindow(); - LauncherWindow* cloneWindow(); - void updateFPS(int fps); - -signals: - void enteredFullScreenMode(bool on); - -private: - void createChrome(); - void applyZoom(); - -private: - QVector<int> m_zoomLevels; - int m_currentZoom; - - QWidget* m_view; - WebInspector* m_inspector; - - QAction* m_formatMenuAction; - QAction* m_flipAnimated; - QAction* m_flipYAnimated; - -#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0) - QPropertyAnimation* m_zoomAnimation; - QList<QTouchEvent::TouchPoint> m_touchPoints; - bool m_touchMocking; -#endif - - void init(bool useGraphicsView = false); - bool isGraphicsBased() const; - void applyPrefs(LauncherWindow* other = 0); -}; - -LauncherWindow::LauncherWindow(LauncherWindow* other, bool shareScene) - : MainWindow() - , m_currentZoom(100) - , m_view(0) - , m_inspector(0) - , m_formatMenuAction(0) - , m_flipAnimated(0) - , m_flipYAnimated(0) -#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0) - , m_zoomAnimation(0) -#endif -{ - if (other) { - init(other->isGraphicsBased()); - applyPrefs(other); - if (shareScene && other->isGraphicsBased()) { - QGraphicsView* otherView = static_cast<QGraphicsView*>(other->m_view); - static_cast<QGraphicsView*>(m_view)->setScene(otherView->scene()); - } - } else { - init(gUseGraphicsView); - applyPrefs(); - } - - createChrome(); -} - -LauncherWindow::~LauncherWindow() -{ - grabZoomKeys(false); -} - -void LauncherWindow::init(bool useGraphicsView) -{ - QSplitter* splitter = new QSplitter(Qt::Vertical, this); - setCentralWidget(splitter); - -#if defined(Q_WS_S60) - setWindowState(Qt::WindowMaximized); -#else - setWindowState(Qt::WindowNoState); - resize(800, 600); -#endif - - initializeView(useGraphicsView); - - connect(page(), SIGNAL(loadStarted()), this, SLOT(loadStarted())); - connect(page(), SIGNAL(loadFinished(bool)), this, SLOT(loadFinished())); - connect(page(), SIGNAL(linkHovered(const QString&, const QString&, const QString&)), - this, SLOT(showLinkHover(const QString&, const QString&))); - connect(this, SIGNAL(enteredFullScreenMode(bool)), this, SLOT(toggleFullScreenMode(bool))); - - m_inspector = new WebInspector(splitter); - if (!gInspectorUrl.isEmpty()) - m_inspector->setProperty("_q_inspectorUrl", gInspectorUrl); - m_inspector->setPage(page()); - m_inspector->hide(); - connect(this, SIGNAL(destroyed()), m_inspector, SLOT(deleteLater())); - - // the zoom values are chosen to be like in Mozilla Firefox 3 - m_zoomLevels << 30 << 50 << 67 << 80 << 90; - m_zoomLevels << 100; - m_zoomLevels << 110 << 120 << 133 << 150 << 170 << 200 << 240 << 300; - - grabZoomKeys(true); -} - -bool LauncherWindow::isGraphicsBased() const -{ - return bool(qobject_cast<QGraphicsView*>(m_view)); -} - -inline void applySetting(QWebSettings::WebAttribute type, QWebSettings* settings, QWebSettings* other, bool defaultValue) -{ - settings->setAttribute(type, other ? other->testAttribute(type) : defaultValue); -} - -void LauncherWindow::applyPrefs(LauncherWindow* source) -{ - QWebSettings* other = source ? source->page()->settings() : 0; - QWebSettings* settings = page()->settings(); - - applySetting(QWebSettings::AcceleratedCompositingEnabled, settings, other, gUseCompositing); - applySetting(QWebSettings::TiledBackingStoreEnabled, settings, other, gUseTiledBackingStore); - applySetting(QWebSettings::WebGLEnabled, settings, other, false); - applySetting(QWebSettings::FrameFlatteningEnabled, settings, other, gUseFrameFlattening); - - if (!isGraphicsBased()) - return; - - WebViewGraphicsBased* view = static_cast<WebViewGraphicsBased*>(m_view); - WebViewGraphicsBased* otherView = source ? qobject_cast<WebViewGraphicsBased*>(source->m_view) : 0; - - view->setViewportUpdateMode(otherView ? otherView->viewportUpdateMode() : gViewportUpdateMode); - view->setFrameRateMeasurementEnabled(otherView ? otherView->frameRateMeasurementEnabled() : gShowFrameRate); - - if (otherView) - view->setItemCacheMode(otherView->itemCacheMode()); - else - view->setItemCacheMode(gCacheWebView ? QGraphicsItem::DeviceCoordinateCache : QGraphicsItem::NoCache); -} - -void LauncherWindow::keyPressEvent(QKeyEvent* event) -{ -#ifdef Q_WS_MAEMO_5 - switch (event->key()) { - case Qt::Key_F7: - zoomIn(); - event->accept(); - break; - case Qt::Key_F8: - zoomOut(); - event->accept(); - break; - } -#endif - MainWindow::keyPressEvent(event); -} - -void LauncherWindow::grabZoomKeys(bool grab) -{ -#ifdef Q_WS_MAEMO_5 - if (!winId()) { - qWarning("Can't grab keys unless we have a window id"); - return; - } - - Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False); - if (!atom) { - qWarning("Unable to obtain _HILDON_ZOOM_KEY_ATOM"); - return; - } - - unsigned long val = (grab) ? 1 : 0; - XChangeProperty(QX11Info::display(), winId(), atom, XA_INTEGER, 32, PropModeReplace, reinterpret_cast<unsigned char*>(&val), 1); -#endif -} - -#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0) -void LauncherWindow::sendTouchEvent() -{ - if (m_touchPoints.isEmpty()) - return; - - QEvent::Type type = QEvent::TouchUpdate; - if (m_touchPoints.size() == 1) { - if (m_touchPoints[0].state() == Qt::TouchPointReleased) - type = QEvent::TouchEnd; - else if (m_touchPoints[0].state() == Qt::TouchPointPressed) - type = QEvent::TouchBegin; - } - - QTouchEvent touchEv(type); - touchEv.setTouchPoints(m_touchPoints); - QCoreApplication::sendEvent(page(), &touchEv); - - // After sending the event, remove all touchpoints that were released - if (m_touchPoints[0].state() == Qt::TouchPointReleased) - m_touchPoints.removeAt(0); - if (m_touchPoints.size() > 1 && m_touchPoints[1].state() == Qt::TouchPointReleased) - m_touchPoints.removeAt(1); -} -#endif // QT_VERSION >= QT_VERSION_CHECK(4, 6, 0) - -bool LauncherWindow::eventFilter(QObject* obj, QEvent* event) -{ - // If click pos is the bottom right corner (square with size defined by gExitClickArea) - // and the window is on FullScreen, the window must return to its original state. - if (event->type() == QEvent::MouseButtonRelease) { - QMouseEvent* ev = static_cast<QMouseEvent*>(event); - if (windowState() == Qt::WindowFullScreen - && ev->pos().x() > (width() - gExitClickArea) - && ev->pos().y() > (height() - gExitClickArea)) { - - emit enteredFullScreenMode(false); - } - } - -#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0) - if (!m_touchMocking) - return QObject::eventFilter(obj, event); - - if (event->type() == QEvent::MouseButtonPress - || event->type() == QEvent::MouseButtonRelease - || event->type() == QEvent::MouseButtonDblClick - || event->type() == QEvent::MouseMove) { - - QMouseEvent* ev = static_cast<QMouseEvent*>(event); - if (ev->type() == QEvent::MouseMove - && !(ev->buttons() & Qt::LeftButton)) - return false; - - QTouchEvent::TouchPoint touchPoint; - touchPoint.setState(Qt::TouchPointMoved); - if ((ev->type() == QEvent::MouseButtonPress - || ev->type() == QEvent::MouseButtonDblClick)) - touchPoint.setState(Qt::TouchPointPressed); - else if (ev->type() == QEvent::MouseButtonRelease) - touchPoint.setState(Qt::TouchPointReleased); - - touchPoint.setId(0); - touchPoint.setScreenPos(ev->globalPos()); - touchPoint.setPos(ev->pos()); - touchPoint.setPressure(1); - - // If the point already exists, update it. Otherwise create it. - if (m_touchPoints.size() > 0 && !m_touchPoints[0].id()) - m_touchPoints[0] = touchPoint; - else if (m_touchPoints.size() > 1 && !m_touchPoints[1].id()) - m_touchPoints[1] = touchPoint; - else - m_touchPoints.append(touchPoint); - - sendTouchEvent(); - } else if (event->type() == QEvent::KeyPress - && static_cast<QKeyEvent*>(event)->key() == Qt::Key_F - && static_cast<QKeyEvent*>(event)->modifiers() == Qt::ControlModifier) { - - // If the keyboard point is already pressed, release it. - // Otherwise create it and append to m_touchPoints. - if (m_touchPoints.size() > 0 && m_touchPoints[0].id() == 1) { - m_touchPoints[0].setState(Qt::TouchPointReleased); - sendTouchEvent(); - } else if (m_touchPoints.size() > 1 && m_touchPoints[1].id() == 1) { - m_touchPoints[1].setState(Qt::TouchPointReleased); - sendTouchEvent(); - } else { - QTouchEvent::TouchPoint touchPoint; - touchPoint.setState(Qt::TouchPointPressed); - touchPoint.setId(1); - touchPoint.setScreenPos(QCursor::pos()); - touchPoint.setPos(m_view->mapFromGlobal(QCursor::pos())); - touchPoint.setPressure(1); - m_touchPoints.append(touchPoint); - sendTouchEvent(); - - // After sending the event, change the touchpoint state to stationary - m_touchPoints.last().setState(Qt::TouchPointStationary); - } - } -#endif // QT_VERSION >= QT_VERSION_CHECK(4, 6, 0) - - return false; -} - -void LauncherWindow::loadStarted() -{ - m_view->setFocus(Qt::OtherFocusReason); -} - -void LauncherWindow::loadFinished() -{ - QUrl url = page()->mainFrame()->url(); - setAddressUrl(url.toString(QUrl::RemoveUserInfo)); - addCompleterEntry(url); -} - -void LauncherWindow::showLinkHover(const QString &link, const QString &toolTip) -{ -#ifndef Q_WS_MAEMO_5 - statusBar()->showMessage(link); -#endif -#ifndef QT_NO_TOOLTIP - if (!toolTip.isEmpty()) - QToolTip::showText(QCursor::pos(), toolTip); -#endif -} - -void LauncherWindow::zoomAnimationFinished() -{ - if (!isGraphicsBased()) - return; - QGraphicsWebView* view = static_cast<WebViewGraphicsBased*>(m_view)->graphicsWebView(); - view->setTiledBackingStoreFrozen(false); -} - -void LauncherWindow::applyZoom() -{ -#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0) - if (isGraphicsBased() && page()->settings()->testAttribute(QWebSettings::TiledBackingStoreEnabled)) { - QGraphicsWebView* view = static_cast<WebViewGraphicsBased*>(m_view)->graphicsWebView(); - view->setTiledBackingStoreFrozen(true); - if (!m_zoomAnimation) { - m_zoomAnimation = new QPropertyAnimation(view, "scale"); - m_zoomAnimation->setStartValue(view->scale()); - connect(m_zoomAnimation, SIGNAL(finished()), this, SLOT(zoomAnimationFinished())); - } else { - m_zoomAnimation->stop(); - m_zoomAnimation->setStartValue(m_zoomAnimation->currentValue()); - } - - m_zoomAnimation->setDuration(300); - m_zoomAnimation->setEndValue(qreal(m_currentZoom) / 100.); - m_zoomAnimation->start(); - return; - } -#endif - page()->mainFrame()->setZoomFactor(qreal(m_currentZoom) / 100.0); -} - -void LauncherWindow::zoomIn() -{ - int i = m_zoomLevels.indexOf(m_currentZoom); - Q_ASSERT(i >= 0); - if (i < m_zoomLevels.count() - 1) - m_currentZoom = m_zoomLevels[i + 1]; - - applyZoom(); -} - -void LauncherWindow::zoomOut() -{ - int i = m_zoomLevels.indexOf(m_currentZoom); - Q_ASSERT(i >= 0); - if (i > 0) - m_currentZoom = m_zoomLevels[i - 1]; - - applyZoom(); -} - -void LauncherWindow::resetZoom() -{ - m_currentZoom = 100; - page()->mainFrame()->setZoomFactor(1.0); -} - -void LauncherWindow::toggleZoomTextOnly(bool b) -{ - page()->settings()->setAttribute(QWebSettings::ZoomTextOnly, b); -} - -void LauncherWindow::print() -{ -#if !defined(QT_NO_PRINTER) - QPrintPreviewDialog dlg(this); - connect(&dlg, SIGNAL(paintRequested(QPrinter*)), - page()->mainFrame(), SLOT(print(QPrinter*))); - dlg.exec(); -#endif -} - -void LauncherWindow::screenshot() -{ - QPixmap pixmap = QPixmap::grabWidget(m_view); - QLabel* label = new QLabel; - label->setAttribute(Qt::WA_DeleteOnClose); - label->setWindowTitle("Screenshot - Preview"); - label->setPixmap(pixmap); - label->show(); - - QString fileName = QFileDialog::getSaveFileName(label, "Screenshot"); - if (!fileName.isEmpty()) { - pixmap.save(fileName, "png"); - label->setWindowTitle(QString("Screenshot - Saved at %1").arg(fileName)); - } -} - -void LauncherWindow::setEditable(bool on) -{ - page()->setContentEditable(on); - m_formatMenuAction->setVisible(on); -} - -/* -void LauncherWindow::dumpPlugins() { - QList<QWebPluginInfo> plugins = QWebSettings::pluginDatabase()->plugins(); - foreach (const QWebPluginInfo plugin, plugins) { - qDebug() << "Plugin:" << plugin.name(); - foreach (const QWebPluginInfo::MimeType mime, plugin.mimeTypes()) { - qDebug() << " " << mime.name; - } - } -} -*/ - -void LauncherWindow::dumpHtml() -{ - qDebug() << "HTML: " << page()->mainFrame()->toHtml(); -} - -void LauncherWindow::selectElements() -{ - bool ok; - QString str = QInputDialog::getText(this, "Select elements", "Choose elements", - QLineEdit::Normal, "a", &ok); - - if (ok && !str.isEmpty()) { - QWebElementCollection result = page()->mainFrame()->findAllElements(str); - foreach (QWebElement e, result) - e.setStyleProperty("background-color", "yellow"); -#ifndef Q_WS_MAEMO_5 - statusBar()->showMessage(QString("%1 element(s) selected").arg(result.count()), 5000); -#endif - } -} - -void LauncherWindow::setTouchMocking(bool on) -{ -#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0) - m_touchMocking = on; -#endif -} - -void LauncherWindow::toggleAcceleratedCompositing(bool toggle) -{ - gUseCompositing = toggle; - page()->settings()->setAttribute(QWebSettings::AcceleratedCompositingEnabled, toggle); -} - -void LauncherWindow::toggleTiledBackingStore(bool toggle) -{ - page()->settings()->setAttribute(QWebSettings::TiledBackingStoreEnabled, toggle); -} - -void LauncherWindow::toggleResizesToContents(bool toggle) -{ - static_cast<WebViewGraphicsBased*>(m_view)->setResizesToContents(toggle); -} - -void LauncherWindow::toggleWebGL(bool toggle) -{ - page()->settings()->setAttribute(QWebSettings::WebGLEnabled, toggle); -} - -void LauncherWindow::initializeView(bool useGraphicsView) -{ - delete m_view; - - QSplitter* splitter = static_cast<QSplitter*>(centralWidget()); - - if (!useGraphicsView) { - WebViewTraditional* view = new WebViewTraditional(splitter); - view->setPage(page()); - - view->installEventFilter(this); - - m_view = view; - } else { - WebViewGraphicsBased* view = new WebViewGraphicsBased(splitter); - view->setPage(page()); - - if (m_flipAnimated) - connect(m_flipAnimated, SIGNAL(triggered()), view, SLOT(animatedFlip())); - - if (m_flipYAnimated) - connect(m_flipYAnimated, SIGNAL(triggered()), view, SLOT(animatedYFlip())); - - connect(view, SIGNAL(currentFPSUpdated(int)), this, SLOT(updateFPS(int))); - - view->installEventFilter(this); - // The implementation of QAbstractScrollArea::eventFilter makes us need - // to install the event filter also on the viewport of a QGraphicsView. - view->viewport()->installEventFilter(this); - - m_view = view; - } - -#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0) - m_touchMocking = false; -#endif -} - -void LauncherWindow::toggleSpatialNavigation(bool b) -{ - page()->settings()->setAttribute(QWebSettings::SpatialNavigationEnabled, b); -} - -void LauncherWindow::toggleFullScreenMode(bool enable) -{ - if (enable) - setWindowState(Qt::WindowFullScreen); - else { -#if defined(Q_WS_S60) - setWindowState(Qt::WindowMaximized); -#else - setWindowState(Qt::WindowNoState); -#endif - } -} - -void LauncherWindow::showFPS(bool enable) -{ - if (!isGraphicsBased()) - return; - - gShowFrameRate = enable; - WebViewGraphicsBased* view = static_cast<WebViewGraphicsBased*>(m_view); - view->setFrameRateMeasurementEnabled(enable); - - if (!enable) { -#if defined(Q_WS_MAEMO_5) && defined(Q_WS_S60) - setWindowTitle(""); -#else - statusBar()->clearMessage(); -#endif - } -} - -void LauncherWindow::changeViewportUpdateMode(int mode) -{ - gViewportUpdateMode = QGraphicsView::ViewportUpdateMode(mode); - - if (!isGraphicsBased()) - return; - - WebViewGraphicsBased* view = static_cast<WebViewGraphicsBased*>(m_view); - view->setViewportUpdateMode(gViewportUpdateMode); -} - -void LauncherWindow::toggleFrameFlattening(bool toggle) -{ - gUseFrameFlattening = toggle; - page()->settings()->setAttribute(QWebSettings::FrameFlatteningEnabled, toggle); -} - -void LauncherWindow::toggleInterruptingJavaScriptEnabled(bool enable) -{ - page()->setInterruptingJavaScriptEnabled(enable); -} - -#if defined(QT_CONFIGURED_WITH_OPENGL) -void LauncherWindow::toggleQGLWidgetViewport(bool enable) -{ - if (!isGraphicsBased()) - return; - - gUseQGLWidgetViewport = enable; - WebViewGraphicsBased* view = static_cast<WebViewGraphicsBased*>(m_view); - - view->setViewport(enable ? new QGLWidget() : 0); -} -#endif - -void LauncherWindow::showUserAgentDialog() -{ - QStringList items; - QFile file(":/useragentlist.txt"); - if (file.open(QIODevice::ReadOnly)) { - while (!file.atEnd()) - items << file.readLine().trimmed(); - file.close(); - } - - QSettings settings; - QString customUserAgent = settings.value("CustomUserAgent").toString(); - if (!items.contains(customUserAgent) && !customUserAgent.isEmpty()) - items << customUserAgent; - - QDialog* dialog = new QDialog(this); - dialog->setWindowTitle("Change User Agent"); - - QVBoxLayout* layout = new QVBoxLayout(dialog); - dialog->setLayout(layout); - - QComboBox* combo = new QComboBox(dialog); - combo->setMaximumWidth(size().width() * 0.7); - combo->setEditable(true); - combo->insertItems(0, items); - layout->addWidget(combo); - - int index = combo->findText(page()->userAgentForUrl(QUrl())); - combo->setCurrentIndex(index); - - QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok - | QDialogButtonBox::Cancel, Qt::Horizontal, dialog); - connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept())); - connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject())); - layout->addWidget(buttonBox); - - if (dialog->exec() && !combo->currentText().isEmpty()) { - page()->setUserAgent(combo->currentText()); - if (!items.contains(combo->currentText())) - settings.setValue("CustomUserAgent", combo->currentText()); - } - - delete dialog; -} - -LauncherWindow* LauncherWindow::newWindow() -{ - LauncherWindow* mw = new LauncherWindow(this, false); - mw->show(); - return mw; -} - -LauncherWindow* LauncherWindow::cloneWindow() -{ - LauncherWindow* mw = new LauncherWindow(this, true); - mw->show(); - return mw; -} - -void LauncherWindow::updateFPS(int fps) -{ - QString fpsStatusText = QString("Current FPS: %1").arg(fps); - -#if defined(Q_WS_MAEMO_5) && defined(Q_WS_S60) - setWindowTitle(fpsStatusText); -#else - statusBar()->showMessage(fpsStatusText); -#endif -} - -void LauncherWindow::createChrome() -{ - QMenu* fileMenu = menuBar()->addMenu("&File"); - fileMenu->addAction("New Window", this, SLOT(newWindow()), QKeySequence::New); - fileMenu->addAction(tr("Open File..."), this, SLOT(openFile()), QKeySequence::Open); - fileMenu->addAction("Close Window", this, SLOT(close()), QKeySequence::Close); - fileMenu->addSeparator(); - fileMenu->addAction("Take Screen Shot...", this, SLOT(screenshot())); - fileMenu->addAction(tr("Print..."), this, SLOT(print()), QKeySequence::Print); - fileMenu->addSeparator(); - fileMenu->addAction("Quit", QApplication::instance(), SLOT(closeAllWindows()), QKeySequence(Qt::CTRL | Qt::Key_Q)); - - QMenu* editMenu = menuBar()->addMenu("&Edit"); - editMenu->addAction(page()->action(QWebPage::Undo)); - editMenu->addAction(page()->action(QWebPage::Redo)); - editMenu->addSeparator(); - editMenu->addAction(page()->action(QWebPage::Cut)); - editMenu->addAction(page()->action(QWebPage::Copy)); - editMenu->addAction(page()->action(QWebPage::Paste)); - editMenu->addSeparator(); - QAction* setEditable = editMenu->addAction("Set Editable", this, SLOT(setEditable(bool))); - setEditable->setCheckable(true); - - QMenu* viewMenu = menuBar()->addMenu("&View"); - viewMenu->addAction(page()->action(QWebPage::Stop)); - viewMenu->addAction(page()->action(QWebPage::Reload)); - viewMenu->addSeparator(); - QAction* zoomIn = viewMenu->addAction("Zoom &In", this, SLOT(zoomIn())); - QAction* zoomOut = viewMenu->addAction("Zoom &Out", this, SLOT(zoomOut())); - QAction* resetZoom = viewMenu->addAction("Reset Zoom", this, SLOT(resetZoom())); - QAction* zoomTextOnly = viewMenu->addAction("Zoom Text Only", this, SLOT(toggleZoomTextOnly(bool))); - zoomTextOnly->setCheckable(true); - zoomTextOnly->setChecked(false); - viewMenu->addSeparator(); - viewMenu->addAction("Dump HTML", this, SLOT(dumpHtml())); - // viewMenu->addAction("Dump plugins", this, SLOT(dumpPlugins())); - - QMenu* formatMenu = new QMenu("F&ormat", this); - m_formatMenuAction = menuBar()->addMenu(formatMenu); - m_formatMenuAction->setVisible(false); - formatMenu->addAction(page()->action(QWebPage::ToggleBold)); - formatMenu->addAction(page()->action(QWebPage::ToggleItalic)); - formatMenu->addAction(page()->action(QWebPage::ToggleUnderline)); - QMenu* writingMenu = formatMenu->addMenu(tr("Writing Direction")); - writingMenu->addAction(page()->action(QWebPage::SetTextDirectionDefault)); - writingMenu->addAction(page()->action(QWebPage::SetTextDirectionLeftToRight)); - writingMenu->addAction(page()->action(QWebPage::SetTextDirectionRightToLeft)); - - zoomIn->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Plus)); - zoomOut->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Minus)); - resetZoom->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_0)); - - QMenu* windowMenu = menuBar()->addMenu("&Window"); - QAction* toggleFullScreen = windowMenu->addAction("Toggle FullScreen", this, SIGNAL(enteredFullScreenMode(bool))); - toggleFullScreen->setCheckable(true); - toggleFullScreen->setChecked(false); - - // when exit fullscreen mode by clicking on the exit area (bottom right corner) we must - // uncheck the Toggle FullScreen action - toggleFullScreen->connect(this, SIGNAL(enteredFullScreenMode(bool)), SLOT(setChecked(bool))); - - QMenu* toolsMenu = menuBar()->addMenu("&Develop"); - toolsMenu->addAction("Select Elements...", this, SLOT(selectElements())); - QAction* showInspectorAction = toolsMenu->addAction("Show Web Inspector", m_inspector, SLOT(setVisible(bool)), QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_I)); - showInspectorAction->setCheckable(true); - showInspectorAction->connect(m_inspector, SIGNAL(visibleChanged(bool)), SLOT(setChecked(bool))); - -#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0) - QAction* touchMockAction = toolsMenu->addAction("Toggle multitouch mocking", this, SLOT(setTouchMocking(bool))); - touchMockAction->setCheckable(true); - touchMockAction->setShortcut(QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_T)); -#endif - - QWebSettings* settings = page()->settings(); - - QMenu* graphicsViewMenu = toolsMenu->addMenu("QGraphicsView"); - QAction* toggleGraphicsView = graphicsViewMenu->addAction("Toggle use of QGraphicsView", this, SLOT(initializeView(bool))); - toggleGraphicsView->setCheckable(true); - toggleGraphicsView->setChecked(isGraphicsBased()); - - QAction* toggleWebGL = toolsMenu->addAction("Toggle WebGL", this, SLOT(toggleWebGL(bool))); - toggleWebGL->setCheckable(true); - toggleWebGL->setChecked(settings->testAttribute(QWebSettings::WebGLEnabled)); - - QAction* toggleAcceleratedCompositing = graphicsViewMenu->addAction("Toggle Accelerated Compositing", this, SLOT(toggleAcceleratedCompositing(bool))); - toggleAcceleratedCompositing->setCheckable(true); - toggleAcceleratedCompositing->setChecked(settings->testAttribute(QWebSettings::AcceleratedCompositingEnabled)); - toggleAcceleratedCompositing->setEnabled(isGraphicsBased()); - toggleAcceleratedCompositing->connect(toggleGraphicsView, SIGNAL(toggled(bool)), SLOT(setEnabled(bool))); - - QAction* toggleResizesToContents = graphicsViewMenu->addAction("Toggle Resizes To Contents Mode", this, SLOT(toggleResizesToContents(bool))); - toggleResizesToContents->setCheckable(true); - toggleResizesToContents->setChecked(false); - toggleResizesToContents->setEnabled(false); - toggleResizesToContents->connect(toggleGraphicsView, SIGNAL(toggled(bool)), SLOT(setEnabled(bool))); - - QAction* toggleTiledBackingStore = graphicsViewMenu->addAction("Toggle Tiled Backing Store", this, SLOT(toggleTiledBackingStore(bool))); - toggleTiledBackingStore->setCheckable(true); - toggleTiledBackingStore->setChecked(false); - toggleTiledBackingStore->setEnabled(false); - toggleTiledBackingStore->connect(toggleGraphicsView, SIGNAL(toggled(bool)), SLOT(setEnabled(bool))); - - QAction* spatialNavigationAction = toolsMenu->addAction("Toggle Spatial Navigation", this, SLOT(toggleSpatialNavigation(bool))); - spatialNavigationAction->setCheckable(true); - spatialNavigationAction->setShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_S)); - - QAction* toggleFrameFlattening = toolsMenu->addAction("Toggle Frame Flattening", this, SLOT(toggleFrameFlattening(bool))); - toggleFrameFlattening->setCheckable(true); - toggleFrameFlattening->setChecked(settings->testAttribute(QWebSettings::FrameFlatteningEnabled)); - - QAction* toggleInterruptingJavaScripteEnabled = toolsMenu->addAction("Enable interrupting js scripts", this, SLOT(toggleInterruptingJavaScriptEnabled(bool))); - toggleInterruptingJavaScripteEnabled->setCheckable(true); - toggleInterruptingJavaScripteEnabled->setChecked(false); - -#if defined(QT_CONFIGURED_WITH_OPENGL) - QAction* toggleQGLWidgetViewport = graphicsViewMenu->addAction("Toggle use of QGLWidget Viewport", this, SLOT(toggleQGLWidgetViewport(bool))); - toggleQGLWidgetViewport->setCheckable(true); - toggleQGLWidgetViewport->setChecked(gUseQGLWidgetViewport); - toggleQGLWidgetViewport->setEnabled(isGraphicsBased()); - toggleQGLWidgetViewport->connect(toggleGraphicsView, SIGNAL(toggled(bool)), SLOT(setEnabled(bool))); -#endif - - QAction* userAgentAction = toolsMenu->addAction("Change User Agent", this, SLOT(showUserAgentDialog())); - userAgentAction->setShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_U)); - - graphicsViewMenu->addSeparator(); - - m_flipAnimated = graphicsViewMenu->addAction("Animated Flip"); - m_flipAnimated->connect(toggleGraphicsView, SIGNAL(toggled(bool)), SLOT(setEnabled(bool))); - m_flipAnimated->setEnabled(isGraphicsBased()); - - m_flipYAnimated = graphicsViewMenu->addAction("Animated Y-Flip"); - m_flipYAnimated->connect(toggleGraphicsView, SIGNAL(toggled(bool)), SLOT(setEnabled(bool))); - m_flipYAnimated->setEnabled(isGraphicsBased()); - - if (isGraphicsBased()) { - WebViewGraphicsBased* view = static_cast<WebViewGraphicsBased*>(m_view); - connect(m_flipAnimated, SIGNAL(triggered()), view, SLOT(animatedFlip())); - connect(m_flipYAnimated, SIGNAL(triggered()), view, SLOT(animatedYFlip())); - } - - graphicsViewMenu->addSeparator(); - - QAction* cloneWindow = graphicsViewMenu->addAction("Clone Window", this, SLOT(cloneWindow())); - cloneWindow->connect(toggleGraphicsView, SIGNAL(toggled(bool)), SLOT(setEnabled(bool))); - cloneWindow->setEnabled(isGraphicsBased()); - - QAction* showFPS = graphicsViewMenu->addAction("Show FPS", this, SLOT(showFPS(bool))); - showFPS->setCheckable(true); - showFPS->setEnabled(isGraphicsBased()); - showFPS->connect(toggleGraphicsView, SIGNAL(toggled(bool)), SLOT(setEnabled(bool))); - showFPS->setChecked(gShowFrameRate); - - QMenu* viewportUpdateMenu = graphicsViewMenu->addMenu("Change Viewport Update Mode"); - viewportUpdateMenu->setEnabled(isGraphicsBased()); - viewportUpdateMenu->connect(toggleGraphicsView, SIGNAL(toggled(bool)), SLOT(setEnabled(bool))); - - QAction* fullUpdate = viewportUpdateMenu->addAction("FullViewportUpdate"); - fullUpdate->setCheckable(true); - fullUpdate->setChecked((gViewportUpdateMode == QGraphicsView::FullViewportUpdate) ? true : false); - - QAction* minimalUpdate = viewportUpdateMenu->addAction("MinimalViewportUpdate"); - minimalUpdate->setCheckable(true); - minimalUpdate->setChecked((gViewportUpdateMode == QGraphicsView::MinimalViewportUpdate) ? true : false); - - QAction* smartUpdate = viewportUpdateMenu->addAction("SmartViewportUpdate"); - smartUpdate->setCheckable(true); - smartUpdate->setChecked((gViewportUpdateMode == QGraphicsView::SmartViewportUpdate) ? true : false); - - QAction* boundingRectUpdate = viewportUpdateMenu->addAction("BoundingRectViewportUpdate"); - boundingRectUpdate->setCheckable(true); - boundingRectUpdate->setChecked((gViewportUpdateMode == QGraphicsView::BoundingRectViewportUpdate) ? true : false); - - QAction* noUpdate = viewportUpdateMenu->addAction("NoViewportUpdate"); - noUpdate->setCheckable(true); - noUpdate->setChecked((gViewportUpdateMode == QGraphicsView::NoViewportUpdate) ? true : false); - - QSignalMapper* signalMapper = new QSignalMapper(viewportUpdateMenu); - signalMapper->setMapping(fullUpdate, QGraphicsView::FullViewportUpdate); - signalMapper->setMapping(minimalUpdate, QGraphicsView::MinimalViewportUpdate); - signalMapper->setMapping(smartUpdate, QGraphicsView::SmartViewportUpdate); - signalMapper->setMapping(boundingRectUpdate, QGraphicsView::BoundingRectViewportUpdate); - signalMapper->setMapping(noUpdate, QGraphicsView::NoViewportUpdate); - - connect(fullUpdate, SIGNAL(triggered()), signalMapper, SLOT(map())); - connect(minimalUpdate, SIGNAL(triggered()), signalMapper, SLOT(map())); - connect(smartUpdate, SIGNAL(triggered()), signalMapper, SLOT(map())); - connect(boundingRectUpdate, SIGNAL(triggered()), signalMapper, SLOT(map())); - connect(noUpdate, SIGNAL(triggered()), signalMapper, SLOT(map())); - - connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(changeViewportUpdateMode(int))); - - QActionGroup* viewportUpdateModeActions = new QActionGroup(viewportUpdateMenu); - viewportUpdateModeActions->addAction(fullUpdate); - viewportUpdateModeActions->addAction(minimalUpdate); - viewportUpdateModeActions->addAction(smartUpdate); - viewportUpdateModeActions->addAction(boundingRectUpdate); - viewportUpdateModeActions->addAction(noUpdate); -} - -QWebPage* WebPage::createWindow(QWebPage::WebWindowType type) -{ - LauncherWindow* mw = new LauncherWindow; - if (type == WebModalDialog) - mw->setWindowModality(Qt::ApplicationModal); - mw->show(); - return mw->page(); -} - -QObject* WebPage::createPlugin(const QString &classId, const QUrl&, const QStringList&, const QStringList&) -{ - if (classId == "alien_QLabel") { - QLabel* l = new QLabel; - l->winId(); - return l; - } - -#ifndef QT_NO_UITOOLS - QUiLoader loader; - return loader.createWidget(classId, view()); -#else - Q_UNUSED(classId); - return 0; -#endif -} - - -int launcherMain(const QApplication& app) -{ -#ifndef NDEBUG - int retVal = app.exec(); - DumpRenderTreeSupportQt::garbageCollectorCollect(); - QWebSettings::clearMemoryCaches(); - return retVal; -#else - return app.exec(); -#endif -} - -class LauncherApplication : public QApplication { - Q_OBJECT - -public: - LauncherApplication(int& argc, char** argv); - QStringList urls() const { return m_urls; } - bool isRobotized() const { return m_isRobotized; } - -private: - void handleUserOptions(); - void applyDefaultSettings(); - -private: - bool m_isRobotized; - QStringList m_urls; -}; - -void LauncherApplication::applyDefaultSettings() -{ - QWebSettings::setMaximumPagesInCache(4); - - QWebSettings::setObjectCacheCapacities((16*1024*1024) / 8, (16*1024*1024) / 8, 16*1024*1024); - - QWebSettings::globalSettings()->setAttribute(QWebSettings::PluginsEnabled, true); - QWebSettings::globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true); - QWebSettings::enablePersistentStorage(); -} - -LauncherApplication::LauncherApplication(int& argc, char** argv) - : QApplication(argc, argv, QApplication::GuiServer) - , m_isRobotized(false) -{ - // To allow QWebInspector's configuration persistence - setOrganizationName("Nokia"); - setApplicationName("QtLauncher"); - setApplicationVersion("0.1"); - - applyDefaultSettings(); - - handleUserOptions(); -} - -static void requiresGraphicsView(const QString& option) -{ - if (gUseGraphicsView) - return; - appQuit(1, QString("%1 only works in combination with the -graphicsbased option").arg(option)); -} - -void LauncherApplication::handleUserOptions() -{ - QStringList args = arguments(); - QFileInfo program(args.at(0)); - QString programName("QtLauncher"); - if (program.exists()) - programName = program.baseName(); - - QList<QString> updateModes(enumToKeys(QGraphicsView::staticMetaObject, - "ViewportUpdateMode", "ViewportUpdate")); - - if (args.contains("-help")) { - qDebug() << "Usage:" << programName.toLatin1().data() - << "[-graphicsbased]" - << "[-no-compositing]" - << QString("[-viewport-update-mode %1]").arg(formatKeys(updateModes)).toLatin1().data() - << "[-cache-webview]" - << "[-show-fps]" - << "[-r list]" - << "[-inspector-url location]" - << "[-tiled-backing-store]" - << "[-resizes-to-contents]" - << "URLs"; - appQuit(0); - } - - if (args.contains("-graphicsbased")) - gUseGraphicsView = true; - - if (args.contains("-no-compositing")) { - requiresGraphicsView("-no-compositing"); - gUseCompositing = false; - } - - if (args.contains("-show-fps")) { - requiresGraphicsView("-show-fps"); - gShowFrameRate = true; - } - - if (args.contains("-cache-webview")) { - requiresGraphicsView("-cache-webview"); - gCacheWebView = true; - } - - if (args.contains("-tiled-backing-store")) { - requiresGraphicsView("-tiled-backing-store"); - gUseTiledBackingStore = true; - } - - if (args.contains("-resizes-to-contents")) { - requiresGraphicsView("-resizes-to-contents"); - gResizesToContents = true; - } - - QString arg1("-viewport-update-mode"); - int modeIndex = args.indexOf(arg1); - if (modeIndex != -1) { - requiresGraphicsView(arg1); - - QString mode = takeOptionValue(&args, modeIndex); - if (mode.isEmpty()) - appQuit(1, QString("%1 needs a value of one of [%2]").arg(arg1).arg(formatKeys(updateModes))); - int idx = updateModes.indexOf(mode); - if (idx == -1) - appQuit(1, QString("%1 value has to be one of [%2]").arg(arg1).arg(formatKeys(updateModes))); - - gViewportUpdateMode = static_cast<QGraphicsView::ViewportUpdateMode>(idx); - } - - QString inspectorUrlArg("-inspector-url"); - int inspectorUrlIndex = args.indexOf(inspectorUrlArg); - if (inspectorUrlIndex != -1) - gInspectorUrl = takeOptionValue(&args, inspectorUrlIndex); - - int robotIndex = args.indexOf("-r"); - if (robotIndex != -1) { - QString listFile = takeOptionValue(&args, robotIndex); - if (listFile.isEmpty()) - appQuit(1, "-r needs a list file to start in robotized mode"); - if (!QFile::exists(listFile)) - appQuit(1, "The list file supplied to -r does not exist."); - - m_isRobotized = true; - m_urls = QStringList(listFile); - return; - } - - int lastArg = args.lastIndexOf(QRegExp("^-.*")); - m_urls = (lastArg != -1) ? args.mid(++lastArg) : args.mid(1); -} - - -int main(int argc, char **argv) -{ - LauncherApplication app(argc, argv); - - if (app.isRobotized()) { - LauncherWindow* window = new LauncherWindow(); - UrlLoader loader(window->page()->mainFrame(), app.urls().at(0)); - QObject::connect(window->page()->mainFrame(), SIGNAL(loadFinished(bool)), &loader, SLOT(loadNext())); - loader.loadNext(); - window->show(); - return launcherMain(app); - } - - QStringList urls = app.urls(); - - if (urls.isEmpty()) { - QString defaultUrl = QString("file://%1/%2").arg(QDir::homePath()).arg(QLatin1String("index.html")); - if (QDir(defaultUrl).exists()) - urls.append(defaultUrl); - else - urls.append(""); - } - - LauncherWindow* window = 0; - foreach (QString url, urls) { - LauncherWindow* newWindow; - if (!window) - newWindow = window = new LauncherWindow(); - else - newWindow = window->newWindow(); - - newWindow->load(url); - } - - window->show(); - return launcherMain(app); -} - -#include "main.moc" diff --git a/WebKitTools/QtLauncher/mainwindow.cpp b/WebKitTools/QtLauncher/mainwindow.cpp deleted file mode 100644 index aa6aa26..0000000 --- a/WebKitTools/QtLauncher/mainwindow.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies) - * Copyright (C) 2009 Girish Ramakrishnan <girish@forwardbias.in> - * Copyright (C) 2006 George Staikos <staikos@kde.org> - * Copyright (C) 2006 Dirk Mueller <mueller@kde.org> - * Copyright (C) 2006 Zack Rusin <zack@kde.org> - * Copyright (C) 2006 Simon Hausmann <hausmann@kde.org> - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "mainwindow.h" - -#include "locationedit.h" -#include "utils.h" - -MainWindow::MainWindow(const QString& url) - : m_page(new WebPage(this)) -{ - setAttribute(Qt::WA_DeleteOnClose); - if (qgetenv("QTLAUNCHER_USE_ARGB_VISUALS").toInt() == 1) - setAttribute(Qt::WA_TranslucentBackground); - - buildUI(); -} - -void MainWindow::buildUI() -{ - QToolBar* bar = addToolBar("Navigation"); -#if defined(Q_WS_S60) - bar->setIconSize(QSize(16, 16)); -#endif - bar->addAction(page()->action(QWebPage::Back)); - bar->addAction(page()->action(QWebPage::Forward)); - bar->addAction(page()->action(QWebPage::Reload)); - bar->addAction(page()->action(QWebPage::Stop)); - - urlEdit = new LocationEdit(this); - urlEdit->setSizePolicy(QSizePolicy::Expanding, urlEdit->sizePolicy().verticalPolicy()); - connect(urlEdit, SIGNAL(returnPressed()), SLOT(changeLocation())); - QCompleter* completer = new QCompleter(this); - urlEdit->setCompleter(completer); - completer->setModel(&urlModel); -#if defined(Q_WS_S60) - addToolBarBreak(); - addToolBar("Location")->addWidget(urlEdit); -#else - bar->addWidget(urlEdit); -#endif - - connect(page()->mainFrame(), SIGNAL(titleChanged(const QString&)), - this, SLOT(setWindowTitle(const QString&))); - connect(page()->mainFrame(), SIGNAL(urlChanged(QUrl)), this, SLOT(setAddressUrl(QUrl))); - connect(page(), SIGNAL(loadProgress(int)), urlEdit, SLOT(setProgress(int))); - connect(page(), SIGNAL(windowCloseRequested()), this, SLOT(close())); - - // short-cuts - page()->action(QWebPage::Back)->setShortcut(QKeySequence::Back); - page()->action(QWebPage::Stop)->setShortcut(Qt::Key_Escape); - page()->action(QWebPage::Forward)->setShortcut(QKeySequence::Forward); - page()->action(QWebPage::Reload)->setShortcut(QKeySequence::Refresh); - page()->action(QWebPage::Undo)->setShortcut(QKeySequence::Undo); - page()->action(QWebPage::Redo)->setShortcut(QKeySequence::Redo); - page()->action(QWebPage::Cut)->setShortcut(QKeySequence::Cut); - page()->action(QWebPage::Copy)->setShortcut(QKeySequence::Copy); - page()->action(QWebPage::Paste)->setShortcut(QKeySequence::Paste); - - page()->action(QWebPage::ToggleBold)->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_B)); - page()->action(QWebPage::ToggleItalic)->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_I)); - page()->action(QWebPage::ToggleUnderline)->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_U)); -} - -WebPage* MainWindow::page() -{ - return m_page; -} - -void MainWindow::setAddressUrl(const QUrl& url) -{ - urlEdit->setText(url.toString(QUrl::RemoveUserInfo)); -} - -void MainWindow::setAddressUrl(const QString& url) -{ - urlEdit->setText(url); -} - -void MainWindow::addCompleterEntry(const QUrl& url) -{ - QUrl::FormattingOptions opts; - opts |= QUrl::RemoveScheme; - opts |= QUrl::RemoveUserInfo; - opts |= QUrl::StripTrailingSlash; - QString s = url.toString(opts); - s = s.mid(2); - if (s.isEmpty()) - return; - - if (!urlList.contains(s)) - urlList += s; - urlModel.setStringList(urlList); -} - -void MainWindow::load(const QString& url) -{ - QUrl qurl = urlFromUserInput(url); - if (qurl.scheme().isEmpty()) - qurl = QUrl("http://" + url + "/"); - load(qurl); -} - -void MainWindow::load(const QUrl& url) -{ - if (!url.isValid()) - return; - - setAddressUrl(url.toString()); - page()->mainFrame()->load(url); -} - -void MainWindow::changeLocation() -{ - QString string = urlEdit->text(); - load(string); -} - -void MainWindow::openFile() -{ - static const QString filter("HTML Files (*.htm *.html);;Text Files (*.txt);;Image Files (*.gif *.jpg *.png);;All Files (*)"); - - QFileDialog fileDialog(this, tr("Open"), QString(), filter); - fileDialog.setAcceptMode(QFileDialog::AcceptOpen); - fileDialog.setFileMode(QFileDialog::ExistingFile); - fileDialog.setOptions(QFileDialog::ReadOnly); - - if (fileDialog.exec()) { - QString selectedFile = fileDialog.selectedFiles()[0]; - if (!selectedFile.isEmpty()) - load(QUrl::fromLocalFile(selectedFile)); - } -} - diff --git a/WebKitTools/QtLauncher/mainwindow.h b/WebKitTools/QtLauncher/mainwindow.h deleted file mode 100644 index d753a46..0000000 --- a/WebKitTools/QtLauncher/mainwindow.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies) - * Copyright (C) 2009 Girish Ramakrishnan <girish@forwardbias.in> - * Copyright (C) 2006 George Staikos <staikos@kde.org> - * Copyright (C) 2006 Dirk Mueller <mueller@kde.org> - * Copyright (C) 2006 Zack Rusin <zack@kde.org> - * Copyright (C) 2006 Simon Hausmann <hausmann@kde.org> - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef mainwindow_h -#define mainwindow_h - -#include <QtGui> -#include "webpage.h" - -class LocationEdit; - -class MainWindow : public QMainWindow { - Q_OBJECT - -public: - MainWindow(const QString& url = QString()); - - void addCompleterEntry(const QUrl& url); - - void load(const QString& url); - void load(const QUrl& url); - - WebPage* page(); - -protected slots: - void setAddressUrl(const QString& url); - void setAddressUrl(const QUrl& url); - void openFile(); - void changeLocation(); - -private: - void buildUI(); - - QStringListModel urlModel; - QStringList urlList; - LocationEdit* urlEdit; - - WebPage* m_page; -}; - -#endif diff --git a/WebKitTools/QtLauncher/urlloader.cpp b/WebKitTools/QtLauncher/urlloader.cpp deleted file mode 100644 index 630ead6..0000000 --- a/WebKitTools/QtLauncher/urlloader.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) - * Copyright (C) 2009 University of Szeged - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "urlloader.h" - -#include <QFile> -#include <QDebug> - -UrlLoader::UrlLoader(QWebFrame* frame, const QString& inputFileName) - : m_frame(frame) - , m_stdOut(stdout) - , m_loaded(0) -{ - init(inputFileName); -} - -void UrlLoader::loadNext() -{ - QString qstr; - if (getUrl(qstr)) { - QUrl url(qstr, QUrl::StrictMode); - if (url.isValid()) { - m_stdOut << "Loading " << qstr << " ......" << ++m_loaded << endl; - m_frame->load(url); - } else - loadNext(); - } else - disconnect(m_frame, 0, this, 0); -} - -void UrlLoader::init(const QString& inputFileName) -{ - QFile inputFile(inputFileName); - if (inputFile.open(QIODevice::ReadOnly | QIODevice::Text)) { - QTextStream stream(&inputFile); - QString line; - while (true) { - line = stream.readLine(); - if (line.isNull()) - break; - m_urls.append(line); - } - } else { - qDebug() << "Can't open list file"; - exit(0); - } - m_index = 0; - inputFile.close(); -} - -bool UrlLoader::getUrl(QString& qstr) -{ - if (m_index == m_urls.size()) - return false; - - qstr = m_urls[m_index++]; - return true; -} diff --git a/WebKitTools/QtLauncher/urlloader.h b/WebKitTools/QtLauncher/urlloader.h deleted file mode 100644 index ed14adc..0000000 --- a/WebKitTools/QtLauncher/urlloader.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) - * Copyright (C) 2009 University of Szeged - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef urlloader_h -#define urlloader_h - -#include "qwebframe.h" - -#include <QTextStream> -#include <QVector> - -class UrlLoader : public QObject { - Q_OBJECT - -public: - UrlLoader(QWebFrame* frame, const QString& inputFileName); - -public slots: - void loadNext(); - -private: - void init(const QString& inputFileName); - bool getUrl(QString& qstr); - -private: - QVector<QString> m_urls; - int m_index; - QWebFrame* m_frame; - QTextStream m_stdOut; - int m_loaded; -}; - -#endif diff --git a/WebKitTools/QtLauncher/useragentlist.txt b/WebKitTools/QtLauncher/useragentlist.txt deleted file mode 100644 index ca53693..0000000 --- a/WebKitTools/QtLauncher/useragentlist.txt +++ /dev/null @@ -1,9 +0,0 @@ -Mozilla/5.0 (X11; U; Linux; en-US) AppleWebKit/533.3 (KHTML, like Gecko) QtLauncher/0.1 Safari/533.3 -Mozilla/5.0 (SymbianOS/9.4; U; Series60/5.0; en-GB) AppleWebKit/533.3 (KHTML, like Gecko) QtLauncher/0.1 Mobile Safari/533.3 -Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/125.2 (KHTML, like Gecko) Safari/125.8 -Mozilla/5.0 (Linux; U; Android 1.1; en-gb; dream) AppleWebKit/525.10+ (KHTML, like Gecko) Version/3.0.4 Mobile Safari/523.12.2 -Mozilla/5.0 (iPhone; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10 -Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10 -Opera/9.25 (Windows NT 6.0; U; en) -Mozilla/5.0 (SymbianOS/9.4; U; Series60/5.0 Nokia5800d-1b/20.2.014; Profile/MIDP-2.1 Configuration/CLDC-1.1 ) AppleWebKit/413 (KHTML, like Gecko) Safari/413 -Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.2; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0) diff --git a/WebKitTools/QtLauncher/utils.cpp b/WebKitTools/QtLauncher/utils.cpp deleted file mode 100644 index 2d45dd0..0000000 --- a/WebKitTools/QtLauncher/utils.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "utils.h" - - -QString takeOptionValue(QStringList* arguments, int index) -{ - QString result; - - if (++index < arguments->count() && !arguments->at(index).startsWith("-")) - result = arguments->takeAt(index); - - return result; -} - -QString formatKeys(QList<QString> keys) -{ - QString result; - for (int i = 0; i < keys.count() - 1; i++) - result.append(keys.at(i) + "|"); - result.append(keys.last()); - return result; -} - -QList<QString> enumToKeys(const QMetaObject o, const QString& name, const QString& strip) -{ - QList<QString> list; - - int enumIndex = o.indexOfEnumerator(name.toLatin1().data()); - QMetaEnum enumerator = o.enumerator(enumIndex); - - if (enumerator.isValid()) { - for (int i = 0; i < enumerator.keyCount(); i++) { - QString key(enumerator.valueToKey(i)); - list.append(key.remove(strip)); - } - } - - return list; -} - -void appQuit(int exitCode, const QString& msg) -{ - if (!msg.isEmpty()) { - if (exitCode > 0) - qDebug("ERROR: %s", msg.toLatin1().data()); - else - qDebug() << msg; - } - exit(exitCode); -} - -QUrl urlFromUserInput(const QString& string) -{ - QString input(string); - QFileInfo fi(input); - if (fi.exists() && fi.isRelative()) - input = fi.absoluteFilePath(); - -#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0) - return QUrl::fromUserInput(input); -#else - return QUrl(input); -#endif -} - - diff --git a/WebKitTools/QtLauncher/utils.h b/WebKitTools/QtLauncher/utils.h deleted file mode 100644 index b67351e..0000000 --- a/WebKitTools/QtLauncher/utils.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef utils_h -#define utils_h - -#include <QtCore> - -#ifndef NO_RETURN -#if defined(__CC_ARM) || defined(__ARMCC__) -#define NO_RETURN __declspec(noreturn) -#elif defined(__GNUC__) -#define NO_RETURN __attribute((__noreturn__)) -#else -#define NO_RETURN -#endif -#endif - -// options handling -QString takeOptionValue(QStringList* arguments, int index); -QString formatKeys(QList<QString> keys); -QList<QString> enumToKeys(const QMetaObject o, const QString& name, const QString& strip); - -NO_RETURN void appQuit(int status, const QString& msg = QString()); - -QUrl urlFromUserInput(const QString& input); - -#endif diff --git a/WebKitTools/QtLauncher/webinspector.h b/WebKitTools/QtLauncher/webinspector.h deleted file mode 100644 index d251c5c..0000000 --- a/WebKitTools/QtLauncher/webinspector.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2009-2010 Nokia Corporation and/or its subsidiary(-ies) - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef webinspector_h -#define webinspector_h - -#include <QtGui> -#include "qwebinspector.h" - -class WebInspector : public QWebInspector { - Q_OBJECT - -public: - WebInspector(QWidget* parent) : QWebInspector(parent) {} - -signals: - void visibleChanged(bool nowVisible); - -protected: - void showEvent(QShowEvent* event) - { - QWebInspector::showEvent(event); - emit visibleChanged(true); - } - void hideEvent(QHideEvent* event) - { - QWebInspector::hideEvent(event); - emit visibleChanged(false); - } -}; - -#endif diff --git a/WebKitTools/QtLauncher/webpage.cpp b/WebKitTools/QtLauncher/webpage.cpp deleted file mode 100644 index 624a66f..0000000 --- a/WebKitTools/QtLauncher/webpage.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (C) 2009-2010 Nokia Corporation and/or its subsidiary(-ies) - * Copyright (C) 2009 Girish Ramakrishnan <girish@forwardbias.in> - * Copyright (C) 2006 George Staikos <staikos@kde.org> - * Copyright (C) 2006 Dirk Mueller <mueller@kde.org> - * Copyright (C) 2006 Zack Rusin <zack@kde.org> - * Copyright (C) 2006 Simon Hausmann <hausmann@kde.org> - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "webpage.h" - -#include <QDesktopServices> -#include <QtGui> -#include <QtNetwork/QNetworkRequest> -#include <QtNetwork/QNetworkProxy> - -WebPage::WebPage(QObject* parent) - : QWebPage(parent) - , m_userAgent() - , m_interruptingJavaScriptEnabled(false) -{ - applyProxy(); -} - -void WebPage::applyProxy() -{ - QUrl proxyUrl(qgetenv("http_proxy")); - - if (proxyUrl.isValid() && !proxyUrl.host().isEmpty()) { - int proxyPort = (proxyUrl.port() > 0) ? proxyUrl.port() : 8080; - networkAccessManager()->setProxy(QNetworkProxy(QNetworkProxy::HttpProxy, proxyUrl.host(), proxyPort)); - } -} - -bool WebPage::supportsExtension(QWebPage::Extension extension) const -{ - if (extension == QWebPage::ErrorPageExtension) - return true; - return false; -} - -bool WebPage::extension(Extension extension, const ExtensionOption* option, ExtensionReturn* output) -{ - const QWebPage::ErrorPageExtensionOption* info = static_cast<const QWebPage::ErrorPageExtensionOption*>(option); - QWebPage::ErrorPageExtensionReturn* errorPage = static_cast<QWebPage::ErrorPageExtensionReturn*>(output); - - errorPage->content = QString("<html><head><title>Failed loading page</title></head><body>%1</body></html>") - .arg(info->errorString).toUtf8(); - - return true; -} - -bool WebPage::acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest& request, NavigationType type) -{ - QObject* view = parent(); - - QVariant value = view->property("keyboardModifiers"); - - if (!value.isNull()) { - Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers(value.toInt()); - - if (modifiers & Qt::ShiftModifier) { - QWebPage* page = createWindow(QWebPage::WebBrowserWindow); - page->mainFrame()->load(request); - return false; - } - - if (modifiers & Qt::AltModifier) { - openUrlInDefaultBrowser(request.url()); - return false; - } - } - - return QWebPage::acceptNavigationRequest(frame, request, type); -} - -void WebPage::openUrlInDefaultBrowser(const QUrl& url) -{ - if (QAction* action = qobject_cast<QAction*>(sender())) - QDesktopServices::openUrl(action->data().toUrl()); - else - QDesktopServices::openUrl(url); -} - -QString WebPage::userAgentForUrl(const QUrl& url) const -{ - if (!m_userAgent.isEmpty()) - return m_userAgent; - return QWebPage::userAgentForUrl(url); -} - -bool WebPage::shouldInterruptJavaScript() -{ - if (!m_interruptingJavaScriptEnabled) - return false; - return QWebPage::shouldInterruptJavaScript(); -} diff --git a/WebKitTools/QtLauncher/webpage.h b/WebKitTools/QtLauncher/webpage.h deleted file mode 100644 index 061deb5..0000000 --- a/WebKitTools/QtLauncher/webpage.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies) - * Copyright (C) 2009 Girish Ramakrishnan <girish@forwardbias.in> - * Copyright (C) 2006 George Staikos <staikos@kde.org> - * Copyright (C) 2006 Dirk Mueller <mueller@kde.org> - * Copyright (C) 2006 Zack Rusin <zack@kde.org> - * Copyright (C) 2006 Simon Hausmann <hausmann@kde.org> - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef webpage_h -#define webpage_h - -#include <qwebframe.h> -#include <qwebpage.h> - -class WebPage : public QWebPage { - Q_OBJECT - -public: - WebPage(QObject* parent = 0); - - virtual QWebPage* createWindow(QWebPage::WebWindowType); - virtual QObject* createPlugin(const QString&, const QUrl&, const QStringList&, const QStringList&); - virtual bool supportsExtension(QWebPage::Extension extension) const; - virtual bool extension(Extension extension, const ExtensionOption* option, ExtensionReturn* output); - - virtual bool acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest& request, NavigationType type); - - QString userAgentForUrl(const QUrl& url) const; - void setInterruptingJavaScriptEnabled(bool enabled) { m_interruptingJavaScriptEnabled = enabled; } - -public slots: - void openUrlInDefaultBrowser(const QUrl& url = QUrl()); - void setUserAgent(const QString& ua) { m_userAgent = ua; } - bool shouldInterruptJavaScript(); - -private: - void applyProxy(); - QString m_userAgent; - bool m_interruptingJavaScriptEnabled; -}; - -#endif diff --git a/WebKitTools/QtLauncher/webview.cpp b/WebKitTools/QtLauncher/webview.cpp deleted file mode 100644 index 1467cf8..0000000 --- a/WebKitTools/QtLauncher/webview.cpp +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies) - * Copyright (C) 2009 Girish Ramakrishnan <girish@forwardbias.in> - * Copyright (C) 2006 George Staikos <staikos@kde.org> - * Copyright (C) 2006 Dirk Mueller <mueller@kde.org> - * Copyright (C) 2006 Zack Rusin <zack@kde.org> - * Copyright (C) 2006 Simon Hausmann <hausmann@kde.org> - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "webview.h" - -#include <QtGui> -#include <QGraphicsScene> - -WebViewGraphicsBased::WebViewGraphicsBased(QWidget* parent) - : QGraphicsView(parent) - , m_item(new GraphicsWebView) - , m_numPaintsTotal(0) - , m_numPaintsSinceLastMeasure(0) - , m_measureFps(false) - , m_resizesToContents(false) -{ - setScene(new QGraphicsScene(this)); - scene()->addItem(m_item); - - setFrameShape(QFrame::NoFrame); - setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - -#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0) - QStateMachine* machine = new QStateMachine(this); - QState* s0 = new QState(machine); - s0->assignProperty(this, "yRotation", 0); - - QState* s1 = new QState(machine); - s1->assignProperty(this, "yRotation", 90); - - QAbstractTransition* t1 = s0->addTransition(this, SIGNAL(yFlipRequest()), s1); - QPropertyAnimation* yRotationAnim = new QPropertyAnimation(this, "yRotation", this); - yRotationAnim->setDuration(1000); - t1->addAnimation(yRotationAnim); - - QState* s2 = new QState(machine); - s2->assignProperty(this, "yRotation", -90); - s1->addTransition(s1, SIGNAL(propertiesAssigned()), s2); - - QAbstractTransition* t2 = s2->addTransition(s0); - t2->addAnimation(yRotationAnim); - - machine->setInitialState(s0); - machine->start(); -#endif - - m_updateTimer = new QTimer(this); - m_updateTimer->setInterval(1000); - connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(updateFrameRate())); -} - -void WebViewGraphicsBased::setResizesToContents(bool b) -{ - m_resizesToContents = b; - m_item->setResizesToContents(m_resizesToContents); - if (m_resizesToContents) { - setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); - setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); - } else { - setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - } -} - -void WebViewGraphicsBased::resizeEvent(QResizeEvent* event) -{ - QGraphicsView::resizeEvent(event); - if (m_resizesToContents) - return; - QRectF rect(QPoint(0, 0), event->size()); - m_item->setGeometry(rect); - scene()->setSceneRect(rect); -} - -void WebViewGraphicsBased::setFrameRateMeasurementEnabled(bool enabled) -{ - m_measureFps = enabled; - if (m_measureFps) { - m_lastConsultTime = m_startTime = QTime::currentTime(); - m_fpsTimer.start(); - m_updateTimer->start(); - } else { - m_fpsTimer.stop(); - m_updateTimer->stop(); - } -} - -void WebViewGraphicsBased::updateFrameRate() -{ - const QTime now = QTime::currentTime(); - int interval = m_lastConsultTime.msecsTo(now); - int frames = m_fpsTimer.numFrames(interval); - int current = interval ? frames * 1000 / interval : 0; - - emit currentFPSUpdated(current); - - m_lastConsultTime = now; -} - -void WebViewGraphicsBased::animatedFlip() -{ -#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0) - QSizeF center = m_item->boundingRect().size() / 2; - QPointF centerPoint = QPointF(center.width(), center.height()); - m_item->setTransformOriginPoint(centerPoint); - - QPropertyAnimation* animation = new QPropertyAnimation(m_item, "rotation", this); - animation->setDuration(1000); - - int rotation = int(m_item->rotation()); - - animation->setStartValue(rotation); - animation->setEndValue(rotation + 180 - (rotation % 180)); - - animation->start(QAbstractAnimation::DeleteWhenStopped); -#endif -} - -void WebViewGraphicsBased::animatedYFlip() -{ - emit yFlipRequest(); -} - -void WebViewGraphicsBased::paintEvent(QPaintEvent* event) -{ - QGraphicsView::paintEvent(event); - if (!m_measureFps) - return; -} - -static QMenu* createContextMenu(QWebPage* page, QPoint position) -{ - QMenu* menu = page->createStandardContextMenu(); - - QWebHitTestResult r = page->mainFrame()->hitTestContent(position); - - if (!r.linkUrl().isEmpty()) { - WebPage* webPage = qobject_cast<WebPage*>(page); - QAction* newTabAction = menu->addAction("Open in Default &Browser", webPage, SLOT(openUrlInDefaultBrowser())); - newTabAction->setData(r.linkUrl()); - menu->insertAction(menu->actions().at(2), newTabAction); - } - return menu; -} - -void GraphicsWebView::mousePressEvent(QGraphicsSceneMouseEvent* event) -{ - setProperty("mouseButtons", QVariant::fromValue(int(event->buttons()))); - setProperty("keyboardModifiers", QVariant::fromValue(int(event->modifiers()))); - - QGraphicsWebView::mousePressEvent(event); -} - -void WebViewTraditional::mousePressEvent(QMouseEvent* event) -{ - setProperty("mouseButtons", QVariant::fromValue(int(event->buttons()))); - setProperty("keyboardModifiers", QVariant::fromValue(int(event->modifiers()))); - - QWebView::mousePressEvent(event); -} - -void GraphicsWebView::contextMenuEvent(QGraphicsSceneContextMenuEvent* event) -{ - QMenu* menu = createContextMenu(page(), event->pos().toPoint()); - menu->exec(mapToScene(event->pos()).toPoint()); - delete menu; -} - -void WebViewTraditional::contextMenuEvent(QContextMenuEvent* event) -{ - QMenu* menu = createContextMenu(page(), event->pos()); - menu->exec(mapToGlobal(event->pos())); - delete menu; -} - diff --git a/WebKitTools/QtLauncher/webview.h b/WebKitTools/QtLauncher/webview.h deleted file mode 100644 index 30161bb..0000000 --- a/WebKitTools/QtLauncher/webview.h +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies) - * Copyright (C) 2009 Girish Ramakrishnan <girish@forwardbias.in> - * Copyright (C) 2006 George Staikos <staikos@kde.org> - * Copyright (C) 2006 Dirk Mueller <mueller@kde.org> - * Copyright (C) 2006 Zack Rusin <zack@kde.org> - * Copyright (C) 2006 Simon Hausmann <hausmann@kde.org> - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef webview_h -#define webview_h - -#include "fpstimer.h" -#include "webpage.h" -#include <qwebview.h> -#include <qgraphicswebview.h> -#include <QGraphicsView> -#include <QGraphicsWidget> -#include <QTime> - -class WebViewTraditional : public QWebView { - Q_OBJECT - -public: - WebViewTraditional(QWidget* parent) : QWebView(parent) {} - -protected: - virtual void contextMenuEvent(QContextMenuEvent*); - virtual void mousePressEvent(QMouseEvent*); -}; - - -class GraphicsWebView : public QGraphicsWebView { - Q_OBJECT - -public: - GraphicsWebView(QGraphicsItem* parent = 0) : QGraphicsWebView(parent) {}; - -protected: - virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent*); - virtual void mousePressEvent(QGraphicsSceneMouseEvent*); -}; - - -class WebViewGraphicsBased : public QGraphicsView { - Q_OBJECT - Q_PROPERTY(qreal yRotation READ yRotation WRITE setYRotation) - -public: - WebViewGraphicsBased(QWidget* parent); - virtual void resizeEvent(QResizeEvent*); - void setPage(QWebPage* page) { m_item->setPage(page); } - void setItemCacheMode(QGraphicsItem::CacheMode mode) { m_item->setCacheMode(mode); } - QGraphicsItem::CacheMode itemCacheMode() { return m_item->cacheMode(); } - - void setFrameRateMeasurementEnabled(bool enabled); - bool frameRateMeasurementEnabled() const { return m_measureFps; } - - virtual void paintEvent(QPaintEvent* event); - - void setResizesToContents(bool b); - - void setYRotation(qreal angle) - { -#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0) - QRectF r = m_item->boundingRect(); - m_item->setTransform(QTransform() - .translate(r.width() / 2, r.height() / 2) - .rotate(angle, Qt::YAxis) - .translate(-r.width() / 2, -r.height() / 2)); -#endif - m_yRotation = angle; - } - qreal yRotation() const - { - return m_yRotation; - } - - GraphicsWebView* graphicsWebView() const { return m_item; } - -public slots: - void updateFrameRate(); - void animatedFlip(); - void animatedYFlip(); - -signals: - void yFlipRequest(); - void currentFPSUpdated(int fps); - -private: - GraphicsWebView* m_item; - int m_numPaintsTotal; - int m_numPaintsSinceLastMeasure; - QTime m_startTime; - QTime m_lastConsultTime; - QTimer* m_updateTimer; - bool m_measureFps; - qreal m_yRotation; - bool m_resizesToContents; - FpsTimer m_fpsTimer; -}; - -#endif |