From 4504d9ca31986b6e939b1a434b724404b72102f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 15 May 2019 16:05:04 +0200 Subject: macOS: Remove broken UTF-16 handling in QMacPasteboard::retrieveData The logic seems to be to prefer public.utf16-plain-text over the UTI reported by the mime converter's flavorFor, but this doesn't make sense for two reasons: 1. If the converter reports a UTI from flavorFor, we should respect that as the preferred UTI. QMacPasteboardMimeUnicodeText already reports public.utf16-plain-text as expected. 2. We don't know if the converter supports the public.utf16-plain-text UTI, which is the case for QMacPasteboardMimeTraditionalMacPlainText for example. The result is that we fail to retrieve any data. The reason we haven't been seeing this issue is that the code path above using qt_mac_get_pasteboardString will in most cases succeed and return early. Change-Id: I0b7e0d09a97389a229e7a945f17fef74ad5c2fc0 Reviewed-by: Volker Hilsheimer Reviewed-by: Richard Moe Gustavsen --- src/plugins/platforms/cocoa/qmacclipboard.mm | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/plugins/platforms/cocoa/qmacclipboard.mm') diff --git a/src/plugins/platforms/cocoa/qmacclipboard.mm b/src/plugins/platforms/cocoa/qmacclipboard.mm index ba6cfca219..554fd7c4c1 100644 --- a/src/plugins/platforms/cocoa/qmacclipboard.mm +++ b/src/plugins/platforms/cocoa/qmacclipboard.mm @@ -500,8 +500,6 @@ QMacPasteboard::retrieveData(const QString &format, QVariant::Type) const if (!str.isEmpty()) return str; } - if (checkForUtf16 && hasFlavor(QLatin1String("public.utf16-plain-text"))) - c_flavor = QLatin1String("public.utf16-plain-text"); QVariant ret; QList retList; -- cgit v1.2.3 From e6036cfc5ae1b0ab30ef3e23f0bb3362db32f1a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 15 May 2019 16:30:16 +0200 Subject: macOS: Better document plain-text code-path in QMacPasteboard::retrieveData MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Due to PasteboardCopyItemFlavorData converting newlines to '\r' for some UTIs we have traditionally had to shortcut these UTIs via NSStringPboardType instead of the mime converters such as QMacPasteboardMimeUnicodeText. Let's explain this a bit better for future generations. Note that public.utf8-plain-text doesn't seem to have this problem anymore, but it's left in for now to not cause any regressions due to behavior change. Change-Id: I7dce80828865c6323ed308780b8ca07b7a3e7c17 Reviewed-by: Volker Hilsheimer Reviewed-by: Morten Johan Sørvig Reviewed-by: Timur Pocheptsov --- src/plugins/platforms/cocoa/qmacclipboard.mm | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/plugins/platforms/cocoa/qmacclipboard.mm') diff --git a/src/plugins/platforms/cocoa/qmacclipboard.mm b/src/plugins/platforms/cocoa/qmacclipboard.mm index 554fd7c4c1..358a6b49fd 100644 --- a/src/plugins/platforms/cocoa/qmacclipboard.mm +++ b/src/plugins/platforms/cocoa/qmacclipboard.mm @@ -489,13 +489,12 @@ QMacPasteboard::retrieveData(const QString &format, QVariant::Type) const QMacInternalPasteboardMime *c = mimes.at(mime); QString c_flavor = c->flavorFor(format); if (!c_flavor.isEmpty()) { - // Handle text/plain a little differently. Try handling Unicode first. - bool checkForUtf16 = (c_flavor == QLatin1String("com.apple.traditional-mac-plain-text") - || c_flavor == QLatin1String("public.utf8-plain-text")); - if (checkForUtf16 || c_flavor == QLatin1String("public.utf16-plain-text")) { - // Try to get the NSStringPboardType from NSPasteboard, newlines are mapped - // correctly (as '\n') in this data. The 'public.utf16-plain-text' type - // usually maps newlines to '\r' instead. + // Converting via PasteboardCopyItemFlavorData below will for some UITs result + // in newlines mapping to '\r' instead of '\n'. To work around this we shortcut + // the conversion via NSPasteboard's NSStringPboardType if possible. + if (c_flavor == QLatin1String("com.apple.traditional-mac-plain-text") + || c_flavor == QLatin1String("public.utf8-plain-text") + || c_flavor == QLatin1String("public.utf16-plain-text")) { QString str = qt_mac_get_pasteboardString(paste); if (!str.isEmpty()) return str; -- cgit v1.2.3