summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/widgets/browser/browsermainwindow.cpp6
-rw-r--r--lib/web_contents_adapter.cpp16
-rw-r--r--lib/web_contents_adapter.h2
-rw-r--r--lib/widgets/Api/qwebenginepage.cpp12
-rw-r--r--lib/widgets/Api/qwebengineview.cpp11
5 files changed, 41 insertions, 6 deletions
diff --git a/examples/widgets/browser/browsermainwindow.cpp b/examples/widgets/browser/browsermainwindow.cpp
index 2d6c02288..fab4faba6 100644
--- a/examples/widgets/browser/browsermainwindow.cpp
+++ b/examples/widgets/browser/browsermainwindow.cpp
@@ -751,29 +751,23 @@ void BrowserMainWindow::slotEditFindPrevious()
void BrowserMainWindow::slotViewZoomIn()
{
-#if defined(QWEBENGINEPAGE_SETZOOMFACTOR)
if (!currentTab())
return;
currentTab()->setZoomFactor(currentTab()->zoomFactor() + 0.1);
-#endif
}
void BrowserMainWindow::slotViewZoomOut()
{
-#if defined(QWEBENGINEPAGE_SETZOOMFACTOR)
if (!currentTab())
return;
currentTab()->setZoomFactor(currentTab()->zoomFactor() - 0.1);
-#endif
}
void BrowserMainWindow::slotViewResetZoom()
{
-#if defined(QWEBENGINEPAGE_SETZOOMFACTOR)
if (!currentTab())
return;
currentTab()->setZoomFactor(1.0);
-#endif
}
void BrowserMainWindow::slotViewZoomTextOnly(bool enable)
diff --git a/lib/web_contents_adapter.cpp b/lib/web_contents_adapter.cpp
index 7fa180e70..6a914af99 100644
--- a/lib/web_contents_adapter.cpp
+++ b/lib/web_contents_adapter.cpp
@@ -50,6 +50,7 @@
#include "content/public/browser/web_contents.h"
#include "content/public/browser/navigation_entry.h"
+#include "content/public/common/page_zoom.h"
#include "content/public/common/renderer_preferences.h"
#include <QGuiApplication>
@@ -226,3 +227,18 @@ void WebContentsAdapter::clearNavigationHistory()
if (d->webContents->GetController().CanPruneAllButVisible())
d->webContents->GetController().PruneAllButVisible();
}
+
+void WebContentsAdapter::setZoomFactor(qreal factor)
+{
+ Q_D(WebContentsAdapter);
+ if (content::RenderViewHost *rvh = d->webContents->GetRenderViewHost()) {
+ rvh->SetZoomLevel(content::ZoomFactorToZoomLevel(static_cast<double>(factor)));
+ }
+
+}
+
+qreal WebContentsAdapter::currentZoomFactor() const
+{
+ Q_D(const WebContentsAdapter);
+ return static_cast<qreal>(content::ZoomLevelToZoomFactor(d->webContents->GetZoomLevel()));
+}
diff --git a/lib/web_contents_adapter.h b/lib/web_contents_adapter.h
index 8b4dae1f2..0b48dc81b 100644
--- a/lib/web_contents_adapter.h
+++ b/lib/web_contents_adapter.h
@@ -79,6 +79,8 @@ public:
QUrl getNavigationEntryUrl(int index);
QString getNavigationEntryTitle(int index);
void clearNavigationHistory();
+ void setZoomFactor(qreal);
+ qreal currentZoomFactor() const;
private:
Q_DISABLE_COPY(WebContentsAdapter);
diff --git a/lib/widgets/Api/qwebenginepage.cpp b/lib/widgets/Api/qwebenginepage.cpp
index 365101e99..ee0238368 100644
--- a/lib/widgets/Api/qwebenginepage.cpp
+++ b/lib/widgets/Api/qwebenginepage.cpp
@@ -281,6 +281,18 @@ QUrl QWebEnginePage::url() const
return d->adapter->activeUrl();
}
+qreal QWebEnginePage::zoomFactor() const
+{
+ Q_D(const QWebEnginePage);
+ return d->adapter->currentZoomFactor();
+}
+
+void QWebEnginePage::setZoomFactor(qreal factor)
+{
+ Q_D(QWebEnginePage);
+ d->adapter->setZoomFactor(factor);
+}
+
QWebEnginePage *QWebEnginePage::createWindow(WebWindowType type)
{
Q_D(const QWebEnginePage);
diff --git a/lib/widgets/Api/qwebengineview.cpp b/lib/widgets/Api/qwebengineview.cpp
index c8001245e..a1b4fbc27 100644
--- a/lib/widgets/Api/qwebengineview.cpp
+++ b/lib/widgets/Api/qwebengineview.cpp
@@ -174,6 +174,17 @@ QWebEngineView *QWebEngineView::createWindow(QWebEnginePage::WebWindowType type)
return 0;
}
+
+qreal QWebEngineView::zoomFactor() const
+{
+ return page()->zoomFactor();
+}
+
+void QWebEngineView::setZoomFactor(qreal factor)
+{
+ page()->setZoomFactor(factor);
+}
+
QT_END_NAMESPACE
#include "moc_qwebengineview.cpp"