summaryrefslogtreecommitdiffstats
path: root/src/webenginewidgets
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2019-11-25 15:15:49 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2019-11-30 13:06:49 +0100
commitcc2b1d2b66806a67f13996cbb8631d5ea8cdf71a (patch)
tree388a85b86356e9d502356bcf8f06216a27c7025b /src/webenginewidgets
parent9d8ce033587c22658af9c9b06ac491ea840b71c1 (diff)
Fix regression in alt attribute of copied image urls
The linkText hasn't had the alt attribute for a long time, so instead add direct support for contextual title and alt text. Change-Id: I88e1c43374d855da7fb0d1ca42c0eb474012f0f2 Reviewed-by: Kirill Burtsev <kirill.burtsev@qt.io>
Diffstat (limited to 'src/webenginewidgets')
-rw-r--r--src/webenginewidgets/api/qwebenginepage.cpp26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp
index 1a8eae0b9..958238c9d 100644
--- a/src/webenginewidgets/api/qwebenginepage.cpp
+++ b/src/webenginewidgets/api/qwebenginepage.cpp
@@ -1426,10 +1426,14 @@ void QWebEnginePage::triggerAction(WebAction action, bool)
case CopyLinkToClipboard:
if (menuData && !menuData->unfilteredLinkUrl().isEmpty()) {
QString urlString = menuData->unfilteredLinkUrl().toString(QUrl::FullyEncoded);
- QString title = menuData->linkText().toHtmlEscaped();
+ QString linkText = menuData->linkText().toHtmlEscaped();
+ QString title = menuData->titleText();
+ if (!title.isEmpty())
+ title = QStringLiteral(" title=\"%1\"").arg(title.toHtmlEscaped());
QMimeData *data = new QMimeData();
data->setText(urlString);
- QString html = QStringLiteral("<a href=\"") + urlString + QStringLiteral("\">") + title + QStringLiteral("</a>");
+ QString html = QStringLiteral("<a href=\"") + urlString + QStringLiteral("\"") + title + QStringLiteral(">")
+ + linkText + QStringLiteral("</a>");
data->setHtml(html);
data->setUrls(QList<QUrl>() << menuData->unfilteredLinkUrl());
qApp->clipboard()->setMimeData(data);
@@ -1452,12 +1456,15 @@ void QWebEnginePage::triggerAction(WebAction action, bool)
case CopyImageUrlToClipboard:
if (menuData && menuData->mediaUrl().isValid() && menuData->mediaType() == WebEngineContextMenuData::MediaTypeImage) {
QString urlString = menuData->mediaUrl().toString(QUrl::FullyEncoded);
- QString title = menuData->linkText();
+ QString alt = menuData->altText();
+ if (!alt.isEmpty())
+ alt = QStringLiteral(" alt=\"%1\"").arg(alt.toHtmlEscaped());
+ QString title = menuData->titleText();
if (!title.isEmpty())
- title = QStringLiteral(" alt=\"%1\"").arg(title.toHtmlEscaped());
+ title = QStringLiteral(" title=\"%1\"").arg(title.toHtmlEscaped());
QMimeData *data = new QMimeData();
data->setText(urlString);
- QString html = QStringLiteral("<img src=\"") + urlString + QStringLiteral("\"") + title + QStringLiteral("></img>");
+ QString html = QStringLiteral("<img src=\"") + urlString + QStringLiteral("\"") + title + alt + QStringLiteral("></img>");
data->setHtml(html);
data->setUrls(QList<QUrl>() << menuData->mediaUrl());
qApp->clipboard()->setMimeData(data);
@@ -1475,12 +1482,17 @@ void QWebEnginePage::triggerAction(WebAction action, bool)
menuData->mediaType() == WebEngineContextMenuData::MediaTypeVideo))
{
QString urlString = menuData->mediaUrl().toString(QUrl::FullyEncoded);
+ QString title = menuData->titleText();
+ if (!title.isEmpty())
+ title = QStringLiteral(" title=\"%1\"").arg(title.toHtmlEscaped());
QMimeData *data = new QMimeData();
data->setText(urlString);
if (menuData->mediaType() == WebEngineContextMenuData::MediaTypeAudio)
- data->setHtml(QStringLiteral("<audio src=\"") + urlString + QStringLiteral("\"></audio>"));
+ data->setHtml(QStringLiteral("<audio src=\"") + urlString + QStringLiteral("\"") + title +
+ QStringLiteral("></audio>"));
else
- data->setHtml(QStringLiteral("<video src=\"") + urlString + QStringLiteral("\"></video>"));
+ data->setHtml(QStringLiteral("<video src=\"") + urlString + QStringLiteral("\"") + title +
+ QStringLiteral("></video>"));
data->setUrls(QList<QUrl>() << menuData->mediaUrl());
qApp->clipboard()->setMimeData(data);
}