diff options
author | Allan Sandfeld Jensen <allan.jensen@digia.com> | 2014-02-06 18:01:02 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-02-07 22:08:31 +0100 |
commit | 3f9bd69da1ac2f70158849d5f1b4b464d0488e0e (patch) | |
tree | 2c4e55646611c7d89b2b0abdac2c91f78d11bd1e | |
parent | 386fbb8ccd02af90ddec81fb1730876c18b07099 (diff) |
Update device pixel ratio on screen change
This patch makes QWebPage listen to QWindow::screenChangedEvent
and update the device pixel ratio when it is received.
Task-number: QTBUG-36190
Change-Id: Ia28571ef241a3a2f970876f6e474b01c1ac001e1
Reviewed-by: Jocelyn Turcotte <jocelyn.turcotte@digia.com>
-rw-r--r-- | Source/WebKit/qt/WebCoreSupport/QWebPageAdapter.cpp | 2 | ||||
-rw-r--r-- | Source/WebKit/qt/WebCoreSupport/QWebPageAdapter.h | 2 | ||||
-rw-r--r-- | Source/WebKit/qt/WidgetApi/qwebpage.cpp | 31 | ||||
-rw-r--r-- | Source/WebKit/qt/WidgetApi/qwebpage.h | 2 | ||||
-rw-r--r-- | Source/WebKit/qt/WidgetApi/qwebpage_p.h | 9 |
5 files changed, 40 insertions, 6 deletions
diff --git a/Source/WebKit/qt/WebCoreSupport/QWebPageAdapter.cpp b/Source/WebKit/qt/WebCoreSupport/QWebPageAdapter.cpp index a12ef553b..129f888b9 100644 --- a/Source/WebKit/qt/WebCoreSupport/QWebPageAdapter.cpp +++ b/Source/WebKit/qt/WebCoreSupport/QWebPageAdapter.cpp @@ -1362,7 +1362,7 @@ QWebPageAdapter::ViewportAttributes QWebPageAdapter::viewportAttributesForSize(c return result; } -void QWebPageAdapter::setDevicePixelRatio(int devicePixelRatio) +void QWebPageAdapter::setDevicePixelRatio(float devicePixelRatio) { page->setDeviceScaleFactor(devicePixelRatio); } diff --git a/Source/WebKit/qt/WebCoreSupport/QWebPageAdapter.h b/Source/WebKit/qt/WebCoreSupport/QWebPageAdapter.h index 3b6fc3a5c..3629e906d 100644 --- a/Source/WebKit/qt/WebCoreSupport/QWebPageAdapter.h +++ b/Source/WebKit/qt/WebCoreSupport/QWebPageAdapter.h @@ -352,7 +352,7 @@ public: }; ViewportAttributes viewportAttributesForSize(const QSize& availableSize, const QSize& deviceSize) const; - void setDevicePixelRatio(int devicePixelRatio); + void setDevicePixelRatio(float devicePixelRatio); QWebSettings *settings; diff --git a/Source/WebKit/qt/WidgetApi/qwebpage.cpp b/Source/WebKit/qt/WidgetApi/qwebpage.cpp index dac343bd2..cb9559e33 100644 --- a/Source/WebKit/qt/WidgetApi/qwebpage.cpp +++ b/Source/WebKit/qt/WidgetApi/qwebpage.cpp @@ -68,6 +68,7 @@ #include <QNetworkProxy> #include <QNetworkRequest> #include <QPainter> +#include <QScreen> #include <QSslSocket> #include <QStyle> #include <QSysInfo> @@ -80,6 +81,7 @@ #include <QTouchEvent> #include <QUndoStack> #include <QUrl> +#include <QWindow> #if defined(Q_WS_X11) #include <QX11Info> #endif @@ -195,6 +197,7 @@ QWebPagePrivate::QWebPagePrivate(QWebPage *qq) , linkPolicy(QWebPage::DontDelegateLinks) , m_viewportSize(QSize(0, 0)) , useFixedLayout(false) + , window(0) , inspectorFrontend(0) , inspector(0) , inspectorIsInternalOnly(false) @@ -1941,15 +1944,39 @@ void QWebPage::setViewportSize(const QSize &size) const { d->m_viewportSize = size; + d->updateWindow(); + QWebFrameAdapter* mainFrame = d->mainFrameAdapter(); if (!mainFrame->hasView()) return; - d->setDevicePixelRatio(d->view->devicePixelRatio()); - mainFrame->setViewportSize(size); } +void QWebPagePrivate::updateWindow() +{ + QWindow* _window = 0; + if (view && view->window()) + _window = view->window()->windowHandle(); + + if (window == _window) + return; + + if (window) + QObject::disconnect(window, SIGNAL(screenChanged(QScreen*)), q, SLOT(_q_updateScreen(QScreen*))); + window = _window; + if (window) { + QObject::connect(window, SIGNAL(screenChanged(QScreen*)), q, SLOT(_q_updateScreen(QScreen*))); + _q_updateScreen(window->screen()); + } +} + +void QWebPagePrivate::_q_updateScreen(QScreen* screen) +{ + if (screen) + setDevicePixelRatio(screen->devicePixelRatio()); +} + static int getintenv(const char* variable) { bool ok; diff --git a/Source/WebKit/qt/WidgetApi/qwebpage.h b/Source/WebKit/qt/WidgetApi/qwebpage.h index 2e3f6aa50..24fe1383e 100644 --- a/Source/WebKit/qt/WidgetApi/qwebpage.h +++ b/Source/WebKit/qt/WidgetApi/qwebpage.h @@ -35,6 +35,7 @@ class QMenu; class QNetworkRequest; class QNetworkReply; class QNetworkAccessManager; +class QScreen; QT_END_NAMESPACE class QWebElement; @@ -444,6 +445,7 @@ private: Q_PRIVATE_SLOT(d, void _q_webActionTriggered(bool checked)) #endif Q_PRIVATE_SLOT(d, void _q_cleanupLeakMessages()) + Q_PRIVATE_SLOT(d, void _q_updateScreen(QScreen*)) QWebPagePrivate *d; diff --git a/Source/WebKit/qt/WidgetApi/qwebpage_p.h b/Source/WebKit/qt/WidgetApi/qwebpage_p.h index b35cf2e19..8ba6c4c40 100644 --- a/Source/WebKit/qt/WidgetApi/qwebpage_p.h +++ b/Source/WebKit/qt/WidgetApi/qwebpage_p.h @@ -48,9 +48,11 @@ class Frame; } QT_BEGIN_NAMESPACE -class QUndoStack; -class QMenu; class QBitArray; +class QMenu; +class QScreen; +class QUndoStack; +class QWindow; QT_END_NAMESPACE class QtPluginWidgetAdapter; @@ -163,6 +165,8 @@ public: bool gestureEvent(QGestureEvent*); + void updateWindow(); + void _q_updateScreen(QScreen*); void setInspector(QWebInspector*); QWebInspector* getOrCreateInspector(); @@ -195,6 +199,7 @@ public: QAction *actions[QWebPage::WebActionCount]; + QWindow* window; QWidget* inspectorFrontend; QWebInspector* inspector; bool inspectorIsInternalOnly; // True if created through the Inspect context menu action |