2008-09-10 Alp Toker <alp@nuanti.com>
authoralp@webkit.org <alp@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 Sep 2008 20:30:18 +0000 (20:30 +0000)
committeralp@webkit.org <alp@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 Sep 2008 20:30:18 +0000 (20:30 +0000)
        Reviewed by Mark Rowe.

        https://bugs.webkit.org/show_bug.cgi?id=17267
        [GTK] Primary selection/clipboard support

        Implement primary selection support (copying only, no paste yet).

        * WebCoreSupport/EditorClientGtk.cpp:
        (WebKit::clipboard_get_contents_cb):
        (WebKit::clipboard_clear_contents_cb):
        (WebKit::EditorClient::respondToChangedSelection):

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

WebKit/gtk/ChangeLog
WebKit/gtk/WebCoreSupport/EditorClientGtk.cpp

index ccb41a5..2491ada 100644 (file)
@@ -1,3 +1,17 @@
+2008-09-10  Alp Toker  <alp@nuanti.com>
+
+        Reviewed by Mark Rowe.
+
+        https://bugs.webkit.org/show_bug.cgi?id=17267
+        [GTK] Primary selection/clipboard support
+
+        Implement primary selection support (copying only, no paste yet).
+
+        * WebCoreSupport/EditorClientGtk.cpp:
+        (WebKit::clipboard_get_contents_cb):
+        (WebKit::clipboard_clear_contents_cb):
+        (WebKit::EditorClient::respondToChangedSelection):
+
 2008-09-07  Cameron Zwarich  <cwzwarich@uwaterloo.ca>
 
         Reviewed by Maciej Stachowiak.
 2008-09-07  Cameron Zwarich  <cwzwarich@uwaterloo.ca>
 
         Reviewed by Maciej Stachowiak.
index 81517b4..62f1f27 100644 (file)
@@ -20,6 +20,7 @@
 #include "config.h"
 #include "EditorClientGtk.h"
 
 #include "config.h"
 #include "EditorClientGtk.h"
 
+#include "CString.h"
 #include "EditCommand.h"
 #include "Editor.h"
 #include "FocusController.h"
 #include "EditCommand.h"
 #include "Editor.h"
 #include "FocusController.h"
@@ -29,6 +30,7 @@
 #include "NotImplemented.h"
 #include "Page.h"
 #include "PlatformKeyboardEvent.h"
 #include "NotImplemented.h"
 #include "Page.h"
 #include "PlatformKeyboardEvent.h"
+#include "markup.h"
 #include "webkitprivate.h"
 
 using namespace WebCore;
 #include "webkitprivate.h"
 
 using namespace WebCore;
@@ -162,17 +164,60 @@ void EditorClient::respondToChangedContents()
     notImplemented();
 }
 
     notImplemented();
 }
 
+#if GTK_CHECK_VERSION(2,10,0)
+static void clipboard_get_contents_cb(GtkClipboard* clipboard, GtkSelectionData* selection_data, guint info, gpointer data)
+{
+    WebKitWebView* webView = reinterpret_cast<WebKitWebView*>(data);
+    Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
+    PassRefPtr<Range> selectedRange = frame->selection()->toRange();
+
+    if (static_cast<gint>(info) == WEBKIT_WEB_VIEW_TARGET_INFO_HTML) {
+        String markup = createMarkup(selectedRange.get(), 0, AnnotateForInterchange);
+        gtk_selection_data_set(selection_data, selection_data->target, 8,
+                               reinterpret_cast<const guchar*>(markup.utf8().data()), markup.utf8().length());
+    } else {
+        String text = selectedRange->text();
+        gtk_selection_data_set_text(selection_data, text.utf8().data(), text.utf8().length());
+    }
+}
+
+static void clipboard_clear_contents_cb(GtkClipboard* clipboard, gpointer data)
+{
+    WebKitWebView* webView = reinterpret_cast<WebKitWebView*>(data);
+    Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
+
+    // Collapse the selection without clearing it
+    frame->selection()->setBase(frame->selection()->extent(), frame->selection()->affinity());
+}
+#endif
+
 void EditorClient::respondToChangedSelection()
 {
     WebKitWebViewPrivate* priv = m_webView->priv;
 void EditorClient::respondToChangedSelection()
 {
     WebKitWebViewPrivate* priv = m_webView->priv;
-
     Frame* targetFrame = core(m_webView)->focusController()->focusedOrMainFrame();
     Frame* targetFrame = core(m_webView)->focusController()->focusedOrMainFrame();
-    if (!targetFrame || !targetFrame->editor()->hasComposition())
+
+    if (!targetFrame)
         return;
 
     if (targetFrame->editor()->ignoreCompositionSelectionChange())
         return;
 
         return;
 
     if (targetFrame->editor()->ignoreCompositionSelectionChange())
         return;
 
+#if GTK_CHECK_VERSION(2,10,0)
+    GtkClipboard* clipboard = gtk_widget_get_clipboard(GTK_WIDGET(m_webView), GDK_SELECTION_PRIMARY);
+    if (targetFrame->selection()->isRange()) {
+        GtkTargetList* targetList = webkit_web_view_get_copy_target_list(m_webView);
+        gint targetCount;
+        GtkTargetEntry* targets = gtk_target_table_new_from_list(targetList, &targetCount);
+        gtk_clipboard_set_with_owner(clipboard, targets, targetCount,
+                                     clipboard_get_contents_cb, clipboard_clear_contents_cb, G_OBJECT(m_webView));
+        gtk_target_table_free(targets, targetCount);
+    } else if (gtk_clipboard_get_owner(clipboard) == G_OBJECT(m_webView))
+        gtk_clipboard_clear(clipboard);
+#endif
+
+    if (!targetFrame->editor()->hasComposition())
+        return;
+
     unsigned start;
     unsigned end;
     if (!targetFrame->editor()->getCompositionSelection(start, end)) {
     unsigned start;
     unsigned end;
     if (!targetFrame->editor()->getCompositionSelection(start, end)) {