diff options
author | Martin Negyokru <negyokru@inf.u-szeged.hu> | 2023-11-21 15:45:51 +0100 |
---|---|---|
committer | Michal Klocek <michal.klocek@qt.io> | 2024-01-10 16:31:23 +0000 |
commit | 3fcf62c0c19e89abbd154bc5f1fc8d84099aa58e (patch) | |
tree | f79942ec3e0f49f44b6f64823a0a5f5f42c11edc /src/webenginewidgets/api | |
parent | 8bedcaac01cd0a08031f42acfd7ebcc15f541964 (diff) |
Fix text formatting in JS Dialogs
Use plain text instead of escaped html to match
other browsers behavior.
Also set the text format for qml dialogs.
Pick-to: 6.6 6.7
Fixes: QTBUG-119245
Task-number: QTBUG-83338
Change-Id: Icb2c9fd21f27487418835372d6afda96a6812cc3
Reviewed-by: Michal Klocek <michal.klocek@qt.io>
Diffstat (limited to 'src/webenginewidgets/api')
-rw-r--r-- | src/webenginewidgets/api/qwebengineview.cpp | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/src/webenginewidgets/api/qwebengineview.cpp b/src/webenginewidgets/api/qwebengineview.cpp index 952ebe7cd..c4a0da4d9 100644 --- a/src/webenginewidgets/api/qwebengineview.cpp +++ b/src/webenginewidgets/api/qwebengineview.cpp @@ -553,8 +553,10 @@ bool QWebEngineViewPrivate::showAuthorizationDialog(const QString &title, const { #if QT_CONFIG(messagebox) Q_Q(QWebEngineView); - return QMessageBox::question(q, title, message, QMessageBox::Yes, QMessageBox::No) - == QMessageBox::Yes; + QMessageBox msgBox(QMessageBox::Question, title, message, QMessageBox::Yes | QMessageBox::No, + q, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint); + msgBox.setTextFormat(Qt::PlainText); + return msgBox.exec() == QMessageBox::Yes; #else return false; #endif // QT_CONFIG(messagebox) @@ -564,8 +566,12 @@ void QWebEngineViewPrivate::javaScriptAlert(const QUrl &url, const QString &msg) { #if QT_CONFIG(messagebox) Q_Q(QWebEngineView); - QMessageBox::information(q, QStringLiteral("Javascript Alert - %1").arg(url.toString()), - msg.toHtmlEscaped()); + QMessageBox msgBox(QMessageBox::Information, + QStringLiteral("Javascript Alert - %1").arg(url.toString()), + msg, QMessageBox::Ok, q, + Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint); + msgBox.setTextFormat(Qt::PlainText); + msgBox.exec(); #else Q_UNUSED(msg); #endif // QT_CONFIG(messagebox) @@ -575,10 +581,12 @@ bool QWebEngineViewPrivate::javaScriptConfirm(const QUrl &url, const QString &ms { #if QT_CONFIG(messagebox) Q_Q(QWebEngineView); - return (QMessageBox::information(q, - QStringLiteral("Javascript Confirm - %1").arg(url.toString()), - msg.toHtmlEscaped(), QMessageBox::Ok, QMessageBox::Cancel) - == QMessageBox::Ok); + QMessageBox msgBox(QMessageBox::Information, + QStringLiteral("Javascript Confirm - %1").arg(url.toString()), + msg, QMessageBox::Ok | QMessageBox::Cancel, q, + Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint); + msgBox.setTextFormat(Qt::PlainText); + return msgBox.exec() == QMessageBox::Ok; #else Q_UNUSED(msg); return false; @@ -591,10 +599,16 @@ bool QWebEngineViewPrivate::javaScriptPrompt(const QUrl &url, const QString &msg #if QT_CONFIG(inputdialog) Q_Q(QWebEngineView); bool ret = false; + + // Workaround: Do not interpret text as Qt::RichText + // QInputDialog uses Qt::AutoText that interprets the text string as + // Qt::RichText if Qt::mightBeRichText() returns true, otherwise as Qt::PlainText. + const QString message = Qt::mightBeRichText(msg) ? msg.toHtmlEscaped() : msg; + if (result) *result = QInputDialog::getText( q, QStringLiteral("Javascript Prompt - %1").arg(url.toString()), - msg.toHtmlEscaped(), QLineEdit::Normal, defaultValue.toHtmlEscaped(), &ret); + message, QLineEdit::Normal, defaultValue, &ret); return ret; #else Q_UNUSED(msg); |