diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-27 01:41:07 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-27 01:41:07 +0000 |
commit | bb78a4d0473136199ff1c7eaf14140d61644bd41 (patch) | |
tree | b0a1223612052b9769974b0574b7e54d605bc858 /chrome | |
parent | ed95ffbea8f0558c75b99b312b917a71b088a4be (diff) | |
download | chromium_src-bb78a4d0473136199ff1c7eaf14140d61644bd41.zip chromium_src-bb78a4d0473136199ff1c7eaf14140d61644bd41.tar.gz chromium_src-bb78a4d0473136199ff1c7eaf14140d61644bd41.tar.bz2 |
Linux web drag first cut.
You can only drag out of the web contents, and can only drag text.
http://crbug.com/15429
TEST=try dragging some text into gedit
Review URL: http://codereview.chromium.org/147245
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19445 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/tab_contents/tab_contents_view_gtk.cc | 54 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents_view_gtk.h | 14 |
2 files changed, 61 insertions, 7 deletions
diff --git a/chrome/browser/tab_contents/tab_contents_view_gtk.cc b/chrome/browser/tab_contents/tab_contents_view_gtk.cc index 0ad9d9a..1c853bd 100644 --- a/chrome/browser/tab_contents/tab_contents_view_gtk.cc +++ b/chrome/browser/tab_contents/tab_contents_view_gtk.cc @@ -7,15 +7,16 @@ #include <gdk/gdk.h> #include <gtk/gtk.h> -#include "base/string_util.h" #include "base/gfx/point.h" #include "base/gfx/rect.h" #include "base/gfx/size.h" +#include "base/string_util.h" #include "build/build_config.h" #include "chrome/browser/download/download_shelf.h" #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_floating_container.h" #include "chrome/browser/gtk/sad_tab_gtk.h" #include "chrome/browser/renderer_host/render_view_host.h" @@ -28,6 +29,7 @@ #include "chrome/common/gtk_util.h" #include "chrome/common/notification_source.h" #include "chrome/common/notification_type.h" +#include "webkit/glue/webdropdata.h" namespace { @@ -196,6 +198,11 @@ RenderWidgetHostView* TabContentsViewGtk::CreateViewForWidget( g_signal_connect(content_view, "button-press-event", G_CALLBACK(OnMouseDown), this); + // DnD signals. + g_signal_connect(content_view, "drag-end", G_CALLBACK(OnDragEnd), this); + g_signal_connect(content_view, "drag-data-get", G_CALLBACK(OnDragDataGet), + this); + InsertIntoContentArea(content_view); return view; } @@ -347,17 +354,50 @@ void TabContentsViewGtk::ShowContextMenu(const ContextMenuParams& params) { context_menu_->Popup(); } -void TabContentsViewGtk::StartDragging(const WebDropData& drop_data) { - NOTIMPLEMENTED(); +// Render view DnD ------------------------------------------------------------- - // Until we have d'n'd implemented, just immediately pretend we're - // already done with the drag and drop so we don't get stuck - // thinking we're in mid-drag. - // TODO(port): remove me when the above NOTIMPLEMENTED is fixed. +void TabContentsViewGtk::DragEnded() { if (tab_contents()->render_view_host()) tab_contents()->render_view_host()->DragSourceSystemDragEnded(); } +void TabContentsViewGtk::StartDragging(const WebDropData& drop_data) { + DCHECK(GetContentNativeView()); + + if (drop_data.plain_text.empty()) { + NOTIMPLEMENTED() << "Only plain text drags supported, sorry!"; + 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); + 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); +} + +// static +void TabContentsViewGtk::OnDragDataGet( + 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()); +} + +// static +void TabContentsViewGtk::OnDragEnd(GtkWidget* widget, + GdkDragContext* drag_context, TabContentsViewGtk* view) { + view->DragEnded(); + view->drop_data_.reset(); +} + +// ----------------------------------------------------------------------------- + void TabContentsViewGtk::InsertIntoContentArea(GtkWidget* widget) { gtk_fixed_put(GTK_FIXED(fixed_), widget, 0, 0); } diff --git a/chrome/browser/tab_contents/tab_contents_view_gtk.h b/chrome/browser/tab_contents/tab_contents_view_gtk.h index 74de6dd..46cfc50 100644 --- a/chrome/browser/tab_contents/tab_contents_view_gtk.h +++ b/chrome/browser/tab_contents/tab_contents_view_gtk.h @@ -81,6 +81,9 @@ class TabContentsViewGtk : public TabContentsView, // should be taken that the correct one is hidden/shown. void InsertIntoContentArea(GtkWidget* widget); + // Tell webkit the drag is over. + void DragEnded(); + // We keep track of the timestamp of the latest mousedown event. static gboolean OnMouseDown(GtkWidget* widget, GdkEventButton* event, TabContentsViewGtk* view); @@ -94,6 +97,13 @@ class TabContentsViewGtk : public TabContentsView, GtkFloatingContainer* floating_container, GtkAllocation* allocation, TabContentsViewGtk* tab_contents_view); + // Webkit DnD. + static void OnDragEnd(GtkWidget* widget, GdkDragContext* drag_context, + TabContentsViewGtk* tab_contents_view); + static void OnDragDataGet(GtkWidget* drag_widget, + GdkDragContext* context, GtkSelectionData* selection_data, + guint target_type, guint time, TabContentsViewGtk* view); + // Contains |fixed_| as its GtkBin member and a possible floating widget from // |popup_view_|. OwnedWidgetGtk floating_; @@ -125,6 +135,10 @@ class TabContentsViewGtk : public TabContentsView, // objects in this vector are owned by the TabContents, not the view. std::vector<ConstrainedWindowGtk*> constrained_windows_; + // The drop data for the current drag (for drags that originate in the render + // view). + scoped_ptr<WebDropData> drop_data_; + DISALLOW_COPY_AND_ASSIGN(TabContentsViewGtk); }; |