[GTK][WK2] Primary clipboard should be updated with the current selection in X11...
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Jan 2012 15:03:50 +0000 (15:03 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Jan 2012 15:03:50 +0000 (15:03 +0000)
https://bugs.webkit.org/show_bug.cgi?id=77097

Reviewed by Martin Robinson.

* WebProcess/WebCoreSupport/WebEditorClient.cpp:
(WebKit::WebEditorClient::respondToChangedSelection): Call
setSelectionPrimaryClipboardIfNeeded() to update primary clipboard
in X11 platforms.
* WebProcess/WebCoreSupport/WebEditorClient.h:
* WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp:
(WebKit::collapseSelection): Callback called when clearing
clipboard contents.
(WebKit::WebEditorClient::setSelectionPrimaryClipboardIfNeeded):
Updaye primary clipboard with the current selection.

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

Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.cpp
Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.h
Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp

index 5c4c170..2bb7305 100644 (file)
@@ -1,3 +1,21 @@
+2012-01-26  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK][WK2] Primary clipboard should be updated with the current selection in X11 platforms
+        https://bugs.webkit.org/show_bug.cgi?id=77097
+
+        Reviewed by Martin Robinson.
+
+        * WebProcess/WebCoreSupport/WebEditorClient.cpp:
+        (WebKit::WebEditorClient::respondToChangedSelection): Call
+        setSelectionPrimaryClipboardIfNeeded() to update primary clipboard
+        in X11 platforms.
+        * WebProcess/WebCoreSupport/WebEditorClient.h:
+        * WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp:
+        (WebKit::collapseSelection): Callback called when clearing
+        clipboard contents.
+        (WebKit::WebEditorClient::setSelectionPrimaryClipboardIfNeeded):
+        Updaye primary clipboard with the current selection.
+
 2012-01-26  Zeno Albisser  <zeno@webkit.org>
 
         [Qt][WK2] Use QVariant for payload data in application URL schemes.
index efb75be..f22b260 100644 (file)
@@ -195,9 +195,11 @@ void WebEditorClient::respondToChangedSelection(Frame* frame)
     unsigned start;
     unsigned end;
     m_page->send(Messages::WebPageProxy::DidChangeCompositionSelection(frame->editor()->getCompositionSelection(start, end)));
+#elif PLATFORM(GTK)
+    setSelectionPrimaryClipboardIfNeeded(frame);
 #endif
 }
-    
+
 void WebEditorClient::didEndEditing()
 {
     DEFINE_STATIC_LOCAL(String, WebViewDidEndEditingNotification, ("WebViewDidEndEditingNotification"));
index 6664275..8f26220 100644 (file)
@@ -121,6 +121,7 @@ private:
 #if PLATFORM(GTK)
     bool executePendingEditorCommands(WebCore::Frame*, Vector<WTF::String>, bool) OVERRIDE;
     void getEditorCommandsForKeyEvent(const WebCore::KeyboardEvent*, Vector<WTF::String>&) OVERRIDE;
+    void setSelectionPrimaryClipboardIfNeeded(WebCore::Frame*) OVERRIDE;
 #endif
 
     TextCheckerClient* textChecker()  OVERRIDE { return this; }
index 964a395..f59e697 100644 (file)
@@ -25,7 +25,9 @@
 #include "WebPage.h"
 #include "WebPageProxyMessages.h"
 #include "WebProcess.h"
+#include <WebCore/DataObjectGtk.h>
 #include <WebCore/KeyboardEvent.h>
+#include <WebCore/PasteboardHelper.h>
 #include <WebCore/NotImplemented.h>
 
 using namespace WebCore;
@@ -127,4 +129,38 @@ void WebEditorClient::handleInputMethodKeydown(KeyboardEvent*)
     notImplemented();
 }
 
+#if PLATFORM(X11)
+static Frame* frameSettingClipboard;
+static void collapseSelection(GtkClipboard* clipboard, Frame* frame)
+{
+    if (frameSettingClipboard && frameSettingClipboard == frame)
+        return;
+
+    // Collapse the selection without clearing it.
+    ASSERT(frame);
+    frame->selection()->setBase(frame->selection()->extent(), frame->selection()->affinity());
+}
+#endif
+
+void WebEditorClient::setSelectionPrimaryClipboardIfNeeded(Frame* frame)
+{
+#if PLATFORM(X11)
+    GtkClipboard* clipboard = PasteboardHelper::defaultPasteboardHelper()->getPrimarySelectionClipboard(frame);
+    DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
+
+    if (!frame->selection()->isRange())
+        return;
+
+    dataObject->clearAll();
+    dataObject->setRange(frame->selection()->toNormalizedRange());
+
+    frameSettingClipboard = frame;
+    GClosure* callback = g_cclosure_new(G_CALLBACK(collapseSelection), frame, 0);
+    g_closure_set_marshal(callback, g_cclosure_marshal_VOID__VOID);
+    PasteboardHelper::defaultPasteboardHelper()->writeClipboardContents(clipboard, PasteboardHelper::DoNotIncludeSmartPaste, callback);
+    frameSettingClipboard = 0;
+#endif
+}
+
+
 }