From fb9629c1aa53d743fa9cef6347789cb147060749 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Sun, 6 Mar 2011 18:13:54 +0100 Subject: [PATCH] Work around copying bug in WebKitGTK+ Fixes: https://bugs.launchpad.net/midori/+bug/707888 --- midori/midori-browser.c | 9 +++++++++ midori/midori-view.c | 23 +++++------------------ midori/sokoke.c | 13 +++++++++++++ midori/sokoke.h | 4 ++++ 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/midori/midori-browser.c b/midori/midori-browser.c index 584ca481..4f046914 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -2443,6 +2443,15 @@ _action_copy_activate (GtkAction* action, MidoriBrowser* browser) { GtkWidget* widget = gtk_window_get_focus (GTK_WINDOW (browser)); + /* Work around broken clipboard handling for the sake of the user */ + if (WEBKIT_IS_WEB_VIEW (widget)) + { + GtkWidget* scrolled = gtk_widget_get_parent (widget); + GtkWidget* view = gtk_widget_get_parent (scrolled); + const gchar* selected = midori_view_get_selected_text (MIDORI_VIEW (view)); + sokoke_widget_copy_clipboard (widget, selected); + return; + } if (G_LIKELY (widget) && g_signal_lookup ("copy-clipboard", G_OBJECT_TYPE (widget))) g_signal_emit_by_name (widget, "copy-clipboard"); } diff --git a/midori/midori-view.c b/midori/midori-view.c index a193a97d..2b87ae6a 100644 --- a/midori/midori-view.c +++ b/midori/midori-view.c @@ -1973,19 +1973,6 @@ gtk_widget_scroll_event_cb (WebKitWebView* web_view, } #if WEBKIT_CHECK_VERSION (1, 1, 15) -static void -midori_web_view_set_clipboard (GtkWidget* widget, - const gchar* text) -{ - GdkDisplay* display = gtk_widget_get_display (widget); - GtkClipboard* clipboard; - - clipboard = gtk_clipboard_get_for_display (display, GDK_SELECTION_CLIPBOARD); - gtk_clipboard_set_text (clipboard, text, -1); - clipboard = gtk_clipboard_get_for_display (display, GDK_SELECTION_PRIMARY); - gtk_clipboard_set_text (clipboard, text, -1); -} - static void midori_web_view_menu_new_window_activate_cb (GtkWidget* widget, MidoriView* view) @@ -2005,9 +1992,9 @@ midori_web_view_menu_link_copy_activate_cb (GtkWidget* widget, MidoriView* view) { if (g_str_has_prefix (view->link_uri, "mailto:")) - midori_web_view_set_clipboard (widget, view->link_uri + 7); + sokoke_widget_copy_clipboard (widget, view->link_uri + 7); else - midori_web_view_set_clipboard (widget, view->link_uri); + sokoke_widget_copy_clipboard (widget, view->link_uri); } static void @@ -2037,7 +2024,7 @@ midori_web_view_menu_image_copy_activate_cb (GtkWidget* widget, MidoriView* view) { gchar* uri = katze_object_get_string (view->hit_test, "image-uri"); - midori_web_view_set_clipboard (widget, uri); + sokoke_widget_copy_clipboard (widget, uri); g_free (uri); } @@ -2060,7 +2047,7 @@ midori_web_view_menu_video_copy_activate_cb (GtkWidget* widget, MidoriView* view) { gchar* uri = katze_object_get_string (view->hit_test, "media-uri"); - midori_web_view_set_clipboard (widget, uri); + sokoke_widget_copy_clipboard (widget, uri); g_free (uri); } @@ -2153,7 +2140,7 @@ static void midori_web_view_menu_copy_activate_cb (GtkWidget* widget, MidoriView* view) { - midori_web_view_set_clipboard (widget, view->selected_text); + sokoke_widget_copy_clipboard (widget, view->selected_text); } #endif diff --git a/midori/sokoke.c b/midori/sokoke.c index 219fc8f3..7bb38b12 100644 --- a/midori/sokoke.c +++ b/midori/sokoke.c @@ -2171,3 +2171,16 @@ sokoke_register_privacy_item (const gchar* name, items = g_list_append (items, item); return NULL; } + +void +sokoke_widget_copy_clipboard (GtkWidget* widget, + const gchar* text) +{ + GdkDisplay* display = gtk_widget_get_display (widget); + GtkClipboard* clipboard; + + clipboard = gtk_clipboard_get_for_display (display, GDK_SELECTION_CLIPBOARD); + gtk_clipboard_set_text (clipboard, text, -1); + clipboard = gtk_clipboard_get_for_display (display, GDK_SELECTION_PRIMARY); + gtk_clipboard_set_text (clipboard, text, -1); +} diff --git a/midori/sokoke.h b/midori/sokoke.h index 679e684c..88137861 100644 --- a/midori/sokoke.h +++ b/midori/sokoke.h @@ -280,4 +280,8 @@ sokoke_register_privacy_item (const gchar* name, const gchar* label, GCallback clear); +void +sokoke_widget_copy_clipboard (GtkWidget* widget, + const gchar* text); + #endif /* !__SOKOKE_H__ */ -- 2.39.5