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

Added devicePixelRatio support (fixes #10964) #12839

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -1372,6 +1372,11 @@ void QWebPageAdapter::setDevicePixelRatio(float devicePixelRatio)
page->setDeviceScaleFactor(devicePixelRatio);
}

float QWebPageAdapter::devicePixelRatio() const
{
return page->deviceScaleFactor();
}

bool QWebPageAdapter::handleKeyEvent(QKeyEvent *ev)
{
Frame* frame = page->focusController()->focusedOrMainFrame();
Expand Down
Expand Up @@ -356,6 +356,7 @@ class WEBKIT_EXPORTDATA QWebPageAdapter {

ViewportAttributes viewportAttributesForSize(const QSize& availableSize, const QSize& deviceSize) const;
void setDevicePixelRatio(float devicePixelRatio);
float devicePixelRatio() const;

QWebSettings *settings;

Expand Down
10 changes: 10 additions & 0 deletions src/qt/qtwebkit/Source/WebKit/qt/WidgetApi/qwebpage.cpp
Expand Up @@ -1968,6 +1968,7 @@ void QWebPage::setViewportSize(const QSize &size) const
mainFrame->setViewportSize(size);
}


void QWebPagePrivate::updateWindow()
{
QWindow* _window = 0;
Expand All @@ -1992,6 +1993,15 @@ void QWebPagePrivate::_q_updateScreen(QScreen* screen)
setDevicePixelRatio(screen->devicePixelRatio());
}

void QWebPage::setDevicePixelRatio(float ratio) {
d->setDevicePixelRatio(ratio);
}

float QWebPage::devicePixelRatio() const
{
return d->devicePixelRatio();
}

static int getintenv(const char* variable)
{
bool ok;
Expand Down
2 changes: 2 additions & 0 deletions src/qt/qtwebkit/Source/WebKit/qt/WidgetApi/qwebpage.h
Expand Up @@ -305,6 +305,8 @@ class QWEBKITWIDGETS_EXPORT QWebPage : public QObject {
virtual void triggerAction(WebAction action, bool checked = false);

QSize viewportSize() const;
void setDevicePixelRatio(float ratio);
float devicePixelRatio() const;
void setViewportSize(const QSize &size) const;
ViewportAttributes viewportAttributesForSize(const QSize& availableSize) const;

Expand Down
9 changes: 9 additions & 0 deletions src/webpage.cpp
Expand Up @@ -1280,6 +1280,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
Expand Up @@ -70,6 +70,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