2007-10-23 Alp Toker <alp@atoker.com>
authoralp <alp@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 24 Oct 2007 04:40:58 +0000 (04:40 +0000)
committeralp <alp@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 24 Oct 2007 04:40:58 +0000 (04:40 +0000)
        Reviewed by Maciej.

        http://bugs.webkit.org/show_bug.cgi?id=14412
        [GDK] Clipboard support

        Initial clipboard implementation for the GTK+ port.

        * platform/gtk/ClipboardGtk.cpp:
        (WebCore::Editor::newGeneralClipboard):
        * platform/gtk/PasteboardGtk.cpp:
        (WebCore::Pasteboard::generalPasteboard):
        (WebCore::Pasteboard::Pasteboard):
        (WebCore::Pasteboard::~Pasteboard):
        (WebCore::Pasteboard::writeSelection):
        (WebCore::Pasteboard::writeImage):
        (WebCore::Pasteboard::clear):
        (WebCore::Pasteboard::plainText):
        * platform/gtk/TemporaryLinkStubs.cpp:

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

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

index 6bb8076..108b03d 100644 (file)
@@ -1,3 +1,24 @@
+2007-10-23  Alp Toker  <alp@atoker.com>
+
+        Reviewed by Maciej.
+
+        http://bugs.webkit.org/show_bug.cgi?id=14412
+        [GDK] Clipboard support
+
+        Initial clipboard implementation for the GTK+ port.
+
+        * platform/gtk/ClipboardGtk.cpp:
+        (WebCore::Editor::newGeneralClipboard):
+        * platform/gtk/PasteboardGtk.cpp:
+        (WebCore::Pasteboard::generalPasteboard):
+        (WebCore::Pasteboard::Pasteboard):
+        (WebCore::Pasteboard::~Pasteboard):
+        (WebCore::Pasteboard::writeSelection):
+        (WebCore::Pasteboard::writeImage):
+        (WebCore::Pasteboard::clear):
+        (WebCore::Pasteboard::plainText):
+        * platform/gtk/TemporaryLinkStubs.cpp:
+
 2007-10-23  Timothy Hatcher  <timothy@apple.com>
 
         Reviewed by Adam.
index 3ffa3f1..0e296f5 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 2006, 2007 Apple Inc.  All rights reserved.
  * Copyright (C) 2007, Holger Hans Peter Freyther
+ * Copyright (C) 2007 Alp Toker <alp@atoker.com>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #include "NotImplemented.h"
 #include "StringHash.h"
 
+#include "Editor.h"
+
 namespace WebCore {
+PassRefPtr<Clipboard> Editor::newGeneralClipboard(ClipboardAccessPolicy policy)
+{
+    return new ClipboardGtk(policy, false);
+}
+
 ClipboardGtk::ClipboardGtk(ClipboardAccessPolicy policy, bool forDragging)
     : Clipboard(policy, forDragging)
 {
index a492893..da497f6 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 2006, 2007 Apple Inc.  All rights reserved.
  * Copyright (C) 2007 Holger Hans Peter Freyther
+ * Copyright (C) 2007 Alp Toker <alp@atoker.com>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #include "config.h"
 #include "Pasteboard.h"
 
+#include "CString.h"
 #include "DocumentFragment.h"
+#include "Frame.h"
 #include "NotImplemented.h"
 #include "PlatformString.h"
+#include "Image.h"
+#include "RenderImage.h"
+#include "KURL.h"
+
+#include <gtk/gtk.h>
 
 namespace WebCore {
 
 Pasteboard* Pasteboard::generalPasteboard()
 {
+    static Pasteboard* pasteboard = new Pasteboard();
+    return pasteboard;
+}
+
+Pasteboard::Pasteboard()
+{
     notImplemented();
-    return 0;
 }
 
-void Pasteboard::writeSelection(Range*, bool, Frame*)
+Pasteboard::~Pasteboard()
 {
     notImplemented();
 }
 
+void Pasteboard::writeSelection(Range* selectedRange, bool canSmartCopyOrDelete, Frame* frame)
+{
+    GtkClipboard* clipboard = gtk_clipboard_get_for_display(gdk_display_get_default(), GDK_SELECTION_CLIPBOARD);
+
+    String text = frame->selectedText();
+    gtk_clipboard_set_text(clipboard, text.utf8().data(), text.utf8().length());
+}
+
 void Pasteboard::writeURL(const KURL&, const String&, Frame*)
 {
     notImplemented();
 }
 
-void Pasteboard::writeImage(Node*, const KURL&, const String&)
+void Pasteboard::writeImage(Node* node, const KURL&, const String&)
 {
+    // TODO: Enable this when Image gets GdkPixbuf support
+
+    /*
+    GtkClipboard* clipboard = gtk_clipboard_get_for_display(gdk_display_get_default(), GDK_SELECTION_CLIPBOARD);
+
+    ASSERT(node && node->renderer() && node->renderer()->isImage());
+    RenderImage* renderer = static_cast<RenderImage*>(node->renderer());
+    CachedImage* cachedImage = static_cast<CachedImage*>(renderer->cachedImage());
+    ASSERT(cachedImage);
+    Image* image = cachedImage->image();
+    ASSERT(image);
+
+    gtk_clipboard_set_image(clipboard, image->pixbuf());
+    */
+
     notImplemented();
 }
 
 void Pasteboard::clear()
 {
-    notImplemented();
+    GtkClipboard* clipboard = gtk_clipboard_get_for_display(gdk_display_get_default(), GDK_SELECTION_CLIPBOARD);
+
+    gtk_clipboard_clear(clipboard);
 }
 
 bool Pasteboard::canSmartReplace()
@@ -76,17 +114,13 @@ PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame*, PassRefPtr<Ran
 
 String Pasteboard::plainText(Frame*)
 {
-    notImplemented();
-    return String();
-}
+    GtkClipboard* clipboard = gtk_clipboard_get_for_display(gdk_display_get_default(), GDK_SELECTION_CLIPBOARD);
 
-Pasteboard::Pasteboard()
-{
-    notImplemented();
-}
+    gchar* utf8 = gtk_clipboard_wait_for_text(clipboard);
+    String text = String::fromUTF8(utf8);
+    if (utf8)
+        g_free(utf8);
 
-Pasteboard::~Pasteboard()
-{
-    notImplemented();
+    return text;
 }
 }
index 4d36b13..655c836 100644 (file)
@@ -29,7 +29,6 @@
 
 #include "AXObjectCache.h"
 #include "CachedPage.h"
-#include "Clipboard.h"
 #include "Editor.h"
 #include "FrameView.h"
 #include "FTPDirectoryDocument.h"
@@ -73,8 +72,6 @@ void WebCore::setFocusRingColorChangeFunction(void (*)()) { }
 
 void CachedPage::close() { notImplemented(); }
 
-PassRefPtr<Clipboard> Editor::newGeneralClipboard(ClipboardAccessPolicy) { notImplemented(); return 0; }
-
 namespace WebCore {
 Vector<String> supportedKeySizes() { notImplemented(); return Vector<String>(); }
 String signedPublicKeyAndChallengeString(unsigned keySizeIndex, const String &challengeString, const KURL &url) { return String(); }