diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-18 17:10:18 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-18 17:10:18 +0000 |
commit | 2ca8a064a206fba910dc0f50f8a2f2509828d8f1 (patch) | |
tree | 9e128f90d2392b901aca101baabe12dd36621943 /chrome/browser/tab_contents | |
parent | 911f815112d8d11778c771467fbef2c2b1f8e160 (diff) | |
download | chromium_src-2ca8a064a206fba910dc0f50f8a2f2509828d8f1.zip chromium_src-2ca8a064a206fba910dc0f50f8a2f2509828d8f1.tar.gz chromium_src-2ca8a064a206fba910dc0f50f8a2f2509828d8f1.tar.bz2 |
GTK: implement extension bookmark manager drag api.
Also, cross-platform: eschew RenderViewHostDelegate:BookmarkDrag::DragData type in favor of BookmarkDragData.
BUG=37702
TEST=manual
Review URL: http://codereview.chromium.org/1029004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41959 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents')
-rw-r--r-- | chrome/browser/tab_contents/web_drag_dest_gtk.cc | 34 | ||||
-rw-r--r-- | chrome/browser/tab_contents/web_drag_dest_gtk.h | 7 | ||||
-rw-r--r-- | chrome/browser/tab_contents/web_drop_target_win.cc | 17 |
3 files changed, 52 insertions, 6 deletions
diff --git a/chrome/browser/tab_contents/web_drag_dest_gtk.cc b/chrome/browser/tab_contents/web_drag_dest_gtk.cc index 2bb5fa3..d96f6cf 100644 --- a/chrome/browser/tab_contents/web_drag_dest_gtk.cc +++ b/chrome/browser/tab_contents/web_drag_dest_gtk.cc @@ -9,6 +9,7 @@ #include "app/gtk_dnd_util.h" #include "base/file_path.h" #include "base/utf_string_conversions.h" +#include "chrome/browser/gtk/bookmark_utils_gtk.h" #include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/tab_contents/tab_contents.h" @@ -60,6 +61,10 @@ void WebDragDestGtk::UpdateDragStatus(WebDragOperation operation) { void WebDragDestGtk::DragLeave() { tab_contents_->render_view_host()->DragTargetDragLeave(); + + if (tab_contents_->GetBookmarkDragDelegate()) { + tab_contents_->GetBookmarkDragDelegate()->OnDragLeave(bookmark_drag_data_); + } } gboolean WebDragDestGtk::OnDragMotion(GtkWidget* sender, @@ -77,6 +82,7 @@ gboolean WebDragDestGtk::OnDragMotion(GtkWidget* sender, gtk_dnd_util::TEXT_HTML, gtk_dnd_util::NETSCAPE_URL, gtk_dnd_util::CHROME_NAMED_URL, + gtk_dnd_util::CHROME_BOOKMARK_ITEM, // TODO(estade): support image drags? }; @@ -87,12 +93,14 @@ gboolean WebDragDestGtk::OnDragMotion(GtkWidget* sender, time); } } else if (data_requests_ == 0) { + // TODO(snej): Pass appropriate DragOperation instead of hardcoding tab_contents_->render_view_host()-> DragTargetDragOver(gtk_util::ClientPoint(widget_), gtk_util::ScreenPoint(widget_), static_cast<WebDragOperation>( WebDragOperationCopy | WebDragOperationMove)); - // TODO(snej): Pass appropriate DragOperation instead of hardcoding + if (tab_contents_->GetBookmarkDragDelegate()) + tab_contents_->GetBookmarkDragDelegate()->OnDragOver(bookmark_drag_data_); drag_over_time_ = time; } @@ -160,19 +168,36 @@ void WebDragDestGtk::OnDragDataReceived( gtk_dnd_util::GetAtomForTarget(gtk_dnd_util::CHROME_NAMED_URL)) { gtk_dnd_util::ExtractNamedURL(data, &drop_data_->url, &drop_data_->url_title); + } else if (data->target == + gtk_dnd_util::GetAtomForTarget( + gtk_dnd_util::CHROME_BOOKMARK_ITEM)) { + bookmark_drag_data_.ReadFromVector( + bookmark_utils::GetNodesFromSelection( + NULL, data, + gtk_dnd_util::CHROME_BOOKMARK_ITEM, + tab_contents_->profile(), NULL, NULL)); + bookmark_drag_data_.SetOriginatingProfile(tab_contents_->profile()); } } if (data_requests_ == 0) { // Tell the renderer about the drag. // |x| and |y| are seemingly arbitrary at this point. + // TODO(snej): Pass appropriate DragOperation instead of hardcoding. tab_contents_->render_view_host()-> DragTargetDragEnter(*drop_data_.get(), gtk_util::ClientPoint(widget_), gtk_util::ScreenPoint(widget_), static_cast<WebDragOperation>( WebDragOperationCopy | WebDragOperationMove)); - // TODO(snej): Pass appropriate DragOperation instead of hardcoding + + // This is non-null if tab_contents_ is showing an ExtensionDOMUI with + // support for (at the moment experimental) drag and drop extensions. + if (tab_contents_->GetBookmarkDragDelegate()) { + tab_contents_->GetBookmarkDragDelegate()->OnDragEnter( + bookmark_drag_data_); + } + drag_over_time_ = time; } } @@ -202,6 +227,11 @@ gboolean WebDragDestGtk::OnDragDrop(GtkWidget* sender, GdkDragContext* context, DragTargetDrop(gtk_util::ClientPoint(widget_), gtk_util::ScreenPoint(widget_)); + // This is non-null if tab_contents_ is showing an ExtensionDOMUI with + // support for (at the moment experimental) drag and drop extensions. + if (tab_contents_->GetBookmarkDragDelegate()) + tab_contents_->GetBookmarkDragDelegate()->OnDrop(bookmark_drag_data_); + // The second parameter is just an educated guess, but at least we will // get the drag-end animation right sometimes. gtk_drag_finish(context, is_drop_target_, FALSE, time); diff --git a/chrome/browser/tab_contents/web_drag_dest_gtk.h b/chrome/browser/tab_contents/web_drag_dest_gtk.h index e8b0c3a..49607b2 100644 --- a/chrome/browser/tab_contents/web_drag_dest_gtk.h +++ b/chrome/browser/tab_contents/web_drag_dest_gtk.h @@ -6,13 +6,16 @@ #define CHROME_BROWSER_TAB_CONTENTS_WEB_DRAG_DEST_GTK_H_ #include <gtk/gtk.h> +#include <vector> #include "app/gtk_signal.h" #include "base/scoped_ptr.h" #include "base/task.h" +#include "chrome/browser/bookmarks/bookmark_drag_data.h" #include "third_party/WebKit/WebKit/chromium/public/WebDragOperation.h" #include "webkit/glue/webdropdata.h" +class BookmarkNode; class TabContents; // A helper class that handles DnD for drops in the renderer. In GTK parlance, @@ -80,6 +83,10 @@ class WebDragDestGtk { // |widget_| is. int destroy_handler_; + // The bookmark data for the current tab. This will be empty if there is not + // a native bookmark drag (or we haven't gotten the data from the source yet). + BookmarkDragData bookmark_drag_data_; + ScopedRunnableMethodFactory<WebDragDestGtk> method_factory_; DISALLOW_COPY_AND_ASSIGN(WebDragDestGtk); diff --git a/chrome/browser/tab_contents/web_drop_target_win.cc b/chrome/browser/tab_contents/web_drop_target_win.cc index f84a4b0..72d4e23 100644 --- a/chrome/browser/tab_contents/web_drop_target_win.cc +++ b/chrome/browser/tab_contents/web_drop_target_win.cc @@ -10,6 +10,7 @@ #include "app/clipboard/clipboard_util_win.h" #include "app/os_exchange_data.h" #include "app/os_exchange_data_provider_win.h" +#include "chrome/browser/bookmarks/bookmark_drag_data.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "gfx/point.h" @@ -122,7 +123,9 @@ DWORD WebDropTarget::OnDragEnter(IDataObject* data_object, // support for (at the moment experimental) drag and drop extensions. if (tab_contents_->GetBookmarkDragDelegate()) { OSExchangeData os_exchange_data(new OSExchangeDataProviderWin(data_object)); - tab_contents_->GetBookmarkDragDelegate()->OnDragEnter(&os_exchange_data); + BookmarkDragData bookmark_drag_data; + if (bookmark_drag_data.Read(os_exchange_data)) + tab_contents_->GetBookmarkDragDelegate()->OnDragEnter(bookmark_drag_data); } // We lie here and always return a DROPEFFECT because we don't want to @@ -150,7 +153,9 @@ DWORD WebDropTarget::OnDragOver(IDataObject* data_object, if (tab_contents_->GetBookmarkDragDelegate()) { OSExchangeData os_exchange_data(new OSExchangeDataProviderWin(data_object)); - tab_contents_->GetBookmarkDragDelegate()->OnDragOver(&os_exchange_data); + BookmarkDragData bookmark_drag_data; + if (bookmark_drag_data.Read(os_exchange_data)) + tab_contents_->GetBookmarkDragDelegate()->OnDragOver(bookmark_drag_data); } if (!is_drop_target_) @@ -172,7 +177,9 @@ void WebDropTarget::OnDragLeave(IDataObject* data_object) { if (tab_contents_->GetBookmarkDragDelegate()) { OSExchangeData os_exchange_data(new OSExchangeDataProviderWin(data_object)); - tab_contents_->GetBookmarkDragDelegate()->OnDragLeave(&os_exchange_data); + BookmarkDragData bookmark_drag_data; + if (bookmark_drag_data.Read(os_exchange_data)) + tab_contents_->GetBookmarkDragDelegate()->OnDragLeave(bookmark_drag_data); } } @@ -198,7 +205,9 @@ DWORD WebDropTarget::OnDrop(IDataObject* data_object, if (tab_contents_->GetBookmarkDragDelegate()) { OSExchangeData os_exchange_data(new OSExchangeDataProviderWin(data_object)); - tab_contents_->GetBookmarkDragDelegate()->OnDrop(&os_exchange_data); + BookmarkDragData bookmark_drag_data; + if (bookmark_drag_data.Read(os_exchange_data)) + tab_contents_->GetBookmarkDragDelegate()->OnDrop(bookmark_drag_data); } current_rvh_ = NULL; |