diff options
author | Michal Klocek <michal.klocek@theqtcompany.com> | 2016-06-13 12:38:51 +0200 |
---|---|---|
committer | Michal Klocek <michal.klocek@qt.io> | 2016-08-18 09:23:03 +0000 |
commit | baeb20b2e720f5c683cf3810116d827e1561c4b2 (patch) | |
tree | abaf7c153e369c2043b46621ab78fbe42ce74421 /src/webengine/api/qquickwebengineview.cpp | |
parent | 6534b09073791398bad99863821740e986915bff (diff) |
Add Qt Quick Controls 2 support for dialogs
QtQuickControls1 does not handle embedded
platforms too well. In case of eglfs platform
we crash badly - only one window is supported.
QtQuickControls2 on the other hand lacks the native
look on desktop. Therefore on desktop platforms
keep using QtQuickControls1, and on eglfs use
QtQuickControls2.
QtQuick.Dialogs are not implemented for QtQuickControls2,
moreover required authentication dialog and prompt
dialog are neither implemented in QtQuickControls1.
As a workaround make new dialogs to give
consistent look and feel.
Replace close() with reject() signal in java script
prompt dialog to unify handling between qqc1 and qqc2
[ChangeLog][QtWebEngine][General] Qt WebEngine (QML)
now optionally uses Qt Quick 2 Controls to show standard dialogs.
Task-number: QTBUG-53467
Task-number: QTBUG-51177
Change-Id: I42f9506357bbb82d4f04465f30a18c8013439e25
Reviewed-by: Kai Koehne <kai.koehne@qt.io>
Diffstat (limited to 'src/webengine/api/qquickwebengineview.cpp')
-rw-r--r-- | src/webengine/api/qquickwebengineview.cpp | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp index 02484548b..f49ac155e 100644 --- a/src/webengine/api/qquickwebengineview.cpp +++ b/src/webengine/api/qquickwebengineview.cpp @@ -145,8 +145,7 @@ QQuickWebEngineViewPrivate::QQuickWebEngineViewPrivate() , m_dpiScale(1.0) , m_backgroundColor(Qt::white) , m_defaultZoomFactor(1.0) - // QTBUG-53467 - , m_menuEnabled(true) + , m_ui2Enabled(false) { // The gold standard for mobile web content is 160 dpi, and the devicePixelRatio expected // is the (possibly quantized) ratio of device dpi to 160 dpi. @@ -164,8 +163,26 @@ QQuickWebEngineViewPrivate::QQuickWebEngineViewPrivate() // 1x, 2x, 3x etc assets that fit an integral number of pixels. setDevicePixelRatio(qMax(1, qRound(webPixelRatio))); } + if (platform == QLatin1Literal("eglfs")) - m_menuEnabled = false; + m_ui2Enabled = true; + + const QByteArray dialogSet = qgetenv("QTWEBENGINE_DIALOG_SET"); + + if (!dialogSet.isEmpty()) { + if (dialogSet == QByteArrayLiteral("QtQuickControls2")) { + m_ui2Enabled = true; + } else if (dialogSet == QByteArrayLiteral("QtQuickControls1") + && m_ui2Enabled) { + m_ui2Enabled = false; + qWarning("QTWEBENGINE_DIALOG_SET=QtQuickControls1 forces use of Qt Quick Controls 1 " + "on an eglfs backend. This can crash your application!"); + } else { + qWarning("Ignoring QTWEBENGINE_DIALOG_SET environment variable set to %s. Accepted " + "values are \"QtQuickControls1\" and \"QtQuickControls2\"", dialogSet.data()); + } + } + #ifndef QT_NO_ACCESSIBILITY QAccessible::installFactory(&webAccessibleFactory); #endif // QT_NO_ACCESSIBILITY @@ -189,7 +206,7 @@ UIDelegatesManager *QQuickWebEngineViewPrivate::ui() { Q_Q(QQuickWebEngineView); if (m_uIDelegatesManager.isNull()) - m_uIDelegatesManager.reset(new UIDelegatesManager(q)); + m_uIDelegatesManager.reset(m_ui2Enabled ? new UI2DelegatesManager(q) : new UIDelegatesManager(q)); return m_uIDelegatesManager.data(); } @@ -216,12 +233,6 @@ bool QQuickWebEngineViewPrivate::contextMenuRequested(const WebEngineContextMenu { Q_Q(QQuickWebEngineView); - if (!m_menuEnabled) { - qWarning("You are trying to open context menu on eglfs backend, which is not currently supported\n" - "See QTBUG-53467."); - return false; - } - // Assign the WebEngineView as the parent of the menu, so mouse events are properly propagated // on OSX. QObject *menu = ui()->addMenu(q, QString(), data.pos); @@ -354,7 +365,7 @@ bool QQuickWebEngineViewPrivate::contextMenuRequested(const WebEngineContextMenu } // Now fire the popup() method on the top level menu - QMetaObject::invokeMethod(menu, "popup"); + ui()->showMenu(menu); return true; } |