diff options
Diffstat (limited to 'WebKitTools/QtLauncher')
-rw-r--r-- | WebKitTools/QtLauncher/QtLauncher.pro | 34 | ||||
-rw-r--r-- | WebKitTools/QtLauncher/locationedit.cpp | 80 | ||||
-rw-r--r-- | WebKitTools/QtLauncher/locationedit.h | 54 | ||||
-rw-r--r-- | WebKitTools/QtLauncher/main.cpp | 598 | ||||
-rw-r--r-- | WebKitTools/QtLauncher/mainwindow.cpp | 151 | ||||
-rw-r--r-- | WebKitTools/QtLauncher/mainwindow.h | 69 | ||||
-rw-r--r-- | WebKitTools/QtLauncher/urlloader.cpp | 83 | ||||
-rw-r--r-- | WebKitTools/QtLauncher/urlloader.h | 58 | ||||
-rw-r--r-- | WebKitTools/QtLauncher/utils.cpp | 42 | ||||
-rw-r--r-- | WebKitTools/QtLauncher/utils.h | 35 | ||||
-rw-r--r-- | WebKitTools/QtLauncher/webinspector.h | 56 | ||||
-rw-r--r-- | WebKitTools/QtLauncher/webpage.cpp | 106 | ||||
-rw-r--r-- | WebKitTools/QtLauncher/webpage.h | 59 | ||||
-rw-r--r-- | WebKitTools/QtLauncher/webview.cpp | 81 | ||||
-rw-r--r-- | WebKitTools/QtLauncher/webview.h | 62 |
15 files changed, 1568 insertions, 0 deletions
diff --git a/WebKitTools/QtLauncher/QtLauncher.pro b/WebKitTools/QtLauncher/QtLauncher.pro new file mode 100644 index 0000000..e448f69 --- /dev/null +++ b/WebKitTools/QtLauncher/QtLauncher.pro @@ -0,0 +1,34 @@ +TEMPLATE = app + +SOURCES += \ + locationedit.cpp \ + main.cpp \ + mainwindow.cpp \ + urlloader.cpp \ + utils.cpp \ + webpage.cpp \ + webview.cpp \ + +HEADERS += \ + locationedit.h \ + mainwindow.h \ + urlloader.h \ + utils.h \ + webinspector.h \ + webpage.h \ + webview.h \ + +CONFIG -= app_bundle +CONFIG += uitools +DESTDIR = ../../bin + +include(../../WebKit.pri) + +QT += network +macx:QT+=xml +QMAKE_RPATHDIR = $$OUTPUT_DIR/lib $$QMAKE_RPATHDIR + +symbian { + TARGET.UID3 = 0xA000E543 + TARGET.CAPABILITY = ReadUserData WriteUserData NetworkServices +} diff --git a/WebKitTools/QtLauncher/locationedit.cpp b/WebKitTools/QtLauncher/locationedit.cpp new file mode 100644 index 0000000..a97f148 --- /dev/null +++ b/WebKitTools/QtLauncher/locationedit.cpp @@ -0,0 +1,80 @@ +/* + * 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 new file mode 100644 index 0000000..e82920c --- /dev/null +++ b/WebKitTools/QtLauncher/locationedit.h @@ -0,0 +1,54 @@ +/* + * 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 new file mode 100644 index 0000000..081b8f0 --- /dev/null +++ b/WebKitTools/QtLauncher/main.cpp @@ -0,0 +1,598 @@ +/* + * 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_NO_PRINTER) +#include <QPrintPreviewDialog> +#endif + +#ifndef QT_NO_UITOOLS +#include <QtUiTools/QUiLoader> +#endif + +#include <QDebug> + +#include <cstdio> +#include "mainwindow.h" +#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 "urlloader.h" +#include "utils.h" +#include "webinspector.h" +#include "webpage.h" +#include "webview.h" + +#ifdef Q_WS_MAEMO_5 +#include <X11/Xatom.h> +#include <X11/Xlib.h> +#undef KeyPress +#endif + +#ifndef NDEBUG +void QWEBKIT_EXPORT qt_drt_garbageCollector_collect(); +#endif + +class LauncherWindow : public MainWindow { + Q_OBJECT + +public: + LauncherWindow(QString url = QString()); + virtual ~LauncherWindow(); + + virtual void keyPressEvent(QKeyEvent* event); + void grabZoomKeys(bool grab); + +#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0) + void sendTouchEvent(); + bool eventFilter(QObject* obj, QEvent* event); +#endif + + QWebView* webView() const { return view; } + +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 print(); + void screenshot(); + + void setEditable(bool on); + + /* void dumpPlugins() */ + void dumpHtml(); + + void selectElements(); + + void setTouchMocking(bool on); + +public slots: + void newWindow(const QString& url = QString()); + +private: + // create the status bar, tool bar & menu + void setupUI(); + +private: + QVector<int> zoomLevels; + int currentZoom; + + QWebView* view; + WebInspector* inspector; + + QAction* formatMenuAction; + +#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0) + QList<QTouchEvent::TouchPoint> touchPoints; + bool touchMocking; +#endif +}; + + +LauncherWindow::LauncherWindow(QString url) + : MainWindow(url) + , currentZoom(100) +{ + QSplitter* splitter = new QSplitter(Qt::Vertical, this); + setCentralWidget(splitter); + + view = new WebViewTraditional(splitter); + view->setPage(page()); + +#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0) + view->installEventFilter(this); + touchMocking = false; +#endif + + 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&))); + + inspector = new WebInspector(splitter); + inspector->setPage(page()); + inspector->hide(); + connect(this, SIGNAL(destroyed()), inspector, SLOT(deleteLater())); + + setupUI(); + + // the zoom values are chosen to be like in Mozilla Firefox 3 + zoomLevels << 30 << 50 << 67 << 80 << 90; + zoomLevels << 100; + zoomLevels << 110 << 120 << 133 << 150 << 170 << 200 << 240 << 300; + + grabZoomKeys(true); + + load(url); +} + +LauncherWindow::~LauncherWindow() +{ + grabZoomKeys(false); +} + +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 (touchPoints.isEmpty()) + return; + + QEvent::Type type = QEvent::TouchUpdate; + if (touchPoints.size() == 1) { + if (touchPoints[0].state() == Qt::TouchPointReleased) + type = QEvent::TouchEnd; + else if (touchPoints[0].state() == Qt::TouchPointPressed) + type = QEvent::TouchBegin; + } + + QTouchEvent touchEv(type); + touchEv.setTouchPoints(touchPoints); + QCoreApplication::sendEvent(page(), &touchEv); + + // After sending the event, remove all touchpoints that were released + if (touchPoints[0].state() == Qt::TouchPointReleased) + touchPoints.removeAt(0); + if (touchPoints.size() > 1 && touchPoints[1].state() == Qt::TouchPointReleased) + touchPoints.removeAt(1); +} + +bool LauncherWindow::eventFilter(QObject* obj, QEvent* event) +{ + if (!touchMocking || obj != view) + 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 (touchPoints.size() > 0 && !touchPoints[0].id()) + touchPoints[0] = touchPoint; + else if (touchPoints.size() > 1 && !touchPoints[1].id()) + touchPoints[1] = touchPoint; + else + 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 touchPoints. + if (touchPoints.size() > 0 && touchPoints[0].id() == 1) { + touchPoints[0].setState(Qt::TouchPointReleased); + sendTouchEvent(); + } else if (touchPoints.size() > 1 && touchPoints[1].id() == 1) { + touchPoints[1].setState(Qt::TouchPointReleased); + sendTouchEvent(); + } else { + QTouchEvent::TouchPoint touchPoint; + touchPoint.setState(Qt::TouchPointPressed); + touchPoint.setId(1); + touchPoint.setScreenPos(QCursor::pos()); + touchPoint.setPos(view->mapFromGlobal(QCursor::pos())); + touchPoint.setPressure(1); + touchPoints.append(touchPoint); + sendTouchEvent(); + + // After sending the event, change the touchpoint state to stationary + touchPoints.last().setState(Qt::TouchPointStationary); + } + } + return false; +} +#endif // QT_VERSION >= QT_VERSION_CHECK(4, 6, 0) + +void LauncherWindow::loadStarted() +{ + view->setFocus(Qt::OtherFocusReason); +} + +void LauncherWindow::loadFinished() +{ + QUrl url = page()->mainFrame()->url(); + setAddressUrl(url.toString()); + 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::zoomIn() +{ + int i = zoomLevels.indexOf(currentZoom); + Q_ASSERT(i >= 0); + if (i < zoomLevels.count() - 1) + currentZoom = zoomLevels[i + 1]; + + page()->mainFrame()->setZoomFactor(qreal(currentZoom) / 100.0); +} + +void LauncherWindow::zoomOut() +{ + int i = zoomLevels.indexOf(currentZoom); + Q_ASSERT(i >= 0); + if (i > 0) + currentZoom = zoomLevels[i - 1]; + + page()->mainFrame()->setZoomFactor(qreal(currentZoom) / 100.0); +} + +void LauncherWindow::resetZoom() +{ + 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*)), + view, SLOT(print(QPrinter*))); + dlg.exec(); +#endif +} + +void LauncherWindow::screenshot() +{ + QPixmap pixmap = QPixmap::grabWidget(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) +{ + view->page()->setContentEditable(on); + 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) + touchMocking = on; +#endif +} + +void LauncherWindow::newWindow(const QString& url) +{ + LauncherWindow* mw = new LauncherWindow(url); + mw->show(); +} + +void LauncherWindow::setupUI() +{ + 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(view->pageAction(QWebPage::Stop)); + viewMenu->addAction(view->pageAction(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); + formatMenuAction = menuBar()->addMenu(formatMenu); + 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* toolsMenu = menuBar()->addMenu("&Develop"); + toolsMenu->addAction("Select Elements...", this, SLOT(selectElements())); + QAction* showInspectorAction = toolsMenu->addAction("Show Web Inspector", inspector, SLOT(setVisible(bool)), QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_I)); + showInspectorAction->setCheckable(true); + showInspectorAction->connect(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 +} + +QWebPage* WebPage::createWindow(QWebPage::WebWindowType) +{ + LauncherWindow* mw = new LauncherWindow; + 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 +} + + +#include "main.moc" + +int launcherMain(const QApplication& app) +{ +#ifndef NDEBUG + int retVal = app.exec(); + qt_drt_garbageCollector_collect(); + QWebSettings::clearMemoryCaches(); + return retVal; +#else + return app.exec(); +#endif +} + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + QString defaultUrl = QString("file://%1/%2").arg(QDir::homePath()).arg(QLatin1String("index.html")); + + QWebSettings::setMaximumPagesInCache(4); + + app.setApplicationName("QtLauncher"); + app.setApplicationVersion("0.1"); + + 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(); + + // To allow QWebInspector's configuration persistence + QCoreApplication::setOrganizationName("Nokia"); + QCoreApplication::setApplicationName("QtLauncher"); + + const QStringList args = app.arguments(); + + if (args.contains(QLatin1String("-r"))) { + // robotized + QString listFile = args.at(2); + if (!(args.count() == 3) && QFile::exists(listFile)) { + qDebug() << "Usage: QtLauncher -r listfile"; + exit(0); + } + LauncherWindow* window = new LauncherWindow; + QWebView* view = window->webView(); + UrlLoader loader(view->page()->mainFrame(), listFile); + QObject::connect(view->page()->mainFrame(), SIGNAL(loadFinished(bool)), &loader, SLOT(loadNext())); + loader.loadNext(); + window->show(); + launcherMain(app); + } else { + LauncherWindow* window = 0; + + // Look though the args for something we can open + for (int i = 1; i < args.count(); i++) { + if (!args.at(i).startsWith("-")) { + if (!window) + window = new LauncherWindow(args.at(i)); + else + window->newWindow(args.at(i)); + } + } + + // If not, just open the default URL + if (!window) + window = new LauncherWindow(defaultUrl); + + window->show(); + launcherMain(app); + } +} diff --git a/WebKitTools/QtLauncher/mainwindow.cpp b/WebKitTools/QtLauncher/mainwindow.cpp new file mode 100644 index 0000000..2662f5e --- /dev/null +++ b/WebKitTools/QtLauncher/mainwindow.cpp @@ -0,0 +1,151 @@ +/* + * 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 QT_VERSION >= QT_VERSION_CHECK(4, 5, 0) + if (qgetenv("QTLAUNCHER_USE_ARGB_VISUALS").toInt() == 1) + setAttribute(Qt::WA_TranslucentBackground); +#endif + + buildUI(); +} + +void MainWindow::buildUI() +{ + QToolBar* bar = addToolBar("Navigation"); + 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); + bar->addWidget(urlEdit); + + connect(page()->mainFrame(), SIGNAL(titleChanged(const QString&)), + this, SLOT(setWindowTitle(const QString&))); + 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 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 new file mode 100644 index 0000000..1a30a09 --- /dev/null +++ b/WebKitTools/QtLauncher/mainwindow.h @@ -0,0 +1,69 @@ +/* + * 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 setAddressUrl(const QString& url); + void addCompleterEntry(const QUrl& url); + + void load(const QString& url); + void load(const QUrl& url); + + WebPage* page(); + +protected slots: + 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 new file mode 100644 index 0000000..630ead6 --- /dev/null +++ b/WebKitTools/QtLauncher/urlloader.cpp @@ -0,0 +1,83 @@ +/* + * 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 new file mode 100644 index 0000000..ed14adc --- /dev/null +++ b/WebKitTools/QtLauncher/urlloader.h @@ -0,0 +1,58 @@ +/* + * 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/utils.cpp b/WebKitTools/QtLauncher/utils.cpp new file mode 100644 index 0000000..7013f46 --- /dev/null +++ b/WebKitTools/QtLauncher/utils.cpp @@ -0,0 +1,42 @@ +/* + * 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" + +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 new file mode 100644 index 0000000..afe771e --- /dev/null +++ b/WebKitTools/QtLauncher/utils.h @@ -0,0 +1,35 @@ +/* + * 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> + +QUrl urlFromUserInput(const QString& input); + +#endif diff --git a/WebKitTools/QtLauncher/webinspector.h b/WebKitTools/QtLauncher/webinspector.h new file mode 100644 index 0000000..d251c5c --- /dev/null +++ b/WebKitTools/QtLauncher/webinspector.h @@ -0,0 +1,56 @@ +/* + * 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 new file mode 100644 index 0000000..2fe1306 --- /dev/null +++ b/WebKitTools/QtLauncher/webpage.cpp @@ -0,0 +1,106 @@ +/* + * 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) +{ + 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); +} + + diff --git a/WebKitTools/QtLauncher/webpage.h b/WebKitTools/QtLauncher/webpage.h new file mode 100644 index 0000000..14a0571 --- /dev/null +++ b/WebKitTools/QtLauncher/webpage.h @@ -0,0 +1,59 @@ +/* + * 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); + +public slots: + void openUrlInDefaultBrowser(const QUrl& url = QUrl()); + +private: + void applyProxy(); +}; + +#endif diff --git a/WebKitTools/QtLauncher/webview.cpp b/WebKitTools/QtLauncher/webview.cpp new file mode 100644 index 0000000..d08da4c --- /dev/null +++ b/WebKitTools/QtLauncher/webview.cpp @@ -0,0 +1,81 @@ +/* + * 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> + +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 WebViewGraphicsBased::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 WebViewGraphicsBased::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 new file mode 100644 index 0000000..68f220e --- /dev/null +++ b/WebKitTools/QtLauncher/webview.h @@ -0,0 +1,62 @@ +/* + * 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 "webpage.h" +#include <qwebview.h> +#include <qgraphicswebview.h> + +class WebViewGraphicsBased : public QGraphicsWebView { + Q_OBJECT + +public: + WebViewGraphicsBased(QGraphicsItem* parent = 0) : QGraphicsWebView(parent) {}; + +protected: + virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent*); + virtual void mousePressEvent(QGraphicsSceneMouseEvent*); +}; + +class WebViewTraditional : public QWebView { + Q_OBJECT + +public: + WebViewTraditional(QWidget* parent) : QWebView(parent) {} + +protected: + virtual void contextMenuEvent(QContextMenuEvent*); + virtual void mousePressEvent(QMouseEvent*); +}; + +#endif |