| Index: chrome/browser/tab_contents/tab_contents_view_gtk.cc
|
| ===================================================================
|
| --- chrome/browser/tab_contents/tab_contents_view_gtk.cc (revision 19526)
|
| +++ chrome/browser/tab_contents/tab_contents_view_gtk.cc (working copy)
|
| @@ -7,6 +7,7 @@
|
| #include <gdk/gdk.h>
|
| #include <gtk/gtk.h>
|
|
|
| +#include "base/mime_util.h"
|
| #include "base/gfx/point.h"
|
| #include "base/gfx/rect.h"
|
| #include "base/gfx/size.h"
|
| @@ -16,7 +17,7 @@
|
| #include "chrome/browser/gtk/blocked_popup_container_view_gtk.h"
|
| #include "chrome/browser/gtk/browser_window_gtk.h"
|
| #include "chrome/browser/gtk/constrained_window_gtk.h"
|
| -#include "chrome/browser/gtk/dnd_registry.h"
|
| +#include "chrome/browser/gtk/gtk_dnd_util.h"
|
| #include "chrome/browser/gtk/gtk_floating_container.h"
|
| #include "chrome/browser/gtk/sad_tab_gtk.h"
|
| #include "chrome/browser/renderer_host/render_view_host.h"
|
| @@ -364,16 +365,33 @@
|
| void TabContentsViewGtk::StartDragging(const WebDropData& drop_data) {
|
| DCHECK(GetContentNativeView());
|
|
|
| - if (drop_data.plain_text.empty()) {
|
| - NOTIMPLEMENTED() << "Only plain text drags supported, sorry!";
|
| + int targets_mask = 0;
|
| +
|
| + if (!drop_data.plain_text.empty())
|
| + targets_mask |= GtkDndUtil::X_CHROME_TEXT_PLAIN;
|
| + if (drop_data.url.is_valid())
|
| + targets_mask |= GtkDndUtil::X_CHROME_TEXT_URI_LIST;
|
| + if (!drop_data.text_html.empty())
|
| + targets_mask |= GtkDndUtil::X_CHROME_TEXT_HTML;
|
| + if (!drop_data.file_contents.empty())
|
| + targets_mask |= GtkDndUtil::X_CHROME_WEBDROP_FILE_CONTENTS;
|
| +
|
| + if (targets_mask == 0) {
|
| + NOTIMPLEMENTED();
|
| DragEnded();
|
| return;
|
| }
|
|
|
| drop_data_.reset(new WebDropData(drop_data));
|
|
|
| - GtkTargetList* list = gtk_target_list_new(NULL, 0);
|
| - gtk_target_list_add_text_targets(list, dnd::X_CHROME_TEXT_PLAIN);
|
| + GtkTargetList* list = GtkDndUtil::GetTargetListFromCodeMask(targets_mask);
|
| + if (targets_mask & GtkDndUtil::X_CHROME_WEBDROP_FILE_CONTENTS) {
|
| + drag_file_mime_type_ = gdk_atom_intern(
|
| + mime_util::GetDataMimeType(drop_data.file_contents).c_str(), FALSE);
|
| + gtk_target_list_add(list, drag_file_mime_type_,
|
| + 0, GtkDndUtil::X_CHROME_WEBDROP_FILE_CONTENTS);
|
| + }
|
| +
|
| gtk_drag_begin(GetContentNativeView(), list, GDK_ACTION_COPY, 1, NULL);
|
| // The drag adds a ref; let it own the list.
|
| gtk_target_list_unref(list);
|
| @@ -384,9 +402,46 @@
|
| GtkWidget* drag_widget,
|
| GdkDragContext* context, GtkSelectionData* selection_data,
|
| guint target_type, guint time, TabContentsViewGtk* view) {
|
| - std::string utf8_text(UTF16ToUTF8(view->drop_data_->plain_text));
|
| - gtk_selection_data_set_text(selection_data, utf8_text.c_str(),
|
| - utf8_text.length());
|
| + const int bits_per_byte = 8;
|
| + // We must make this initialization here or gcc complains about jumping past
|
| + // it in the switch statement.
|
| + std::string utf8_text;
|
| +
|
| + switch (target_type) {
|
| + case GtkDndUtil::X_CHROME_TEXT_PLAIN:
|
| + utf8_text = UTF16ToUTF8(view->drop_data_->plain_text);
|
| + gtk_selection_data_set_text(selection_data, utf8_text.c_str(),
|
| + utf8_text.length());
|
| + break;
|
| + case GtkDndUtil::X_CHROME_TEXT_URI_LIST:
|
| + gchar* uri_array[2];
|
| + uri_array[0] = strdup(view->drop_data_->url.spec().c_str());
|
| + uri_array[1] = NULL;
|
| + gtk_selection_data_set_uris(selection_data, uri_array);
|
| + free(uri_array[0]);
|
| + break;
|
| + case GtkDndUtil::X_CHROME_TEXT_HTML:
|
| + // TODO(estade): change relative links to be absolute using
|
| + // |html_base_url|.
|
| + utf8_text = UTF16ToUTF8(view->drop_data_->text_html);
|
| + gtk_selection_data_set(selection_data,
|
| + GtkDndUtil::GetAtomForTarget(GtkDndUtil::X_CHROME_TEXT_HTML),
|
| + bits_per_byte,
|
| + reinterpret_cast<const guchar*>(utf8_text.c_str()),
|
| + utf8_text.length());
|
| + break;
|
| +
|
| + case GtkDndUtil::X_CHROME_WEBDROP_FILE_CONTENTS:
|
| + gtk_selection_data_set(selection_data,
|
| + view->drag_file_mime_type_, bits_per_byte,
|
| + reinterpret_cast<const guchar*>(
|
| + view->drop_data_->file_contents.data()),
|
| + view->drop_data_->file_contents.length());
|
| + break;
|
| +
|
| + default:
|
| + NOTREACHED();
|
| + }
|
| }
|
|
|
| // static
|
|
|