diff --git a/src/core/web_engine_settings.cpp b/src/core/web_engine_settings.cpp index 4be985e0c74a7796be64fc611eb81b5262ba1171..fe40298bb0359ada383c1a566c010adb21590d2f 100644 --- a/src/core/web_engine_settings.cpp +++ b/src/core/web_engine_settings.cpp @@ -223,6 +223,7 @@ void WebEngineSettings::initDefaults() s_defaultAttributes.insert(PluginsEnabled, false); s_defaultAttributes.insert(FullScreenSupportEnabled, false); s_defaultAttributes.insert(ScreenCaptureEnabled, false); + s_defaultAttributes.insert(HideScrollbars, false); // The following defaults matches logic in render_view_host_impl.cc // But first we must ensure the WebContext has been initialized QtWebEngineCore::WebEngineContext::current(); @@ -326,6 +327,7 @@ void WebEngineSettings::applySettingsToWebPreferences(content::WebPreferences *p prefs->should_print_backgrounds = testAttribute(PrintElementBackgrounds); prefs->allow_running_insecure_content = testAttribute(AllowRunningInsecureContent); prefs->allow_geolocation_on_insecure_origins = testAttribute(AllowGeolocationOnInsecureOrigins); + prefs->hide_scrollbars = testAttribute(HideScrollbars); // Fonts settings. prefs->standard_font_family_map[content::kCommonScript] = toString16(fontFamily(StandardFont)); diff --git a/src/core/web_engine_settings.h b/src/core/web_engine_settings.h index 7defb0013e539e90303f876aca8a79724f56c084..1304d2ae98ee0850aaffb632575f00ac3e3d4529 100644 --- a/src/core/web_engine_settings.h +++ b/src/core/web_engine_settings.h @@ -84,7 +84,8 @@ public: PrintElementBackgrounds, AllowRunningInsecureContent, AllowGeolocationOnInsecureOrigins, - AllowWindowActivationFromJavaScript + AllowWindowActivationFromJavaScript, + HideScrollbars }; // Must match the values from the public API in qwebenginesettings.h. diff --git a/src/webengine/api/qquickwebenginesettings.cpp b/src/webengine/api/qquickwebenginesettings.cpp index cdbb25e4c68e40364cb0a09d1f3b870f61108ebb..98a3eef39fafc57385f31f228e0f32e8c231f3ed 100644 --- a/src/webengine/api/qquickwebenginesettings.cpp +++ b/src/webengine/api/qquickwebenginesettings.cpp @@ -372,6 +372,16 @@ bool QQuickWebEngineSettings::allowWindowActivationFromJavaScript() const return d_ptr->testAttribute(WebEngineSettings::AllowWindowActivationFromJavaScript); } +/*! + \qmlproperty bool WebEngineSettings::hideScrollbars + \since QtWebEngine 1.6 + Hides scrollbars. Disabled by default. +*/ +bool QQuickWebEngineSettings::hideScrollbars() const +{ + return d_ptr->testAttribute(WebEngineSettings::HideScrollbars); +} + /*! \qmlproperty string WebEngineSettings::defaultTextEncoding \since QtWebEngine 1.2 @@ -582,6 +592,14 @@ void QQuickWebEngineSettings::setAllowWindowActivationFromJavaScript(bool on) Q_EMIT allowWindowActivationFromJavaScriptChanged(); } +void QQuickWebEngineSettings::setHideScrollbars(bool on) +{ + bool wasOn = d_ptr->testAttribute(WebEngineSettings::HideScrollbars); + d_ptr->setAttribute(WebEngineSettings::HideScrollbars, on); + if (wasOn != on) + Q_EMIT hideScrollbarsChanged(); +} + void QQuickWebEngineSettings::setParentSettings(QQuickWebEngineSettings *parentSettings) { d_ptr->setParentSettings(parentSettings->d_ptr.data()); diff --git a/src/webengine/api/qquickwebenginesettings_p.h b/src/webengine/api/qquickwebenginesettings_p.h index 1b9988bceeb9d8b03fbc45e83c2a5af0a5291f8a..da838f52fd66685f69a8a92be10539e2b9a748b1 100644 --- a/src/webengine/api/qquickwebenginesettings_p.h +++ b/src/webengine/api/qquickwebenginesettings_p.h @@ -87,6 +87,7 @@ class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineSettings : public QObject { Q_PROPERTY(bool allowRunningInsecureContent READ allowRunningInsecureContent WRITE setAllowRunningInsecureContent NOTIFY allowRunningInsecureContentChanged REVISION 3 FINAL) Q_PROPERTY(bool allowGeolocationOnInsecureOrigins READ allowGeolocationOnInsecureOrigins WRITE setAllowGeolocationOnInsecureOrigins NOTIFY allowGeolocationOnInsecureOriginsChanged REVISION 4 FINAL) Q_PROPERTY(bool allowWindowActivationFromJavaScript READ allowWindowActivationFromJavaScript WRITE setAllowWindowActivationFromJavaScript NOTIFY allowWindowActivationFromJavaScriptChanged REVISION 5 FINAL) + Q_PROPERTY(bool hideScrollbars READ hideScrollbars WRITE setHideScrollbars NOTIFY hideScrollbarsChanged REVISION 5 FINAL) public: ~QQuickWebEngineSettings(); @@ -115,6 +116,7 @@ public: bool allowRunningInsecureContent() const; bool allowGeolocationOnInsecureOrigins() const; bool allowWindowActivationFromJavaScript() const; + bool hideScrollbars() const; void setAutoLoadImages(bool on); void setJavascriptEnabled(bool on); @@ -140,6 +142,7 @@ public: void setAllowRunningInsecureContent(bool on); void setAllowGeolocationOnInsecureOrigins(bool on); void setAllowWindowActivationFromJavaScript(bool on); + void setHideScrollbars(bool on); signals: void autoLoadImagesChanged(); @@ -166,6 +169,7 @@ signals: Q_REVISION(3) void allowRunningInsecureContentChanged(); Q_REVISION(4) void allowGeolocationOnInsecureOriginsChanged(); Q_REVISION(5) void allowWindowActivationFromJavaScriptChanged(); + Q_REVISION(5) void hideScrollbarsChanged(); private: explicit QQuickWebEngineSettings(QQuickWebEngineSettings *parentSettings = 0); diff --git a/src/webenginewidgets/api/qwebenginesettings.cpp b/src/webenginewidgets/api/qwebenginesettings.cpp index 6e24b4b515f5cbd19608d763b32cc6f1d5d942ab..439e005904051ab6dc3f84bbbea428c25933d293 100644 --- a/src/webenginewidgets/api/qwebenginesettings.cpp +++ b/src/webenginewidgets/api/qwebenginesettings.cpp @@ -99,6 +99,8 @@ static WebEngineSettings::Attribute toWebEngineAttribute(QWebEngineSettings::Web return WebEngineSettings::AllowGeolocationOnInsecureOrigins; case QWebEngineSettings::AllowWindowActivationFromJavaScript: return WebEngineSettings::AllowWindowActivationFromJavaScript; + case QWebEngineSettings::HideScrollbars: + return WebEngineSettings::HideScrollbars; default: return WebEngineSettings::UnsupportedInCoreSettings; diff --git a/src/webenginewidgets/api/qwebenginesettings.h b/src/webenginewidgets/api/qwebenginesettings.h index 4b997f0ac07a2f0ecd837663c83796a8da6e063f..1857e52280ca0e67ebde81da2e961e2a4d209eb3 100644 --- a/src/webenginewidgets/api/qwebenginesettings.h +++ b/src/webenginewidgets/api/qwebenginesettings.h @@ -90,7 +90,8 @@ public: PrintElementBackgrounds, AllowRunningInsecureContent, AllowGeolocationOnInsecureOrigins, - AllowWindowActivationFromJavaScript + AllowWindowActivationFromJavaScript, + HideScrollbars }; enum FontSize { diff --git a/src/webenginewidgets/doc/src/qwebenginesettings_lgpl.qdoc b/src/webenginewidgets/doc/src/qwebenginesettings_lgpl.qdoc index 26f3964da997b11aa4c0303a33cad40418bf520c..907f6f643d78e38a0140dfdfcdb8256ddc35ff71 100644 --- a/src/webenginewidgets/doc/src/qwebenginesettings_lgpl.qdoc +++ b/src/webenginewidgets/doc/src/qwebenginesettings_lgpl.qdoc @@ -165,6 +165,9 @@ \value AllowWindowActivationFromJavaScript Allows the window.focus() method in JavaScript. Disallowed by default. (Added in Qt 5.10) + \value HideScrollbars + Hides scrollbars. + Disabled by default. (Added in Qt 5.10) */ diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp index 393902a9e8357d189a7746e9a0d5f96acfe12b53..4cb8e23e552fa1f6fc9431a8b40c24c2be75034f 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp @@ -3515,39 +3515,19 @@ void tst_QWebEnginePage::scrollPosition() void tst_QWebEnginePage::scrollbarsOff() { -#if !defined(QWEBENGINEPAGE_EVALUATEJAVASCRIPT) - QSKIP("QWEBENGINEPAGE_EVALUATEJAVASCRIPT"); -#else QWebEngineView view; - QWebEngineFrame* mainFrame = view.page(); - - mainFrame->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff); - mainFrame->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff); - - QString html("<script>" \ - " function checkScrollbar() {" \ - " if (innerWidth === document.documentElement.offsetWidth)" \ - " document.getElementById('span1').innerText = 'SUCCESS';" \ - " else" \ - " document.getElementById('span1').innerText = 'FAIL';" \ - " }" \ - "</script>" \ - "<body>" \ - " <div style='margin-top:1000px ; margin-left:1000px'>" \ - " <a id='offscreen' href='a'>End</a>" \ - " </div>" \ - "<span id='span1'></span>" \ - "</body>"); - - - QSignalSpy loadSpy(&view, &QWebEngineView::loadFinished); - view.setHtml(html); - QVERIFY(loadSpy.wait(200); - QCOMPARE(loadSpy.count(), 1); + view.page()->settings()->setAttribute(QWebEngineSettings::HideScrollbars, true); - mainFrame->evaluateJavaScript("checkScrollbar();"); - QCOMPARE(mainFrame->documentElement().findAll("span").at(0).toPlainText(), QString("SUCCESS")); -#endif + QString html("<html><body>" + " <div style='margin-top:1000px ; margin-left:1000px'>" + " <a id='offscreen' href='a'>End</a>" + " </div>" + "</body></html>"); + + QSignalSpy loadSpy(&view, SIGNAL(loadFinished(bool))); + view.setHtml(html); + QTRY_COMPARE(loadSpy.count(), 1); + QVERIFY(evaluateJavaScriptSync(view.page(), "innerWidth == document.documentElement.offsetWidth").toBool()); } void tst_QWebEnginePage::horizontalScrollAfterBack()