+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.
#include "config.h"
#include "EditorClientGtk.h"
+#include "CString.h"
#include "EditCommand.h"
#include "Editor.h"
#include "FocusController.h"
#include "NotImplemented.h"
#include "Page.h"
#include "PlatformKeyboardEvent.h"
+#include "markup.h"
#include "webkitprivate.h"
using namespace WebCore;
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;
-
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)) {