From: alp@webkit.org Date: Wed, 10 Sep 2008 20:30:18 +0000 (+0000) Subject: 2008-09-10 Alp Toker X-Git-Url: http://git.webkit.org/?p=WebKit-https.git;a=commitdiff_plain;h=39963244975339f941f7b4bd6142078bae63099a 2008-09-10 Alp Toker 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 --- diff --git a/WebKit/gtk/ChangeLog b/WebKit/gtk/ChangeLog index ccb41a5..2491ada 100644 --- a/WebKit/gtk/ChangeLog +++ b/WebKit/gtk/ChangeLog @@ -1,3 +1,17 @@ +2008-09-10 Alp Toker + + 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 Reviewed by Maciej Stachowiak. diff --git a/WebKit/gtk/WebCoreSupport/EditorClientGtk.cpp b/WebKit/gtk/WebCoreSupport/EditorClientGtk.cpp index 81517b4..62f1f27 100644 --- a/WebKit/gtk/WebCoreSupport/EditorClientGtk.cpp +++ b/WebKit/gtk/WebCoreSupport/EditorClientGtk.cpp @@ -20,6 +20,7 @@ #include "config.h" #include "EditorClientGtk.h" +#include "CString.h" #include "EditCommand.h" #include "Editor.h" #include "FocusController.h" @@ -29,6 +30,7 @@ #include "NotImplemented.h" #include "Page.h" #include "PlatformKeyboardEvent.h" +#include "markup.h" #include "webkitprivate.h" using namespace WebCore; @@ -162,17 +164,60 @@ void EditorClient::respondToChangedContents() 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(data); + Frame* frame = core(webView)->focusController()->focusedOrMainFrame(); + PassRefPtr selectedRange = frame->selection()->toRange(); + + if (static_cast(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(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(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; - Frame* targetFrame = core(m_webView)->focusController()->focusedOrMainFrame(); - if (!targetFrame || !targetFrame->editor()->hasComposition()) + + if (!targetFrame) 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)) {