summaryrefslogtreecommitdiffstats
path: root/WebKitTools/QtTestBrowser
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2010-08-11 14:44:44 +0100
committerBen Murdoch <benm@google.com>2010-08-12 19:15:41 +0100
commitdd8bb3de4f353a81954234999f1fea748aee2ea9 (patch)
tree729b52bf09294f0d6c67cd5ea80aee1b727b7bd8 /WebKitTools/QtTestBrowser
parentf3d41ba51d86bf719c7a65ab5297aea3c17e2d98 (diff)
downloadexternal_webkit-dd8bb3de4f353a81954234999f1fea748aee2ea9.zip
external_webkit-dd8bb3de4f353a81954234999f1fea748aee2ea9.tar.gz
external_webkit-dd8bb3de4f353a81954234999f1fea748aee2ea9.tar.bz2
Merge WebKit at r65072 : Initial merge by git.
Change-Id: Ibcf418498376b2660aacb7f8d46ea7085ef91585
Diffstat (limited to 'WebKitTools/QtTestBrowser')
-rw-r--r--WebKitTools/QtTestBrowser/launcherwindow.cpp197
-rw-r--r--WebKitTools/QtTestBrowser/launcherwindow.h67
-rw-r--r--WebKitTools/QtTestBrowser/main.cpp22
-rw-r--r--WebKitTools/QtTestBrowser/webview.cpp49
-rw-r--r--WebKitTools/QtTestBrowser/webview.h6
5 files changed, 186 insertions, 155 deletions
diff --git a/WebKitTools/QtTestBrowser/launcherwindow.cpp b/WebKitTools/QtTestBrowser/launcherwindow.cpp
index 177adea..095a984 100644
--- a/WebKitTools/QtTestBrowser/launcherwindow.cpp
+++ b/WebKitTools/QtTestBrowser/launcherwindow.cpp
@@ -32,48 +32,25 @@
#include "launcherwindow.h"
-bool LauncherWindow::gUseGraphicsView = false;
-bool LauncherWindow::gUseCompositing = true;
-bool LauncherWindow::gCacheWebView = false;
-bool LauncherWindow::gShowFrameRate = false;
-bool LauncherWindow::gResizesToContents = false;
-bool LauncherWindow::gUseTiledBackingStore = false;
-QGraphicsView::ViewportUpdateMode LauncherWindow::gViewportUpdateMode = QGraphicsView::MinimalViewportUpdate;
-QUrl LauncherWindow::gInspectorUrl;
-
-#if defined(Q_WS_MAEMO_5) || defined(Q_WS_S60)
-bool LauncherWindow::gUseFrameFlattening = true;
-#else
-bool LauncherWindow::gUseFrameFlattening = false;
-#endif
+const int gExitClickArea = 80;
+QVector<int> LauncherWindow::m_zoomLevels;
-#if defined(QT_CONFIGURED_WITH_OPENGL)
-bool LauncherWindow::gUseQGLWidgetViewport = false;
-#endif
-
-LauncherWindow::LauncherWindow(LauncherWindow* other, bool shareScene)
+LauncherWindow::LauncherWindow(WindowOptions* data, QGraphicsScene* sharedScene)
: 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();
- }
+ if (data)
+ m_windowOptions = *data;
+
+ init();
+ if (sharedScene && data->useGraphicsView)
+ static_cast<QGraphicsView*>(m_view)->setScene(sharedScene);
createChrome();
}
@@ -83,7 +60,7 @@ LauncherWindow::~LauncherWindow()
grabZoomKeys(false);
}
-void LauncherWindow::init(bool useGraphicsView)
+void LauncherWindow::init()
{
QSplitter* splitter = new QSplitter(Qt::Vertical, this);
setCentralWidget(splitter);
@@ -95,7 +72,7 @@ void LauncherWindow::init(bool useGraphicsView)
resize(800, 600);
#endif
- initializeView(useGraphicsView);
+ initializeView();
connect(page(), SIGNAL(loadStarted()), this, SLOT(loadStarted()));
connect(page(), SIGNAL(loadFinished(bool)), this, SLOT(loadFinished()));
@@ -103,30 +80,34 @@ void LauncherWindow::init(bool useGraphicsView)
this, SLOT(showLinkHover(const QString&, const QString&)));
connect(this, SIGNAL(enteredFullScreenMode(bool)), this, SLOT(toggleFullScreenMode(bool)));
+ applyPrefs();
+
m_inspector = new WebInspector(splitter);
#ifndef QT_NO_PROPERTIES
- if (!gInspectorUrl.isEmpty())
- m_inspector->setProperty("_q_inspectorUrl", gInspectorUrl);
+ if (!m_windowOptions.inspectorUrl.isEmpty())
+ m_inspector->setProperty("_q_inspectorUrl", m_windowOptions.inspectorUrl);
#endif
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;
+ if (!m_zoomLevels.count()) {
+ m_zoomLevels << 30 << 50 << 67 << 80 << 90;
+ m_zoomLevels << 100;
+ m_zoomLevels << 110 << 120 << 133 << 150 << 170 << 200 << 240 << 300;
+ }
grabZoomKeys(true);
}
-void LauncherWindow::initializeView(bool useGraphicsView)
+void LauncherWindow::initializeView()
{
delete m_view;
QSplitter* splitter = static_cast<QSplitter*>(centralWidget());
- if (!useGraphicsView) {
+ if (!m_windowOptions.useGraphicsView) {
WebViewTraditional* view = new WebViewTraditional(splitter);
view->setPage(page());
@@ -137,12 +118,6 @@ void LauncherWindow::initializeView(bool useGraphicsView)
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);
@@ -158,6 +133,26 @@ void LauncherWindow::initializeView(bool useGraphicsView)
#endif
}
+void LauncherWindow::applyPrefs()
+{
+ QWebSettings* settings = page()->settings();
+ settings->setAttribute(QWebSettings::AcceleratedCompositingEnabled, m_windowOptions.useCompositing);
+ settings->setAttribute(QWebSettings::TiledBackingStoreEnabled, m_windowOptions.useTiledBackingStore);
+ settings->setAttribute(QWebSettings::FrameFlatteningEnabled, m_windowOptions.useFrameFlattening);
+ settings->setAttribute(QWebSettings::WebGLEnabled, m_windowOptions.useWebGL);
+
+ if (!isGraphicsBased())
+ return;
+
+ WebViewGraphicsBased* view = static_cast<WebViewGraphicsBased*>(m_view);
+ view->setViewportUpdateMode(m_windowOptions.viewportUpdateMode);
+ view->setFrameRateMeasurementEnabled(m_windowOptions.showFrameRate);
+ view->setItemCacheMode(m_windowOptions.cacheWebView ? QGraphicsItem::DeviceCoordinateCache : QGraphicsItem::NoCache);
+
+ if (m_windowOptions.resizesToContents)
+ toggleResizesToContents(m_windowOptions.resizesToContents);
+}
+
void LauncherWindow::createChrome()
{
QMenu* fileMenu = menuBar()->addMenu("&File");
@@ -196,6 +191,10 @@ void LauncherWindow::createChrome()
viewMenu->addAction("Dump HTML", this, SLOT(dumpHtml()));
// viewMenu->addAction("Dump plugins", this, SLOT(dumpPlugins()));
+ 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* formatMenu = new QMenu("F&ormat", this);
m_formatMenuAction = menuBar()->addMenu(formatMenu);
m_formatMenuAction->setVisible(false);
@@ -207,25 +206,19 @@ void LauncherWindow::createChrome()
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
+ // 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");
-
QWebSettings* settings = page()->settings();
+ QMenu* toolsMenu = menuBar()->addMenu("&Develop");
QMenu* graphicsViewMenu = toolsMenu->addMenu("QGraphicsView");
- QAction* toggleGraphicsView = graphicsViewMenu->addAction("Toggle use of QGraphicsView", this, SLOT(initializeView(bool)));
+ QAction* toggleGraphicsView = graphicsViewMenu->addAction("Toggle use of QGraphicsView", this, SLOT(initializeView()));
toggleGraphicsView->setCheckable(true);
toggleGraphicsView->setChecked(isGraphicsBased());
@@ -242,7 +235,7 @@ void LauncherWindow::createChrome()
toggleFrameFlattening->setChecked(settings->testAttribute(QWebSettings::FrameFlatteningEnabled));
#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
- QAction* touchMockAction = toolsMenu->addAction("Toggle multitouch mocking", this, SLOT(setTouchMocking(bool)));
+ QAction* touchMockAction = toolsMenu->addAction("Toggle touch mocking", this, SLOT(setTouchMocking(bool)));
touchMockAction->setCheckable(true);
touchMockAction->setShortcut(QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_T));
#endif
@@ -277,20 +270,20 @@ void LauncherWindow::createChrome()
QAction* toggleResizesToContents = graphicsViewMenu->addAction("Toggle Resizes To Contents Mode", this, SLOT(toggleResizesToContents(bool)));
toggleResizesToContents->setCheckable(true);
- toggleResizesToContents->setChecked(gResizesToContents);
+ toggleResizesToContents->setChecked(m_windowOptions.resizesToContents);
toggleResizesToContents->setEnabled(isGraphicsBased());
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->setChecked(m_windowOptions.useTiledBackingStore);
toggleTiledBackingStore->setEnabled(isGraphicsBased());
toggleTiledBackingStore->connect(toggleGraphicsView, SIGNAL(toggled(bool)), SLOT(setEnabled(bool)));
#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->setChecked(m_windowOptions.useQGLWidgetViewport);
toggleQGLWidgetViewport->setEnabled(isGraphicsBased());
toggleQGLWidgetViewport->connect(toggleGraphicsView, SIGNAL(toggled(bool)), SLOT(setEnabled(bool)));
#endif
@@ -301,23 +294,23 @@ void LauncherWindow::createChrome()
QAction* fullUpdate = viewportUpdateMenu->addAction("FullViewportUpdate");
fullUpdate->setCheckable(true);
- fullUpdate->setChecked((gViewportUpdateMode == QGraphicsView::FullViewportUpdate) ? true : false);
+ fullUpdate->setChecked((m_windowOptions.viewportUpdateMode == QGraphicsView::FullViewportUpdate) ? true : false);
QAction* minimalUpdate = viewportUpdateMenu->addAction("MinimalViewportUpdate");
minimalUpdate->setCheckable(true);
- minimalUpdate->setChecked((gViewportUpdateMode == QGraphicsView::MinimalViewportUpdate) ? true : false);
+ minimalUpdate->setChecked((m_windowOptions.viewportUpdateMode == QGraphicsView::MinimalViewportUpdate) ? true : false);
QAction* smartUpdate = viewportUpdateMenu->addAction("SmartViewportUpdate");
smartUpdate->setCheckable(true);
- smartUpdate->setChecked((gViewportUpdateMode == QGraphicsView::SmartViewportUpdate) ? true : false);
+ smartUpdate->setChecked((m_windowOptions.viewportUpdateMode == QGraphicsView::SmartViewportUpdate) ? true : false);
QAction* boundingRectUpdate = viewportUpdateMenu->addAction("BoundingRectViewportUpdate");
boundingRectUpdate->setCheckable(true);
- boundingRectUpdate->setChecked((gViewportUpdateMode == QGraphicsView::BoundingRectViewportUpdate) ? true : false);
+ boundingRectUpdate->setChecked((m_windowOptions.viewportUpdateMode == QGraphicsView::BoundingRectViewportUpdate) ? true : false);
QAction* noUpdate = viewportUpdateMenu->addAction("NoViewportUpdate");
noUpdate->setCheckable(true);
- noUpdate->setChecked((gViewportUpdateMode == QGraphicsView::NoViewportUpdate) ? true : false);
+ noUpdate->setChecked((m_windowOptions.viewportUpdateMode == QGraphicsView::NoViewportUpdate) ? true : false);
QSignalMapper* signalMapper = new QSignalMapper(viewportUpdateMenu);
signalMapper->setMapping(fullUpdate, QGraphicsView::FullViewportUpdate);
@@ -343,18 +336,18 @@ void LauncherWindow::createChrome()
graphicsViewMenu->addSeparator();
- m_flipAnimated = graphicsViewMenu->addAction("Animated Flip");
- m_flipAnimated->connect(toggleGraphicsView, SIGNAL(toggled(bool)), SLOT(setEnabled(bool)));
- m_flipAnimated->setEnabled(isGraphicsBased());
+ QAction* flipAnimated = graphicsViewMenu->addAction("Animated Flip");
+ flipAnimated->connect(toggleGraphicsView, SIGNAL(toggled(bool)), SLOT(setEnabled(bool)));
+ flipAnimated->setEnabled(isGraphicsBased());
- m_flipYAnimated = graphicsViewMenu->addAction("Animated Y-Flip");
- m_flipYAnimated->connect(toggleGraphicsView, SIGNAL(toggled(bool)), SLOT(setEnabled(bool)));
- m_flipYAnimated->setEnabled(isGraphicsBased());
+ QAction* flipYAnimated = graphicsViewMenu->addAction("Animated Y-Flip");
+ flipYAnimated->connect(toggleGraphicsView, SIGNAL(toggled(bool)), SLOT(setEnabled(bool)));
+ 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()));
+ connect(flipAnimated, SIGNAL(triggered()), view, SLOT(animatedFlip()));
+ connect(flipYAnimated, SIGNAL(triggered()), view, SLOT(animatedYFlip()));
}
QAction* cloneWindow = graphicsViewMenu->addAction("Clone Window", this, SLOT(cloneWindow()));
@@ -367,7 +360,7 @@ void LauncherWindow::createChrome()
showFPS->setCheckable(true);
showFPS->setEnabled(isGraphicsBased());
showFPS->connect(toggleGraphicsView, SIGNAL(toggled(bool)), SLOT(setEnabled(bool)));
- showFPS->setChecked(gShowFrameRate);
+ showFPS->setChecked(m_windowOptions.showFrameRate);
}
bool LauncherWindow::isGraphicsBased() const
@@ -375,39 +368,6 @@ 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());
- view->setResizesToContents(otherView->resizesToContents());
- } else {
- view->setItemCacheMode(gCacheWebView ? QGraphicsItem::DeviceCoordinateCache : QGraphicsItem::NoCache);
- view->setResizesToContents(gResizesToContents);
- }
-}
-
void LauncherWindow::keyPressEvent(QKeyEvent* event)
{
#ifdef Q_WS_MAEMO_5
@@ -629,7 +589,7 @@ void LauncherWindow::zoomOut()
void LauncherWindow::resetZoom()
{
m_currentZoom = 100;
- page()->mainFrame()->setZoomFactor(1.0);
+ applyZoom();
}
void LauncherWindow::toggleZoomTextOnly(bool b)
@@ -711,7 +671,7 @@ void LauncherWindow::setTouchMocking(bool on)
void LauncherWindow::toggleAcceleratedCompositing(bool toggle)
{
- gUseCompositing = toggle;
+ m_windowOptions.useCompositing = toggle;
page()->settings()->setAttribute(QWebSettings::AcceleratedCompositingEnabled, toggle);
}
@@ -722,12 +682,13 @@ void LauncherWindow::toggleTiledBackingStore(bool toggle)
void LauncherWindow::toggleResizesToContents(bool toggle)
{
- gResizesToContents = toggle;
+ m_windowOptions.resizesToContents = toggle;
static_cast<WebViewGraphicsBased*>(m_view)->setResizesToContents(toggle);
}
void LauncherWindow::toggleWebGL(bool toggle)
{
+ m_windowOptions.useWebGL = toggle;
page()->settings()->setAttribute(QWebSettings::WebGLEnabled, toggle);
}
@@ -751,7 +712,7 @@ void LauncherWindow::toggleFullScreenMode(bool enable)
void LauncherWindow::toggleFrameFlattening(bool toggle)
{
- gUseFrameFlattening = toggle;
+ m_windowOptions.useFrameFlattening = toggle;
page()->settings()->setAttribute(QWebSettings::FrameFlatteningEnabled, toggle);
}
@@ -771,7 +732,7 @@ void LauncherWindow::toggleQGLWidgetViewport(bool enable)
if (!isGraphicsBased())
return;
- gUseQGLWidgetViewport = enable;
+ m_windowOptions.useQGLWidgetViewport = enable;
WebViewGraphicsBased* view = static_cast<WebViewGraphicsBased*>(m_view);
view->setViewport(enable ? new QGLWidget() : 0);
@@ -780,13 +741,13 @@ void LauncherWindow::toggleQGLWidgetViewport(bool enable)
void LauncherWindow::changeViewportUpdateMode(int mode)
{
- gViewportUpdateMode = QGraphicsView::ViewportUpdateMode(mode);
+ m_windowOptions.viewportUpdateMode = QGraphicsView::ViewportUpdateMode(mode);
if (!isGraphicsBased())
return;
WebViewGraphicsBased* view = static_cast<WebViewGraphicsBased*>(m_view);
- view->setViewportUpdateMode(gViewportUpdateMode);
+ view->setViewportUpdateMode(m_windowOptions.viewportUpdateMode);
}
void LauncherWindow::showFPS(bool enable)
@@ -794,7 +755,7 @@ void LauncherWindow::showFPS(bool enable)
if (!isGraphicsBased())
return;
- gShowFrameRate = enable;
+ m_windowOptions.showFrameRate = enable;
WebViewGraphicsBased* view = static_cast<WebViewGraphicsBased*>(m_view);
view->setFrameRateMeasurementEnabled(enable);
@@ -867,14 +828,14 @@ void LauncherWindow::updateFPS(int fps)
LauncherWindow* LauncherWindow::newWindow()
{
- LauncherWindow* mw = new LauncherWindow(this, false);
+ LauncherWindow* mw = new LauncherWindow(&m_windowOptions);
mw->show();
return mw;
}
LauncherWindow* LauncherWindow::cloneWindow()
{
- LauncherWindow* mw = new LauncherWindow(this, true);
+ LauncherWindow* mw = new LauncherWindow(&m_windowOptions, qobject_cast<QGraphicsView*>(m_view)->scene());
mw->show();
return mw;
}
diff --git a/WebKitTools/QtTestBrowser/launcherwindow.h b/WebKitTools/QtTestBrowser/launcherwindow.h
index f9f157d..9319d24 100644
--- a/WebKitTools/QtTestBrowser/launcherwindow.h
+++ b/WebKitTools/QtTestBrowser/launcherwindow.h
@@ -75,11 +75,48 @@
#undef KeyPress
#endif
+class WindowOptions {
+public:
+ WindowOptions()
+ : useGraphicsView(false)
+ , useCompositing(true)
+ , useTiledBackingStore(false)
+ , useWebGL(false)
+#if defined(Q_WS_MAEMO_5) || defined(Q_WS_S60)
+ , useFrameFlattening(true)
+#else
+ , useFrameFlattening(false)
+#endif
+ , cacheWebView(false)
+ , showFrameRate(false)
+ , resizesToContents(false)
+ , viewportUpdateMode(QGraphicsView::MinimalViewportUpdate)
+#if defined(QT_CONFIGURED_WITH_OPENGL)
+ , useQGLWidgetViewport(false)
+#endif
+ {
+ }
+
+ bool useGraphicsView;
+ bool useCompositing;
+ bool useTiledBackingStore;
+ bool useWebGL;
+ bool useFrameFlattening;
+ bool cacheWebView;
+ bool showFrameRate;
+ bool resizesToContents;
+ QGraphicsView::ViewportUpdateMode viewportUpdateMode;
+#if defined(QT_CONFIGURED_WITH_OPENGL)
+ bool useQGLWidgetViewport;
+#endif
+ QUrl inspectorUrl;
+};
+
class LauncherWindow : public MainWindow {
Q_OBJECT
public:
- LauncherWindow(LauncherWindow* other = 0, bool shareScene = false);
+ LauncherWindow(WindowOptions* data = 0, QGraphicsScene* sharedScene = 0);
virtual ~LauncherWindow();
virtual void keyPressEvent(QKeyEvent* event);
@@ -91,22 +128,6 @@ public:
bool eventFilter(QObject* obj, QEvent* event);
-public:
- static const int gExitClickArea = 80;
- static bool gUseGraphicsView;
- static bool gUseCompositing;
- static bool gCacheWebView;
- static bool gShowFrameRate;
- static bool gResizesToContents;
- static bool gUseTiledBackingStore;
- static bool gUseFrameFlattening;
- static QGraphicsView::ViewportUpdateMode gViewportUpdateMode;
- static QUrl gInspectorUrl;
-
-#if defined(QT_CONFIGURED_WITH_OPENGL)
- static bool gUseQGLWidgetViewport;
-#endif
-
protected slots:
void loadStarted();
void loadFinished();
@@ -127,7 +148,7 @@ protected slots:
/* void dumpPlugins() */
void dumpHtml();
- void initializeView(bool useGraphicsView = false);
+ void initializeView();
void setTouchMocking(bool on);
void toggleAcceleratedCompositing(bool toggle);
@@ -158,22 +179,22 @@ signals:
void enteredFullScreenMode(bool on);
private:
- void init(bool useGraphicsView = false);
+ void init();
bool isGraphicsBased() const;
void createChrome();
- void applyPrefs(LauncherWindow* other = 0);
+ void applyPrefs();
void applyZoom();
private:
- QVector<int> m_zoomLevels;
+ static QVector<int> m_zoomLevels;
int m_currentZoom;
QWidget* m_view;
WebInspector* m_inspector;
+ WindowOptions m_windowOptions;
+
QAction* m_formatMenuAction;
- QAction* m_flipAnimated;
- QAction* m_flipYAnimated;
#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
QPropertyAnimation* m_zoomAnimation;
diff --git a/WebKitTools/QtTestBrowser/main.cpp b/WebKitTools/QtTestBrowser/main.cpp
index 33a6416..842290b 100644
--- a/WebKitTools/QtTestBrowser/main.cpp
+++ b/WebKitTools/QtTestBrowser/main.cpp
@@ -33,6 +33,8 @@
#include "launcherwindow.h"
#include "urlloader.h"
+WindowOptions windowOptions;
+
int launcherMain(const QApplication& app)
{
#ifndef NDEBUG
@@ -89,7 +91,7 @@ LauncherApplication::LauncherApplication(int& argc, char** argv)
static void requiresGraphicsView(const QString& option)
{
- if (LauncherWindow::gUseGraphicsView)
+ if (windowOptions.useGraphicsView)
return;
appQuit(1, QString("%1 only works in combination with the -graphicsbased option").arg(option));
}
@@ -121,31 +123,31 @@ void LauncherApplication::handleUserOptions()
}
if (args.contains("-graphicsbased"))
- LauncherWindow::gUseGraphicsView = true;
+ windowOptions.useGraphicsView = true;
if (args.contains("-no-compositing")) {
requiresGraphicsView("-no-compositing");
- LauncherWindow::gUseCompositing = false;
+ windowOptions.useCompositing = false;
}
if (args.contains("-show-fps")) {
requiresGraphicsView("-show-fps");
- LauncherWindow::gShowFrameRate = true;
+ windowOptions.showFrameRate = true;
}
if (args.contains("-cache-webview")) {
requiresGraphicsView("-cache-webview");
- LauncherWindow::gCacheWebView = true;
+ windowOptions.cacheWebView = true;
}
if (args.contains("-tiled-backing-store")) {
requiresGraphicsView("-tiled-backing-store");
- LauncherWindow::gUseTiledBackingStore = true;
+ windowOptions.useTiledBackingStore = true;
}
if (args.contains("-resizes-to-contents")) {
requiresGraphicsView("-resizes-to-contents");
- LauncherWindow::gResizesToContents = true;
+ windowOptions.resizesToContents = true;
}
QString arg1("-viewport-update-mode");
@@ -160,13 +162,13 @@ void LauncherApplication::handleUserOptions()
if (idx == -1)
appQuit(1, QString("%1 value has to be one of [%2]").arg(arg1).arg(formatKeys(updateModes)));
- LauncherWindow::gViewportUpdateMode = static_cast<QGraphicsView::ViewportUpdateMode>(idx);
+ windowOptions.viewportUpdateMode = static_cast<QGraphicsView::ViewportUpdateMode>(idx);
}
QString inspectorUrlArg("-inspector-url");
int inspectorUrlIndex = args.indexOf(inspectorUrlArg);
if (inspectorUrlIndex != -1)
- LauncherWindow::gInspectorUrl = takeOptionValue(&args, inspectorUrlIndex);
+ windowOptions.inspectorUrl = takeOptionValue(&args, inspectorUrlIndex);
int robotIndex = args.indexOf("-r");
if (robotIndex != -1) {
@@ -213,7 +215,7 @@ int main(int argc, char **argv)
foreach (QString url, urls) {
LauncherWindow* newWindow;
if (!window)
- newWindow = window = new LauncherWindow();
+ newWindow = window = new LauncherWindow(&windowOptions);
else
newWindow = window->newWindow();
diff --git a/WebKitTools/QtTestBrowser/webview.cpp b/WebKitTools/QtTestBrowser/webview.cpp
index d06493e..c8eecd6 100644
--- a/WebKitTools/QtTestBrowser/webview.cpp
+++ b/WebKitTools/QtTestBrowser/webview.cpp
@@ -79,25 +79,70 @@ WebViewGraphicsBased::WebViewGraphicsBased(QWidget* parent)
connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(updateFrameRate()));
}
+void WebViewGraphicsBased::setPage(QWebPage* page)
+{
+ connect(page->mainFrame(), SIGNAL(contentsSizeChanged(const QSize&)), SLOT(contentsSizeChanged(const QSize&)));
+ m_item->setPage(page);
+}
+
+void WebViewGraphicsBased::contentsSizeChanged(const QSize& size)
+{
+ if (m_resizesToContents)
+ scene()->setSceneRect(0, 0, size.width(), size.height());
+}
+
void WebViewGraphicsBased::setResizesToContents(bool b)
{
+ if (b == m_resizesToContents)
+ return;
+
m_resizesToContents = b;
m_item->setResizesToContents(m_resizesToContents);
+
+ // When setting resizesToContents ON, our web view widget will always size as big as the
+ // web content being displayed, and so will the QWebPage's viewport. It implies that internally
+ // WebCore will work as if there was no content rendered offscreen, and then no scrollbars need
+ // drawing. In order to keep scrolling working, we:
+ //
+ // 1) Set QGraphicsView's scrollbars policy back to 'auto'.
+ // 2) Set scene's boundaries rect to an invalid size, which automatically makes it to be as big
+ // as it needs to enclose all items onto it. We do that because QGraphicsView also calculates
+ // the size of its scrollable area according to the amount of content in scene that is rendered
+ // offscreen.
+ // 3) Set QWebPage's preferredContentsSize according to the size of QGraphicsView's viewport,
+ // so WebCore properly lays pages out.
+ //
+ // On the other hand, when toggling resizesToContents OFF, we set back the default values, as
+ // opposite as described above.
if (m_resizesToContents) {
setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
+ m_item->page()->setPreferredContentsSize(size());
+ QRectF itemRect(m_item->geometry().topLeft(), m_item->page()->mainFrame()->contentsSize());
+ m_item->setGeometry(itemRect);
+ scene()->setSceneRect(itemRect);
} else {
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ m_item->page()->setPreferredContentsSize(QSize());
+ QRect viewportRect(QPoint(0, 0), size());
+ m_item->setGeometry(viewportRect);
+ scene()->setSceneRect(viewportRect);
}
}
void WebViewGraphicsBased::resizeEvent(QResizeEvent* event)
{
QGraphicsView::resizeEvent(event);
- if (m_resizesToContents)
+
+ QSize size(event->size());
+
+ if (m_resizesToContents) {
+ m_item->page()->setPreferredContentsSize(size);
return;
- QRectF rect(QPoint(0, 0), event->size());
+ }
+
+ QRectF rect(QPoint(0, 0), size);
m_item->setGeometry(rect);
scene()->setSceneRect(rect);
}
diff --git a/WebKitTools/QtTestBrowser/webview.h b/WebKitTools/QtTestBrowser/webview.h
index 9b533b3..5e7c0c3 100644
--- a/WebKitTools/QtTestBrowser/webview.h
+++ b/WebKitTools/QtTestBrowser/webview.h
@@ -71,14 +71,15 @@ class WebViewGraphicsBased : public QGraphicsView {
public:
WebViewGraphicsBased(QWidget* parent);
- virtual void resizeEvent(QResizeEvent*);
- void setPage(QWebPage* page) { m_item->setPage(page); }
+ void setPage(QWebPage* 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 resizeEvent(QResizeEvent*);
virtual void paintEvent(QPaintEvent* event);
void setResizesToContents(bool b);
@@ -106,6 +107,7 @@ public slots:
void updateFrameRate();
void animatedFlip();
void animatedYFlip();
+ void contentsSizeChanged(const QSize&);
signals:
void yFlipRequest();