diff --git a/widget/gtk/mozgtk/mozgtk.c b/widget/gtk/mozgtk/mozgtk.c --- a/widget/gtk/mozgtk/mozgtk.c +++ b/widget/gtk/mozgtk/mozgtk.c @@ -413,10 +413,11 @@ STUB(gtk_table_attach) STUB(gtk_table_get_type) STUB(gtk_table_new) STUB(gtk_target_list_add) STUB(gtk_target_list_add_image_targets) +STUB(gtk_target_list_add_text_targets) STUB(gtk_target_list_new) STUB(gtk_target_list_unref) STUB(gtk_targets_include_image) STUB(gtk_targets_include_text) STUB(gtk_target_table_free) diff --git a/widget/gtk/nsClipboard.cpp b/widget/gtk/nsClipboard.cpp --- a/widget/gtk/nsClipboard.cpp +++ b/widget/gtk/nsClipboard.cpp @@ -11,10 +11,11 @@ #include "nsClipboard.h" #include "nsClipboardX11.h" #if defined(MOZ_WAYLAND) #include "nsClipboardWayland.h" #endif +#include "nsContentUtils.h" #include "HeadlessClipboard.h" #include "nsSupportsPrimitives.h" #include "nsString.h" #include "nsReadableUtils.h" #include "nsPrimitiveHelpers.h" @@ -161,26 +162,18 @@ // Add all the flavors to this widget's supported type. bool imagesAdded = false; for (uint32_t i = 0; i < flavors.Length(); i++) { nsCString& flavorStr = flavors[i]; - // special case text/unicode since we can handle all of - // the string types + // Special case text/unicode since we can handle all of the string types. if (flavorStr.EqualsLiteral(kUnicodeMime)) { - gtk_target_list_add(list, gdk_atom_intern("UTF8_STRING", FALSE), 0, 0); - gtk_target_list_add(list, gdk_atom_intern("COMPOUND_TEXT", FALSE), 0, 0); - gtk_target_list_add(list, gdk_atom_intern("TEXT", FALSE), 0, 0); - gtk_target_list_add(list, GDK_SELECTION_TYPE_STRING, 0, 0); + gtk_target_list_add_text_targets(list, 0); continue; } - if (flavorStr.EqualsLiteral(kNativeImageMime) || - flavorStr.EqualsLiteral(kPNGImageMime) || - flavorStr.EqualsLiteral(kJPEGImageMime) || - flavorStr.EqualsLiteral(kJPGImageMime) || - flavorStr.EqualsLiteral(kGIFImageMime)) { - // don't bother adding image targets twice + if (nsContentUtils::IsFlavorImage(flavorStr)) { + // Don't bother adding image targets twice if (!imagesAdded) { // accept any writable image type gtk_target_list_add_image_targets(list, 0, TRUE); imagesAdded = true; } @@ -480,16 +473,12 @@ nsCOMPtr item; uint32_t len; GdkAtom selectionTarget = gtk_selection_data_get_target(aSelectionData); - // Check to see if the selection data includes any of the string - // types that we support. - if (selectionTarget == gdk_atom_intern ("STRING", FALSE) || - selectionTarget == gdk_atom_intern ("TEXT", FALSE) || - selectionTarget == gdk_atom_intern ("COMPOUND_TEXT", FALSE) || - selectionTarget == gdk_atom_intern ("UTF8_STRING", FALSE)) { + // Check to see if the selection data is some text type. + if (gtk_targets_include_text(&selectionTarget, 1)) { // Try to convert our internal type into a text string. Get // the transferable for this clipboard and try to get the // text/unicode type for it. rv = trans->GetTransferData("text/unicode", getter_AddRefs(item), &len); @@ -501,18 +490,14 @@ if (!wideString) return; nsAutoString ucs2string; wideString->GetData(ucs2string); - char *utf8string = ToNewUTF8String(ucs2string); - if (!utf8string) - return; + NS_ConvertUTF16toUTF8 utf8string(ucs2string); - gtk_selection_data_set_text (aSelectionData, utf8string, - strlen(utf8string)); - - free(utf8string); + gtk_selection_data_set_text(aSelectionData, utf8string.get(), + utf8string.Length()); return; } // Check to see if the selection data is an image type if (gtk_targets_include_image(&selectionTarget, 1, TRUE)) {