diff options
author | Pierre Rossi <pierre.rossi@digia.com> | 2013-09-30 11:48:55 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-10-01 22:49:24 +0200 |
commit | 8c1de0f07a4b83ad50278231a8866143cf01333c (patch) | |
tree | f1035fcbcf075a201ec0650d64e11c78ebbfb0b1 | |
parent | e316bab5cf7d5c48ded7a49f84ef0ddf02fd413b (diff) |
Widgets: implement zoomFactor
Change-Id: I7ef26e4a2e6c9eb228bcf5542ad272b998f8c6a3
Reviewed-by: Michael Bruning <michael.bruning@digia.com>
Reviewed-by: Zeno Albisser <zeno.albisser@digia.com>
-rw-r--r-- | examples/widgets/browser/browsermainwindow.cpp | 6 | ||||
-rw-r--r-- | lib/web_contents_adapter.cpp | 16 | ||||
-rw-r--r-- | lib/web_contents_adapter.h | 2 | ||||
-rw-r--r-- | lib/widgets/Api/qwebenginepage.cpp | 12 | ||||
-rw-r--r-- | lib/widgets/Api/qwebengineview.cpp | 11 |
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" |