Android: Fix for checking clipboard text mime type
Different mime types are widely used on mobile devices. For example all text copied from gmail is copied as text/html type. After 2937cf91c74b6562bf56e8872dfd2bfaafebb3cc commit there is a regression that makes it impossible to paste any text different than "text/plain". To fix it, any "text/*" mime type should be treat as it contains a text (not only "text/plain"). That will allow to paste different text mime types. During this work also tst_qclipboard testset was turned on for Android and new test (getTextFromHTMLMimeType) was added. Fixes: QTBUG-113461 Change-Id: I3ef9476b8facdc3b61f144bd55222898390127c9 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> (cherry picked from commit fdccb66a4e9a8b22c881c4775895b7af174b0b24) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
98ff5a2676
commit
477ecafaee
@ -895,7 +895,7 @@ public class QtNative
|
||||
|
||||
public static boolean hasClipboardText()
|
||||
{
|
||||
return hasClipboardMimeType("text/plain");
|
||||
return hasClipboardMimeType("text/(.*)");
|
||||
}
|
||||
|
||||
private static String getClipboardText()
|
||||
@ -953,7 +953,7 @@ public class QtNative
|
||||
|
||||
for (int i = 0; i < description.getMimeTypeCount(); ++i) {
|
||||
String itemMimeType = description.getMimeType(i);
|
||||
if (itemMimeType.equals(mimeType))
|
||||
if (itemMimeType.matches(mimeType))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -43,16 +43,16 @@ namespace QtAndroidClipboard
|
||||
"(Ljava/lang/String;)V",
|
||||
QJniObject::fromString(u.toEncoded()).object());
|
||||
}
|
||||
} else if (data->hasText()) { // hasText || hasUrls, so the order matter here.
|
||||
QJniObject::callStaticMethod<void>(applicationClass(),
|
||||
"setClipboardText", "(Ljava/lang/String;)V",
|
||||
QJniObject::fromString(data->text()).object());
|
||||
} else if (data->hasHtml()) {
|
||||
} else if (data->hasHtml()) { // html can contain text
|
||||
QJniObject::callStaticMethod<void>(applicationClass(),
|
||||
"setClipboardHtml",
|
||||
"(Ljava/lang/String;Ljava/lang/String;)V",
|
||||
QJniObject::fromString(data->text()).object(),
|
||||
QJniObject::fromString(data->html()).object());
|
||||
} else if (data->hasText()) { // hasText must be the last (the order matter here)
|
||||
QJniObject::callStaticMethod<void>(applicationClass(),
|
||||
"setClipboardText", "(Ljava/lang/String;)V",
|
||||
QJniObject::fromString(data->text()).object());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ endif()
|
||||
add_subdirectory(qpixelformat)
|
||||
add_subdirectory(qrasterwindow)
|
||||
add_subdirectory(qaddpostroutine)
|
||||
if(NOT ANDROID AND NOT UIKIT)
|
||||
if(NOT UIKIT)
|
||||
add_subdirectory(qclipboard)
|
||||
endif()
|
||||
if(TARGET Qt::Network)
|
||||
|
5
tests/auto/gui/kernel/qclipboard/test/BLACKLIST
Normal file
5
tests/auto/gui/kernel/qclipboard/test/BLACKLIST
Normal file
@ -0,0 +1,5 @@
|
||||
# QTBUG-87429
|
||||
[testSignals]
|
||||
android
|
||||
[setMimeData]
|
||||
android
|
@ -41,6 +41,7 @@ private slots:
|
||||
void testSignals();
|
||||
void setMimeData();
|
||||
void clearBeforeSetText();
|
||||
void getTextFromHTMLMimeType();
|
||||
# ifdef Q_OS_WIN
|
||||
void testWindowsMimeRegisterType();
|
||||
void testWindowsMime_data();
|
||||
@ -61,7 +62,7 @@ void tst_QClipboard::initTestCase()
|
||||
#if QT_CONFIG(clipboard)
|
||||
void tst_QClipboard::init()
|
||||
{
|
||||
#if QT_CONFIG(process)
|
||||
#if QT_CONFIG(process) && !defined(Q_OS_ANDROID)
|
||||
const QString testdataDir = QFileInfo(QFINDTESTDATA("copier")).absolutePath();
|
||||
QVERIFY2(QDir::setCurrent(testdataDir), qPrintable("Could not chdir to " + testdataDir));
|
||||
#endif
|
||||
@ -424,6 +425,24 @@ void tst_QClipboard::clearBeforeSetText()
|
||||
QCOMPARE(QGuiApplication::clipboard()->text(), text);
|
||||
}
|
||||
|
||||
void tst_QClipboard::getTextFromHTMLMimeType()
|
||||
{
|
||||
QClipboard * clipboard = QGuiApplication::clipboard();
|
||||
QMimeData * mimeData = new QMimeData();
|
||||
const QString testString("TEST");
|
||||
const QString htmlString(QLatin1String("<html><body>") + testString + QLatin1String("</body></html>"));
|
||||
|
||||
mimeData->setText(testString);
|
||||
mimeData->setHtml(htmlString);
|
||||
clipboard->setMimeData(mimeData);
|
||||
|
||||
QCOMPARE(clipboard->text(), testString);
|
||||
QVERIFY(clipboard->mimeData()->hasText());
|
||||
QVERIFY(clipboard->mimeData()->hasHtml());
|
||||
QCOMPARE(clipboard->mimeData()->text(), testString);
|
||||
QCOMPARE(clipboard->mimeData()->html(), htmlString);
|
||||
}
|
||||
|
||||
# ifdef Q_OS_WIN
|
||||
|
||||
using QWindowsMimeConverter = QWindowsMimeConverter;
|
||||
|
Loading…
x
Reference in New Issue
Block a user