diff options
author | Allan Sandfeld Jensen <allan.jensen@digia.com> | 2014-12-08 14:27:10 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2015-01-06 13:43:08 +0100 |
commit | c7412da7727fc51a1f89cbe529c5d4a99adcfd10 (patch) | |
tree | f03355aee01e8999fe56f0aaabd30ee59cca69d4 | |
parent | 1dce6f9ed4508f77856d32b5f8957a81ddd5f790 (diff) | |
download | qtwebkit-c7412da7727fc51a1f89cbe529c5d4a99adcfd10.tar.gz |
Support MSIE compatible pasteboard types
Treat 'Text' pasteboard type as 'text/plain' matching Apple and GTK
webkit ports and the whatwg spec.
Task-number: QTBUG-43149
Change-Id: Iac491fd15f1e9e8539daabf30a61e64921c82222
Reviewed-by: Michael BrĂ¼ning <michael.bruning@theqtcompany.com>
Reviewed-by: Pierre Rossi <pierre.rossi@theqtcompany.com>
-rw-r--r-- | Source/WebCore/platform/qt/PasteboardQt.cpp | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/Source/WebCore/platform/qt/PasteboardQt.cpp b/Source/WebCore/platform/qt/PasteboardQt.cpp index 2bcdd5ffa..9114fd571 100644 --- a/Source/WebCore/platform/qt/PasteboardQt.cpp +++ b/Source/WebCore/platform/qt/PasteboardQt.cpp @@ -58,6 +58,19 @@ static bool isHtmlMimeType(const String& type) return type == "text/html" || type.startsWith("text/html;"); } +static String normalizeMimeType(const String& type) +{ + // http://www.whatwg.org/specs/web-apps/current-work/multipage/dnd.html#dom-datatransfer-setdata + String qType = type.lower(); + + if (qType == "text") + qType = ASCIILiteral("text/plain"); + else if (qType == "url") + qType = ASCIILiteral("text/uri-list"); + + return qType; +} + PassOwnPtr<Pasteboard> Pasteboard::create(const QMimeData* readableClipboard, bool isForDragAndDrop) { return adoptPtr(new Pasteboard(readableClipboard, isForDragAndDrop)); @@ -313,13 +326,15 @@ String Pasteboard::readString(const String& type) if (!data) return String(); - if (isHtmlMimeType(type) && data->hasHtml()) + String mimeType = normalizeMimeType(type); + + if (isHtmlMimeType(mimeType) && data->hasHtml()) return data->html(); - if (isTextMimeType(type) && data->hasText()) + if (isTextMimeType(mimeType) && data->hasText()) return data->text(); - QByteArray rawData = data->data(type); + QByteArray rawData = data->data(mimeType); QString stringData = QTextCodec::codecForName("UTF-16")->toUnicode(rawData); return stringData; } @@ -329,13 +344,15 @@ bool Pasteboard::writeString(const String& type, const String& data) if (!m_writableData) m_writableData = new QMimeData; - if (isTextMimeType(type)) + String mimeType = normalizeMimeType(type); + + if (isTextMimeType(mimeType)) m_writableData->setText(QString(data)); - else if (isHtmlMimeType(type)) + else if (isHtmlMimeType(mimeType)) m_writableData->setHtml(QString(data)); else { QByteArray array(reinterpret_cast<const char*>(data.characters()), data.length() * 2); - m_writableData->setData(QString(type), array); + m_writableData->setData(QString(mimeType), array); } return true; |