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 @@ ...@@ -9,6 +9,33 @@
Teach the script how to detect weak external symbols so that these errors can be caught immediately Teach the script how to detect weak external symbols so that these errors can be caught immediately
in the future. 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> 2010-02-04 Kenneth Rohde Christiansen <kenneth@webkit.org>
Rubberstamped by Oliver Hunt. Rubberstamped by Oliver Hunt.
......
...@@ -70,6 +70,8 @@ ...@@ -70,6 +70,8 @@
void QWEBKIT_EXPORT qt_drt_garbageCollector_collect(); void QWEBKIT_EXPORT qt_drt_garbageCollector_collect();
#endif #endif
static bool useGraphicsView = false;
class LauncherWindow : public MainWindow { class LauncherWindow : public MainWindow {
Q_OBJECT Q_OBJECT
...@@ -85,8 +87,6 @@ public: ...@@ -85,8 +87,6 @@ public:
bool eventFilter(QObject* obj, QEvent* event); bool eventFilter(QObject* obj, QEvent* event);
#endif #endif
QWebView* webView() const { return view; }
protected slots: protected slots:
void loadStarted(); void loadStarted();
void loadFinished(); void loadFinished();
...@@ -121,7 +121,7 @@ private: ...@@ -121,7 +121,7 @@ private:
QVector<int> zoomLevels; QVector<int> zoomLevels;
int currentZoom; int currentZoom;
QWebView* view; QWidget* m_view;
WebInspector* inspector; WebInspector* inspector;
QAction* formatMenuAction; QAction* formatMenuAction;
...@@ -140,11 +140,20 @@ LauncherWindow::LauncherWindow(QString url) ...@@ -140,11 +140,20 @@ LauncherWindow::LauncherWindow(QString url)
QSplitter* splitter = new QSplitter(Qt::Vertical, this); QSplitter* splitter = new QSplitter(Qt::Vertical, this);
setCentralWidget(splitter); setCentralWidget(splitter);
view = new WebViewTraditional(splitter); resize(800, 600);
view->setPage(page());
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) #if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
view->installEventFilter(this); m_view->installEventFilter(this);
touchMocking = false; touchMocking = false;
#endif #endif
...@@ -238,7 +247,7 @@ void LauncherWindow::sendTouchEvent() ...@@ -238,7 +247,7 @@ void LauncherWindow::sendTouchEvent()
bool LauncherWindow::eventFilter(QObject* obj, QEvent* event) bool LauncherWindow::eventFilter(QObject* obj, QEvent* event)
{ {
if (!touchMocking || obj != view) if (!touchMocking || obj != m_view)
return QObject::eventFilter(obj, event); return QObject::eventFilter(obj, event);
if (event->type() == QEvent::MouseButtonPress if (event->type() == QEvent::MouseButtonPress
...@@ -290,7 +299,7 @@ bool LauncherWindow::eventFilter(QObject* obj, QEvent* event) ...@@ -290,7 +299,7 @@ bool LauncherWindow::eventFilter(QObject* obj, QEvent* event)
touchPoint.setState(Qt::TouchPointPressed); touchPoint.setState(Qt::TouchPointPressed);
touchPoint.setId(1); touchPoint.setId(1);
touchPoint.setScreenPos(QCursor::pos()); touchPoint.setScreenPos(QCursor::pos());
touchPoint.setPos(view->mapFromGlobal(QCursor::pos())); touchPoint.setPos(m_view->mapFromGlobal(QCursor::pos()));
touchPoint.setPressure(1); touchPoint.setPressure(1);
touchPoints.append(touchPoint); touchPoints.append(touchPoint);
sendTouchEvent(); sendTouchEvent();
...@@ -305,7 +314,7 @@ bool LauncherWindow::eventFilter(QObject* obj, QEvent* event) ...@@ -305,7 +314,7 @@ bool LauncherWindow::eventFilter(QObject* obj, QEvent* event)
void LauncherWindow::loadStarted() void LauncherWindow::loadStarted()
{ {
view->setFocus(Qt::OtherFocusReason); m_view->setFocus(Qt::OtherFocusReason);
} }
void LauncherWindow::loadFinished() void LauncherWindow::loadFinished()
...@@ -362,14 +371,14 @@ void LauncherWindow::print() ...@@ -362,14 +371,14 @@ void LauncherWindow::print()
#if !defined(QT_NO_PRINTER) #if !defined(QT_NO_PRINTER)
QPrintPreviewDialog dlg(this); QPrintPreviewDialog dlg(this);
connect(&dlg, SIGNAL(paintRequested(QPrinter*)), connect(&dlg, SIGNAL(paintRequested(QPrinter*)),
view, SLOT(print(QPrinter*))); m_view, SLOT(print(QPrinter*)));
dlg.exec(); dlg.exec();
#endif #endif
} }
void LauncherWindow::screenshot() void LauncherWindow::screenshot()
{ {
QPixmap pixmap = QPixmap::grabWidget(view); QPixmap pixmap = QPixmap::grabWidget(m_view);
QLabel* label = new QLabel; QLabel* label = new QLabel;
label->setAttribute(Qt::WA_DeleteOnClose); label->setAttribute(Qt::WA_DeleteOnClose);
label->setWindowTitle("Screenshot - Preview"); label->setWindowTitle("Screenshot - Preview");
...@@ -385,7 +394,7 @@ void LauncherWindow::screenshot() ...@@ -385,7 +394,7 @@ void LauncherWindow::screenshot()
void LauncherWindow::setEditable(bool on) void LauncherWindow::setEditable(bool on)
{ {
view->page()->setContentEditable(on); page()->setContentEditable(on);
formatMenuAction->setVisible(on); formatMenuAction->setVisible(on);
} }
...@@ -459,8 +468,8 @@ void LauncherWindow::setupUI() ...@@ -459,8 +468,8 @@ void LauncherWindow::setupUI()
setEditable->setCheckable(true); setEditable->setCheckable(true);
QMenu* viewMenu = menuBar()->addMenu("&View"); QMenu* viewMenu = menuBar()->addMenu("&View");
viewMenu->addAction(view->pageAction(QWebPage::Stop)); viewMenu->addAction(page()->action(QWebPage::Stop));
viewMenu->addAction(view->pageAction(QWebPage::Reload)); viewMenu->addAction(page()->action(QWebPage::Reload));
viewMenu->addSeparator(); viewMenu->addSeparator();
QAction* zoomIn = viewMenu->addAction("Zoom &In", this, SLOT(zoomIn())); QAction* zoomIn = viewMenu->addAction("Zoom &In", this, SLOT(zoomIn()));
QAction* zoomOut = viewMenu->addAction("Zoom &Out", this, SLOT(zoomOut())); QAction* zoomOut = viewMenu->addAction("Zoom &Out", this, SLOT(zoomOut()));
...@@ -579,7 +588,6 @@ LauncherApplication::LauncherApplication(int& argc, char** argv) ...@@ -579,7 +588,6 @@ LauncherApplication::LauncherApplication(int& argc, char** argv)
handleUserOptions(); handleUserOptions();
} }
static bool useGraphicsView = false;
static void requiresGraphicsView(const QString& option) static void requiresGraphicsView(const QString& option)
{ {
if (useGraphicsView) if (useGraphicsView)
...@@ -660,10 +668,9 @@ int main(int argc, char **argv) ...@@ -660,10 +668,9 @@ int main(int argc, char **argv)
LauncherApplication app(argc, argv); LauncherApplication app(argc, argv);
if (app.isRobotized()) { if (app.isRobotized()) {
LauncherWindow* window = new LauncherWindow; LauncherWindow* window = new LauncherWindow();
QWebView* view = window->webView(); UrlLoader loader(window->page()->mainFrame(), app.urls().at(0));
UrlLoader loader(view->page()->mainFrame(), app.urls().at(0)); QObject::connect(window->page()->mainFrame(), SIGNAL(loadFinished(bool)), &loader, SLOT(loadNext()));
QObject::connect(view->page()->mainFrame(), SIGNAL(loadFinished(bool)), &loader, SLOT(loadNext()));
loader.loadNext(); loader.loadNext();
window->show(); window->show();
return launcherMain(app); return launcherMain(app);
......
...@@ -33,6 +33,26 @@ ...@@ -33,6 +33,26 @@
#include "webview.h" #include "webview.h"
#include <QtGui> #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) static QMenu* createContextMenu(QWebPage* page, QPoint position)
{ {
...@@ -49,7 +69,7 @@ static QMenu* createContextMenu(QWebPage* page, QPoint position) ...@@ -49,7 +69,7 @@ static QMenu* createContextMenu(QWebPage* page, QPoint position)
return menu; return menu;
} }
void WebViewGraphicsBased::mousePressEvent(QGraphicsSceneMouseEvent* event) void GraphicsWebView::mousePressEvent(QGraphicsSceneMouseEvent* event)
{ {
setProperty("mouseButtons", QVariant::fromValue(int(event->buttons()))); setProperty("mouseButtons", QVariant::fromValue(int(event->buttons())));
setProperty("keyboardModifiers", QVariant::fromValue(int(event->modifiers()))); setProperty("keyboardModifiers", QVariant::fromValue(int(event->modifiers())));
...@@ -65,7 +85,7 @@ void WebViewTraditional::mousePressEvent(QMouseEvent* event) ...@@ -65,7 +85,7 @@ void WebViewTraditional::mousePressEvent(QMouseEvent* event)
QWebView::mousePressEvent(event); QWebView::mousePressEvent(event);
} }
void WebViewGraphicsBased::contextMenuEvent(QGraphicsSceneContextMenuEvent* event) void GraphicsWebView::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
{ {
QMenu* menu = createContextMenu(page(), event->pos().toPoint()); QMenu* menu = createContextMenu(page(), event->pos().toPoint());
menu->exec(mapToScene(event->pos()).toPoint()); menu->exec(mapToScene(event->pos()).toPoint());
......
...@@ -36,27 +36,43 @@ ...@@ -36,27 +36,43 @@
#include "webpage.h" #include "webpage.h"
#include <qwebview.h> #include <qwebview.h>
#include <qgraphicswebview.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 Q_OBJECT
public: public:
WebViewGraphicsBased(QGraphicsItem* parent = 0) : QGraphicsWebView(parent) {}; GraphicsWebView(QGraphicsItem* parent = 0) : QGraphicsWebView(parent) {};
protected: protected:
virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent*); virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent*);
virtual void mousePressEvent(QGraphicsSceneMouseEvent*); virtual void mousePressEvent(QGraphicsSceneMouseEvent*);
}; };
class WebViewTraditional : public QWebView {
class WebViewGraphicsBased : public QGraphicsView {
Q_OBJECT Q_OBJECT
public: public:
WebViewTraditional(QWidget* parent) : QWebView(parent) {} WebViewGraphicsBased(QWidget* parent);
virtual void resizeEvent(QResizeEvent*);
void setPage(QWebPage* page) { m_item->setPage(page); }
protected: private:
virtual void contextMenuEvent(QContextMenuEvent*); GraphicsWebView* m_item;
virtual void mousePressEvent(QMouseEvent*);
}; };
#endif #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