2009-07-07 Jiahua Huang <jhuangjiahua@gmail.com>
authorjmalonzo@webkit.org <jmalonzo@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 7 Jul 2009 12:52:23 +0000 (12:52 +0000)
committerjmalonzo@webkit.org <jmalonzo@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 7 Jul 2009 12:52:23 +0000 (12:52 +0000)
        Reviewed by Jan Alonzo.

        [Gtk] Paste of rich text from firefox results garbled markup
        https://bugs.webkit.org/show_bug.cgi?id=26791

        Fix problem with UTF-16 clipboard pasted.

        * manual-tests/gtk/paste-richtext-from-firefox.html: Added.
        * platform/gtk/PasteboardGtk.cpp:
        (WebCore::Pasteboard::documentFragment):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@45592 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/manual-tests/gtk/paste-richtext-from-firefox.html [new file with mode: 0644]
WebCore/platform/gtk/PasteboardGtk.cpp

index 0dcc495..c29646a 100644 (file)
@@ -1,3 +1,16 @@
+2009-07-07  Jiahua Huang  <jhuangjiahua@gmail.com>
+
+        Reviewed by Jan Alonzo.
+
+        [Gtk] Paste of rich text from firefox results garbled markup
+        https://bugs.webkit.org/show_bug.cgi?id=26791
+
+        Fix problem with UTF-16 clipboard pasted.
+
+        * manual-tests/gtk/paste-richtext-from-firefox.html: Added.
+        * platform/gtk/PasteboardGtk.cpp:
+        (WebCore::Pasteboard::documentFragment):
+
 2009-07-07  Yury Semikhatsky  <yurys@chromium.org>
 
         Reviewed by Timothy Hatcher.
diff --git a/WebCore/manual-tests/gtk/paste-richtext-from-firefox.html b/WebCore/manual-tests/gtk/paste-richtext-from-firefox.html
new file mode 100644 (file)
index 0000000..c739a59
--- /dev/null
@@ -0,0 +1,30 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+    <head>
+        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+        <title>Paste rich text from firefox</title>
+    </head>
+    <body>
+        <p><b>BUG ID:</b>
+        <a href="https://bugs.webkit.org/show_bug.cgi?id=26791">Bugzilla bug 26791</a>
+        [Gtk] Paste of rich text from firefox results garbled markup
+        </p>
+        <h1>Paste rich text from firefox</h1>
+        <p>
+        <b>STEPS TO TEST:</b><br>
+        <ol>
+            <li>Launch FireFox to browse <a href="http://www.apple.com">http://www.apple.com</a></li>
+            <li>Select that text or picture from FireFox page</li>
+            <li>Copy them use <b>Ctrl-C</b> / Option-C, (or just select them on Linux)</li>
+            <li>Back in WebkitGtk, click inside the EditableArea below, </li>
+            <li>Paste them use <b>Ctrl-V</b> / Option-V, (or just Middle Mouse Click on Linux)</li>
+        </ol>
+        <p><b>Ensure</b> that text or picture has been pasted with formats and no garbled.</p>
+        <div title="EditableArea" contentEditable="true" 
+            style="display: block; border: 1px solid green; margin: 5px; padding: 15px;">
+            <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br />
+        </div>
+        </p>
+    </body>
+</html>
+
index 062ecb8..781baf5 100644 (file)
@@ -25,6 +25,7 @@
 #include "Frame.h"
 #include "NotImplemented.h"
 #include "PlatformString.h"
+#include "TextResourceDecoder.h"
 #include "Image.h"
 #include "RenderImage.h"
 #include "KURL.h"
@@ -163,7 +164,9 @@ PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame* frame, PassRefP
 
     if (GtkSelectionData* data = gtk_clipboard_wait_for_contents(clipboard, textHtml)) {
         ASSERT(data->data);
-        String html = String::fromUTF8(reinterpret_cast<gchar*>(data->data), data->length * data->format / 8);
+        RefPtr<TextResourceDecoder> decoder = TextResourceDecoder::create("text/plain", "UTF-8", true);
+        String html = decoder->decode(reinterpret_cast<char*>(data->data), data->length);
+        html += decoder->flush();
         gtk_selection_data_free(data);
 
         if (!html.isEmpty()) {