Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Commit

Permalink
Allow setting devicePixelRatio
Browse files Browse the repository at this point in the history
  • Loading branch information
DeviaVir authored and Chase Sillevis committed Jun 20, 2016
1 parent 6090f54 commit aa4d53f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/uic_wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
DYLD_LIBRARY_PATH=/Users/Chase/Sites/Charity/phantomjs/src/qt/qtbase/lib${DYLD_LIBRARY_PATH:+:$DYLD_LIBRARY_PATH}
export DYLD_LIBRARY_PATH
QT_PLUGIN_PATH=/Users/Chase/Sites/Charity/phantomjs/src/qt/qtbase/plugins${QT_PLUGIN_PATH:+:$QT_PLUGIN_PATH}
export QT_PLUGIN_PATH
exec /Users/Chase/Sites/Charity/phantomjs/src/qt/qtbase/bin/uic "$@"
10 changes: 10 additions & 0 deletions src/webpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/webpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 <code>"window.name"</code> within the main page frame.
*
Expand Down
14 changes: 14 additions & 0 deletions test/module/webpage/device-pixel-ratio.js
Original file line number Diff line number Diff line change
@@ -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");

0 comments on commit aa4d53f

Please sign in to comment.