Commit c696ef82 authored by kenneth@webkit.org's avatar kenneth@webkit.org

Rubberstamped by Oliver Hunt.

[Qt] Make it possible to choose whether the launcher should
use the traditional QWidget based QWebView or the newer
QGraphics based QGraphicsWebView on a QGraphicsView.

* QtLauncher/main.cpp:
(LauncherWindow::LauncherWindow):
(LauncherWindow::eventFilter):
(LauncherWindow::loadStarted):
(LauncherWindow::print):
(LauncherWindow::screenshot):
(LauncherWindow::setEditable):
(LauncherWindow::setupUI):
(main):
* QtLauncher/webview.cpp:
(WebViewGraphicsBased::WebViewGraphicsBased):
(WebViewGraphicsBased::resizeEvent):
(GraphicsWebView::mousePressEvent):
(GraphicsWebView::contextMenuEvent):
* QtLauncher/webview.h:
(WebViewTraditional::WebViewTraditional):
(GraphicsWebView::GraphicsWebView):
(WebViewGraphicsBased::setPage):

git-svn-id: svn://svn.chromium.org/blink/trunk@54416 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 90e6d0c7
......@@ -9,6 +9,33 @@
Teach the script how to detect weak external symbols so that these errors can be caught immediately
in the future.
2010-02-04 Kenneth Rohde Christiansen <kenneth@webkit.org>
Rubberstamped by Oliver Hunt.
[Qt] Make it possible to choose whether the launcher should
use the traditional QWidget based QWebView or the newer
QGraphics based QGraphicsWebView on a QGraphicsView.
* QtLauncher/main.cpp:
(LauncherWindow::LauncherWindow):
(LauncherWindow::eventFilter):
(LauncherWindow::loadStarted):
(LauncherWindow::print):
(LauncherWindow::screenshot):
(LauncherWindow::setEditable):
(LauncherWindow::setupUI):
(main):
* QtLauncher/webview.cpp:
(WebViewGraphicsBased::WebViewGraphicsBased):
(WebViewGraphicsBased::resizeEvent):
(GraphicsWebView::mousePressEvent):
(GraphicsWebView::contextMenuEvent):
* QtLauncher/webview.h:
(WebViewTraditional::WebViewTraditional):
(GraphicsWebView::GraphicsWebView):
(WebViewGraphicsBased::setPage):
2010-02-04 Kenneth Rohde Christiansen <kenneth@webkit.org>
Rubberstamped by Oliver Hunt.
......
......@@ -70,6 +70,8 @@
void QWEBKIT_EXPORT qt_drt_garbageCollector_collect();
#endif
static bool useGraphicsView = false;
class LauncherWindow : public MainWindow {
Q_OBJECT
......@@ -85,8 +87,6 @@ public:
bool eventFilter(QObject* obj, QEvent* event);
#endif
QWebView* webView() const { return view; }
protected slots:
void loadStarted();
void loadFinished();
......@@ -121,7 +121,7 @@ private:
QVector<int> zoomLevels;
int currentZoom;
QWebView* view;
QWidget* m_view;
WebInspector* inspector;
QAction* formatMenuAction;
......@@ -140,11 +140,20 @@ LauncherWindow::LauncherWindow(QString url)
QSplitter* splitter = new QSplitter(Qt::Vertical, this);
setCentralWidget(splitter);
view = new WebViewTraditional(splitter);
view->setPage(page());
resize(800, 600);
if (!useGraphicsView) {
WebViewTraditional* view = new WebViewTraditional(splitter);
view->setPage(page());
m_view = view;
} else {
WebViewGraphicsBased* view = new WebViewGraphicsBased(splitter);
view->setPage(page());
m_view = view;
}
#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
view->installEventFilter(this);
m_view->installEventFilter(this);
touchMocking = false;
#endif
......@@ -238,7 +247,7 @@ void LauncherWindow::sendTouchEvent()
bool LauncherWindow::eventFilter(QObject* obj, QEvent* event)
{
if (!touchMocking || obj != view)
if (!touchMocking || obj != m_view)
return QObject::eventFilter(obj, event);
if (event->type() == QEvent::MouseButtonPress
......@@ -290,7 +299,7 @@ bool LauncherWindow::eventFilter(QObject* obj, QEvent* event)
touchPoint.setState(Qt::TouchPointPressed);
touchPoint.setId(1);
touchPoint.setScreenPos(QCursor::pos());
touchPoint.setPos(view->mapFromGlobal(QCursor::pos()));
touchPoint.setPos(m_view->mapFromGlobal(QCursor::pos()));
touchPoint.setPressure(1);
touchPoints.append(touchPoint);
sendTouchEvent();
......@@ -305,7 +314,7 @@ bool LauncherWindow::eventFilter(QObject* obj, QEvent* event)
void LauncherWindow::loadStarted()
{
view->setFocus(Qt::OtherFocusReason);
m_view->setFocus(Qt::OtherFocusReason);
}
void LauncherWindow::loadFinished()
......@@ -362,14 +371,14 @@ void LauncherWindow::print()
#if !defined(QT_NO_PRINTER)
QPrintPreviewDialog dlg(this);
connect(&dlg, SIGNAL(paintRequested(QPrinter*)),
view, SLOT(print(QPrinter*)));
m_view, SLOT(print(QPrinter*)));
dlg.exec();
#endif
}
void LauncherWindow::screenshot()
{
QPixmap pixmap = QPixmap::grabWidget(view);
QPixmap pixmap = QPixmap::grabWidget(m_view);
QLabel* label = new QLabel;
label->setAttribute(Qt::WA_DeleteOnClose);
label->setWindowTitle("Screenshot - Preview");
......@@ -385,7 +394,7 @@ void LauncherWindow::screenshot()
void LauncherWindow::setEditable(bool on)
{
view->page()->setContentEditable(on);
page()->setContentEditable(on);
formatMenuAction->setVisible(on);
}
......@@ -459,8 +468,8 @@ void LauncherWindow::setupUI()
setEditable->setCheckable(true);
QMenu* viewMenu = menuBar()->addMenu("&View");
viewMenu->addAction(view->pageAction(QWebPage::Stop));
viewMenu->addAction(view->pageAction(QWebPage::Reload));
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()));
......@@ -579,7 +588,6 @@ LauncherApplication::LauncherApplication(int& argc, char** argv)
handleUserOptions();
}
static bool useGraphicsView = false;
static void requiresGraphicsView(const QString& option)
{
if (useGraphicsView)
......@@ -660,10 +668,9 @@ int main(int argc, char **argv)
LauncherApplication app(argc, argv);
if (app.isRobotized()) {
LauncherWindow* window = new LauncherWindow;
QWebView* view = window->webView();
UrlLoader loader(view->page()->mainFrame(), app.urls().at(0));
QObject::connect(view->page()->mainFrame(), SIGNAL(loadFinished(bool)), &loader, SLOT(loadNext()));
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);
......
......@@ -33,6 +33,26 @@
#include "webview.h"
#include <QtGui>
#include <QGraphicsScene>
WebViewGraphicsBased::WebViewGraphicsBased(QWidget* parent)
: QGraphicsView(parent)
, m_item(new GraphicsWebView)
{
setScene(new QGraphicsScene);
scene()->addItem(m_item);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}
void WebViewGraphicsBased::resizeEvent(QResizeEvent* event)
{
QGraphicsView::resizeEvent(event);
QRectF rect(QPoint(0, 0), event->size());
m_item->setGeometry(rect);
}
static QMenu* createContextMenu(QWebPage* page, QPoint position)
{
......@@ -49,7 +69,7 @@ static QMenu* createContextMenu(QWebPage* page, QPoint position)
return menu;
}
void WebViewGraphicsBased::mousePressEvent(QGraphicsSceneMouseEvent* event)
void GraphicsWebView::mousePressEvent(QGraphicsSceneMouseEvent* event)
{
setProperty("mouseButtons", QVariant::fromValue(int(event->buttons())));
setProperty("keyboardModifiers", QVariant::fromValue(int(event->modifiers())));
......@@ -65,7 +85,7 @@ void WebViewTraditional::mousePressEvent(QMouseEvent* event)
QWebView::mousePressEvent(event);
}
void WebViewGraphicsBased::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
void GraphicsWebView::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
{
QMenu* menu = createContextMenu(page(), event->pos().toPoint());
menu->exec(mapToScene(event->pos()).toPoint());
......
......@@ -36,27 +36,43 @@
#include "webpage.h"
#include <qwebview.h>
#include <qgraphicswebview.h>
#include <QGraphicsView>
#include <QGraphicsWidget>
class WebViewGraphicsBased : public QGraphicsWebView {
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:
WebViewGraphicsBased(QGraphicsItem* parent = 0) : QGraphicsWebView(parent) {};
GraphicsWebView(QGraphicsItem* parent = 0) : QGraphicsWebView(parent) {};
protected:
virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent*);
virtual void mousePressEvent(QGraphicsSceneMouseEvent*);
};
class WebViewTraditional : public QWebView {
class WebViewGraphicsBased : public QGraphicsView {
Q_OBJECT
public:
WebViewTraditional(QWidget* parent) : QWebView(parent) {}
WebViewGraphicsBased(QWidget* parent);
virtual void resizeEvent(QResizeEvent*);
void setPage(QWebPage* page) { m_item->setPage(page); }
protected:
virtual void contextMenuEvent(QContextMenuEvent*);
virtual void mousePressEvent(QMouseEvent*);
private:
GraphicsWebView* m_item;
};
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment