diff --git a/src/webpage.cpp b/src/webpage.cpp index 1b5184983..9533c284f 100644 --- a/src/webpage.cpp +++ b/src/webpage.cpp @@ -440,6 +440,7 @@ WebPage::WebPage(QObject* parent, const QUrl& baseUrl) m_dpi = qRound(QApplication::primaryScreen()->logicalDotsPerInch()); m_customWebPage->setViewportSize(QSize(400, 300)); + m_customWebPage->setDevicePixelRatio(1.0); } WebPage::~WebPage() @@ -1382,6 +1383,15 @@ void WebPage::_uploadFile(const QString& selector, const QStringList& fileNames) el.evaluateJavaScript(JS_ELEMENT_CLICK); } +void WebPage::setDevicePixelRatio(float ratio) { + m_customWebPage->setDevicePixelRatio(ratio); +} + +float WebPage::devicePixelRatio() const +{ + return m_customWebPage->devicePixelRatio(); +} + bool WebPage::injectJs(const QString& jsFilePath) { return Utils::injectJsInFrame(jsFilePath, m_libraryPath, m_currentFrame); diff --git a/src/webpage.h b/src/webpage.h index 55920e718..bdb124588 100644 --- a/src/webpage.h +++ b/src/webpage.h @@ -71,6 +71,7 @@ class WebPage : public QObject, public QWebFrame::PrintCallback Q_PROPERTY(bool navigationLocked READ navigationLocked WRITE setNavigationLocked) Q_PROPERTY(QVariantMap customHeaders READ customHeaders WRITE setCustomHeaders) Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor) + Q_PROPERTY(float devicePixelRatio READ devicePixelRatio WRITE setDevicePixelRatio) Q_PROPERTY(QVariantList cookies READ cookies WRITE setCookies) Q_PROPERTY(QString windowName READ windowName) Q_PROPERTY(QObjectList pages READ pages) @@ -140,6 +141,9 @@ class WebPage : public QObject, public QWebFrame::PrintCallback void setZoomFactor(qreal zoom); qreal zoomFactor() const; + void setDevicePixelRatio(float ratio); + float devicePixelRatio() const; + /** * Value of "window.name" within the main page frame. * diff --git a/test/module/webpage/device-pixel-ratio.js b/test/module/webpage/device-pixel-ratio.js new file mode 100644 index 000000000..681a785c4 --- /dev/null +++ b/test/module/webpage/device-pixel-ratio.js @@ -0,0 +1,14 @@ +var webpage = require('webpage'); + +test(function () { + var defaultPage = webpage.create(); + assert_deep_equals(defaultPage.devicePixelRatio, 1.0); +}, "default device pixel ratio"); + +test(function () { + var options = { + devicePixelRatio: 1.5 + }; + var customPage = webpage.create(options); + assert_deep_equals(customPage.devicePixelRatio, options.devicePixelRatio); +}, "custom device pixel ratio");