2007-12-05 Luca Bruno <lethalman88@gmail.com>
authoralp@webkit.org <alp@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 5 Dec 2007 20:26:42 +0000 (20:26 +0000)
committeralp@webkit.org <alp@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 5 Dec 2007 20:26:42 +0000 (20:26 +0000)
        Reviewed by Alp Toker.

        http://bugs.webkit.org/show_bug.cgi?id=16290
        [GTK] Pasting clipboard in rich text.

        * platform/gtk/PasteboardGtk.cpp:
        (Pasteboard::documentFragment): Implement rich text paste support.

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

WebCore/ChangeLog
WebCore/platform/gtk/PasteboardGtk.cpp

index 624259a741631e54439bfaf7a306d1217557a6e0..566ee00349ba1e130ac1ba955d0b1777a48f4e2b 100644 (file)
@@ -1,3 +1,13 @@
+2007-12-05  Luca Bruno  <lethalman88@gmail.com>
+
+        Reviewed by Alp Toker.
+
+        http://bugs.webkit.org/show_bug.cgi?id=16290
+        [GTK] Pasting clipboard in rich text.
+
+        * platform/gtk/PasteboardGtk.cpp:
+        (Pasteboard::documentFragment): Implement rich text paste support.
+
 2007-12-05  Adele Peterson  <adele@apple.com>
 
         Reviewed by Hyatt.
index 6301aed98d19e274099e0629c983ddc02f5e7d79..c90f16d63f803ec3f32e81452d769c3cbbeb25b3 100644 (file)
@@ -39,6 +39,7 @@
 #include "Image.h"
 #include "RenderImage.h"
 #include "KURL.h"
+#include "markup.h"
 
 #include <gtk/gtk.h>
 
@@ -106,9 +107,42 @@ bool Pasteboard::canSmartReplace()
     return false;
 }
 
-PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame*, PassRefPtr<Range>, bool, bool&)
+PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame* frame, PassRefPtr<Range> context,
+                                                          bool allowPlainText, bool& chosePlainText)
 {
-    notImplemented();
+#if GLIB_CHECK_VERSION(2,10,0)
+    GdkAtom textHtml = gdk_atom_intern_static_string("text/html");
+#else
+    GdkAtom textHtml = gdk_atom_intern("text/html", false);
+#endif
+    GtkClipboard* clipboard = gtk_clipboard_get_for_display(gdk_display_get_default(), GDK_SELECTION_CLIPBOARD);
+    chosePlainText = false;
+
+    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);
+        gtk_selection_data_free(data);
+
+        if (!html.isEmpty()) {
+            RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(frame->document(), html, "");
+            if (fragment)
+                return fragment.release();
+        }
+    }
+
+    if (!allowPlainText)
+        return 0;
+
+    if (gchar* utf8 = gtk_clipboard_wait_for_text(clipboard)) {
+        String text = String::fromUTF8(utf8);
+        g_free(utf8);
+
+        chosePlainText = true;
+        RefPtr<DocumentFragment> fragment = createFragmentFromText(context.get(), text);
+        if (fragment)
+            return fragment.release();
+    }
+
     return 0;
 }