diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-17 01:13:11 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-17 01:13:11 +0000 |
commit | 8fa18a33d2dee21f748139ef503d08ebb4b706af (patch) | |
tree | eb69b882d33b06f9a82fd0d90ffcc29a8a2884f8 /chrome/browser | |
parent | 7cebf25a2c487e8a2428142b260f443bf6107fcf (diff) | |
download | chromium_src-8fa18a33d2dee21f748139ef503d08ebb4b706af.zip chromium_src-8fa18a33d2dee21f748139ef503d08ebb4b706af.tar.gz chromium_src-8fa18a33d2dee21f748139ef503d08ebb4b706af.tar.bz2 |
Basic DragImage implementation.
Only the chromium part is for review. The webkit part shows how that will look when I create the patch for webkit later. This can be landed without the change to webkit.
TODO later:
- use the image on windows, mac
- implement the other DragImageRef functions
TEST=drag an image from the render view in GTK
BUG=11457
Review URL: http://codereview.chromium.org/668125
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41799 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
19 files changed, 108 insertions, 24 deletions
diff --git a/chrome/browser/cocoa/notifications/balloon_view_host_mac.h b/chrome/browser/cocoa/notifications/balloon_view_host_mac.h index 3568576..aabbba8 100644 --- a/chrome/browser/cocoa/notifications/balloon_view_host_mac.h +++ b/chrome/browser/cocoa/notifications/balloon_view_host_mac.h @@ -15,6 +15,10 @@ class Profile; class RenderViewHost; +class SkBitmap; +namespace gfx { +class Point; +} // BalloonViewHost class is a delegate to the renderer host for the HTML // notification. When initialized it creates a new RenderViewHost and loads @@ -76,7 +80,9 @@ class BalloonViewHost : public RenderViewHostDelegate, const gfx::Rect& initial_pos) {} virtual void ShowContextMenu(const ContextMenuParams& params) {} virtual void StartDragging(const WebDropData& drop_data, - WebKit::WebDragOperationsMask allowed_ops) {} + WebKit::WebDragOperationsMask allowed_ops, + const SkBitmap& image, + const gfx::Point& image_offset) {} virtual void UpdateDragCursor(WebKit::WebDragOperation operation) {} virtual void GotFocus() {} virtual void TakeFocus(bool reverse) {} diff --git a/chrome/browser/extensions/extension_host.cc b/chrome/browser/extensions/extension_host.cc index ef9faae..e2d86da 100644 --- a/chrome/browser/extensions/extension_host.cc +++ b/chrome/browser/extensions/extension_host.cc @@ -557,7 +557,9 @@ void ExtensionHost::ShowContextMenu(const ContextMenuParams& params) { } void ExtensionHost::StartDragging(const WebDropData& drop_data, - WebDragOperationsMask operation_mask) { + WebDragOperationsMask operation_mask, + const SkBitmap& image, + const gfx::Point& image_offset) { // We're not going to do any drag & drop, but we have to tell the renderer the // drag & drop ended, othewise the renderer thinks the drag operation is // underway and mouse events won't work. See bug 34061. diff --git a/chrome/browser/extensions/extension_host.h b/chrome/browser/extensions/extension_host.h index a5a0ae0..4cdc8cf 100644 --- a/chrome/browser/extensions/extension_host.h +++ b/chrome/browser/extensions/extension_host.h @@ -141,7 +141,9 @@ class ExtensionHost : public ExtensionPopupHost::PopupDelegate, const gfx::Rect& initial_pos); virtual void ShowContextMenu(const ContextMenuParams& params); virtual void StartDragging(const WebDropData& drop_data, - WebKit::WebDragOperationsMask allowed_operations); + WebKit::WebDragOperationsMask allowed_operations, + const SkBitmap& image, + const gfx::Point& image_offset); virtual void UpdateDragCursor(WebKit::WebDragOperation operation); virtual void GotFocus(); virtual void TakeFocus(bool reverse); diff --git a/chrome/browser/gtk/notifications/balloon_view_host_gtk.h b/chrome/browser/gtk/notifications/balloon_view_host_gtk.h index 0c40864..4bcd5b4 100644 --- a/chrome/browser/gtk/notifications/balloon_view_host_gtk.h +++ b/chrome/browser/gtk/notifications/balloon_view_host_gtk.h @@ -79,7 +79,9 @@ class BalloonViewHost : public RenderViewHostDelegate, const gfx::Rect& initial_pos) {} virtual void ShowContextMenu(const ContextMenuParams& params) {} virtual void StartDragging(const WebDropData& drop_data, - WebKit::WebDragOperationsMask allowed_ops) {} + WebKit::WebDragOperationsMask allowed_ops, + const SkBitmap& image, + const gfx::Point& image_offset) {} virtual void UpdateDragCursor(WebKit::WebDragOperation operation) {} virtual void GotFocus() {} virtual void TakeFocus(bool reverse) {} diff --git a/chrome/browser/gtk/tab_contents_drag_source.cc b/chrome/browser/gtk/tab_contents_drag_source.cc index 85ebe0c..45f0f1f 100644 --- a/chrome/browser/gtk/tab_contents_drag_source.cc +++ b/chrome/browser/gtk/tab_contents_drag_source.cc @@ -6,6 +6,7 @@ #include <string> +#include "app/gfx/gtk_util.h" #include "app/gtk_dnd_util.h" #include "base/file_util.h" #include "base/mime_util.h" @@ -69,7 +70,9 @@ TabContents* TabContentsDragSource::tab_contents() const { } void TabContentsDragSource::StartDragging(const WebDropData& drop_data, - GdkEventButton* last_mouse_down) { + GdkEventButton* last_mouse_down, + const SkBitmap& image, + const gfx::Point& image_offset) { int targets_mask = 0; if (!drop_data.plain_text.empty()) @@ -98,6 +101,8 @@ void TabContentsDragSource::StartDragging(const WebDropData& drop_data, } drop_data_.reset(new WebDropData(drop_data)); + drag_image_ = image; + image_offset_ = image_offset; GtkTargetList* list = gtk_dnd_util::GetTargetListFromCodeMask(targets_mask); if (targets_mask & gtk_dnd_util::CHROME_WEBDROP_FILE_CONTENTS) { @@ -303,6 +308,14 @@ void TabContentsDragSource::OnDragBegin(GdkDragContext* drag_context) { generated_download_file_name.value().c_str()), generated_download_file_name.value().length()); } + + if (!drag_image_.isNull()) { + GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(&drag_image_); + gtk_drag_set_icon_pixbuf(drag_context, pixbuf, + image_offset_.x(), image_offset_.y()); + // Let the drag take ownership. + g_object_unref(pixbuf); + } } void TabContentsDragSource::OnDragEnd(GdkDragContext* drag_context, diff --git a/chrome/browser/gtk/tab_contents_drag_source.h b/chrome/browser/gtk/tab_contents_drag_source.h index edef7ad..35693e9 100644 --- a/chrome/browser/gtk/tab_contents_drag_source.h +++ b/chrome/browser/gtk/tab_contents_drag_source.h @@ -10,9 +10,11 @@ #include "app/gfx/native_widget_types.h" #include "base/basictypes.h" #include "base/file_path.h" +#include "base/gfx/point.h" #include "base/message_loop.h" #include "base/string16.h" #include "googleurl/src/gurl.h" +#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/WebKit/WebKit/chromium/public/WebDragOperation.h" class TabContents; @@ -31,7 +33,9 @@ class TabContentsDragSource : public MessageLoopForUI::Observer { // Starts a drag for the tab contents this TabContentsDragSource was // created for. void StartDragging(const WebDropData& drop_data, - GdkEventButton* last_mouse_down); + GdkEventButton* last_mouse_down, + const SkBitmap& image, + const gfx::Point& image_offset); // MessageLoop::Observer implementation: virtual void WillProcessEvent(GdkEvent* event); @@ -79,6 +83,11 @@ class TabContentsDragSource : public MessageLoopForUI::Observer { // view). Non-NULL iff there is a current drag. scoped_ptr<WebDropData> drop_data_; + // The image used for depicting the drag, and the offset between the cursor + // and the top left pixel. + SkBitmap drag_image_; + gfx::Point image_offset_; + // The mime type for the file contents of the current drag (if any). GdkAtom drag_file_mime_type_; diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc index 354acaf..7307a82 100644 --- a/chrome/browser/renderer_host/render_view_host.cc +++ b/chrome/browser/renderer_host/render_view_host.cc @@ -1389,10 +1389,12 @@ void RenderViewHost::OnMsgFormFieldValuesSubmitted( void RenderViewHost::OnMsgStartDragging( const WebDropData& drop_data, - WebDragOperationsMask drag_operations_mask) { + WebDragOperationsMask drag_operations_mask, + const SkBitmap& image, + const gfx::Point& image_offset) { RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); if (view) - view->StartDragging(drop_data, drag_operations_mask); + view->StartDragging(drop_data, drag_operations_mask, image, image_offset); } void RenderViewHost::OnUpdateDragCursor(WebDragOperation current_op) { diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h index 27fb3ff..cc52d47 100644 --- a/chrome/browser/renderer_host/render_view_host.h +++ b/chrome/browser/renderer_host/render_view_host.h @@ -549,7 +549,9 @@ class RenderViewHost : public RenderWidgetHost { const std::vector<webkit_glue::PasswordForm>& forms); void OnMsgFormFieldValuesSubmitted(const webkit_glue::FormFieldValues& forms); void OnMsgStartDragging(const WebDropData& drop_data, - WebKit::WebDragOperationsMask operations_allowed); + WebKit::WebDragOperationsMask operations_allowed, + const SkBitmap& image, + const gfx::Point& image_offset); void OnUpdateDragCursor(WebKit::WebDragOperation drag_operation); void OnTakeFocus(bool reverse); void OnMsgPageHasOSDD(int32 page_id, const GURL& doc_url, bool autodetected); diff --git a/chrome/browser/renderer_host/render_view_host_delegate.h b/chrome/browser/renderer_host/render_view_host_delegate.h index 535bb1f..ff10230 100644 --- a/chrome/browser/renderer_host/render_view_host_delegate.h +++ b/chrome/browser/renderer_host/render_view_host_delegate.h @@ -44,6 +44,7 @@ class WaitableEvent; } namespace gfx { +class Point; class Rect; class Size; } @@ -118,7 +119,9 @@ class RenderViewHostDelegate { // RenderView. Contextual information about the dragged content is supplied // by WebDropData. virtual void StartDragging(const WebDropData& drop_data, - WebKit::WebDragOperationsMask allowed_ops) = 0; + WebKit::WebDragOperationsMask allowed_ops, + const SkBitmap& image, + const gfx::Point& image_offset) = 0; // The page wants to update the mouse cursor during a drag & drop operation. // |operation| describes the current operation (none, move, copy, link.) diff --git a/chrome/browser/tab_contents/interstitial_page.cc b/chrome/browser/tab_contents/interstitial_page.cc index 555e655..2be9448 100644 --- a/chrome/browser/tab_contents/interstitial_page.cc +++ b/chrome/browser/tab_contents/interstitial_page.cc @@ -96,7 +96,9 @@ class InterstitialPage::InterstitialPageRVHViewDelegate const gfx::Rect& initial_pos); virtual void ShowContextMenu(const ContextMenuParams& params); virtual void StartDragging(const WebDropData& drop_data, - WebDragOperationsMask operations_allowed); + WebDragOperationsMask operations_allowed, + const SkBitmap& image, + const gfx::Point& image_offset); virtual void UpdateDragCursor(WebDragOperation operation); virtual void GotFocus(); virtual void TakeFocus(bool reverse); @@ -578,7 +580,9 @@ void InterstitialPage::InterstitialPageRVHViewDelegate::ShowContextMenu( void InterstitialPage::InterstitialPageRVHViewDelegate::StartDragging( const WebDropData& drop_data, - WebDragOperationsMask allowed_operations) { + WebDragOperationsMask allowed_operations, + const SkBitmap& image, + const gfx::Point& image_offset) { NOTREACHED() << "InterstitialPage does not support dragging yet."; } diff --git a/chrome/browser/tab_contents/tab_contents_view_gtk.cc b/chrome/browser/tab_contents/tab_contents_view_gtk.cc index f7286de..b636757 100644 --- a/chrome/browser/tab_contents/tab_contents_view_gtk.cc +++ b/chrome/browser/tab_contents/tab_contents_view_gtk.cc @@ -323,10 +323,13 @@ void TabContentsViewGtk::ShowContextMenu(const ContextMenuParams& params) { // Render view DnD ------------------------------------------------------------- void TabContentsViewGtk::StartDragging(const WebDropData& drop_data, - WebDragOperationsMask ops) { + WebDragOperationsMask ops, + const SkBitmap& image, + const gfx::Point& image_offset) { DCHECK(GetContentNativeView()); - drag_source_->StartDragging(drop_data, &last_mouse_down_); + drag_source_->StartDragging(drop_data, &last_mouse_down_, image, + image_offset); // TODO(snej): Make use of the WebDragOperationsMask somehow } diff --git a/chrome/browser/tab_contents/tab_contents_view_gtk.h b/chrome/browser/tab_contents/tab_contents_view_gtk.h index 954e560..1bded49b 100644 --- a/chrome/browser/tab_contents/tab_contents_view_gtk.h +++ b/chrome/browser/tab_contents/tab_contents_view_gtk.h @@ -57,7 +57,9 @@ class TabContentsViewGtk : public TabContentsView, // Backend implementation of RenderViewHostDelegate::View. virtual void ShowContextMenu(const ContextMenuParams& params); virtual void StartDragging(const WebDropData& drop_data, - WebKit::WebDragOperationsMask allowed_ops); + WebKit::WebDragOperationsMask allowed_ops, + const SkBitmap& image, + const gfx::Point& image_offset); virtual void UpdateDragCursor(WebKit::WebDragOperation operation); virtual void GotFocus(); virtual void TakeFocus(bool reverse); diff --git a/chrome/browser/tab_contents/tab_contents_view_mac.h b/chrome/browser/tab_contents/tab_contents_view_mac.h index 3a3d4c8..e195cbc 100644 --- a/chrome/browser/tab_contents/tab_contents_view_mac.h +++ b/chrome/browser/tab_contents/tab_contents_view_mac.h @@ -20,9 +20,13 @@ class FilePath; class FindBarMac; @class FocusTracker; @class SadTabController; +class SkBitmap; class TabContentsViewMac; @class WebDragSource; @class WebDropTarget; +namespace gfx { +class Point; +} @interface TabContentsViewCocoa : BaseView { @private @@ -73,7 +77,9 @@ class TabContentsViewMac : public TabContentsView, // Backend implementation of RenderViewHostDelegate::View. virtual void ShowContextMenu(const ContextMenuParams& params); virtual void StartDragging(const WebDropData& drop_data, - WebKit::WebDragOperationsMask allowed_operations); + WebKit::WebDragOperationsMask allowed_operations, + const SkBitmap& image, + const gfx::Point& image_offset); virtual void UpdateDragCursor(WebKit::WebDragOperation operation); virtual void GotFocus(); virtual void TakeFocus(bool reverse); diff --git a/chrome/browser/tab_contents/tab_contents_view_mac.mm b/chrome/browser/tab_contents/tab_contents_view_mac.mm index 6949621..a2b622e 100644 --- a/chrome/browser/tab_contents/tab_contents_view_mac.mm +++ b/chrome/browser/tab_contents/tab_contents_view_mac.mm @@ -126,8 +126,11 @@ void TabContentsViewMac::GetContainerBounds(gfx::Rect* out) const { *out = [cocoa_view_.get() NSRectToRect:[cocoa_view_.get() bounds]]; } -void TabContentsViewMac::StartDragging(const WebDropData& drop_data, - WebDragOperationsMask allowed_operations) { +void TabContentsViewMac::StartDragging( + const WebDropData& drop_data, + WebDragOperationsMask allowed_operations, + const SkBitmap& image, + const gfx::Point& image_offset) { // By allowing nested tasks, the code below also allows Close(), // which would deallocate |this|. The same problem can occur while // processing -sendEvent:, so Close() is deferred in that case. @@ -138,6 +141,7 @@ void TabContentsViewMac::StartDragging(const WebDropData& drop_data, // The drag invokes a nested event loop, arrange to continue // processing events. MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); + // TODO(estade): make use of |image| and |image_offset|. NSDragOperation mask = static_cast<NSDragOperation>(allowed_operations); [cocoa_view_ startDragWithDropData:drop_data dragOperationMask:mask]; diff --git a/chrome/browser/views/notifications/balloon_view_host.h b/chrome/browser/views/notifications/balloon_view_host.h index 8b16586..75f3ef7 100644 --- a/chrome/browser/views/notifications/balloon_view_host.h +++ b/chrome/browser/views/notifications/balloon_view_host.h @@ -15,6 +15,10 @@ class Profile; class RenderViewHost; +class SkBitmap; +namespace gfx { +class Point; +} // BalloonViewHost class is a delegate to the renderer host for the HTML // notification. When initialized it creates a new RenderViewHost and loads @@ -70,7 +74,9 @@ class BalloonViewHost : public views::NativeViewHost, const gfx::Rect& initial_pos) {} virtual void ShowContextMenu(const ContextMenuParams& params) {} virtual void StartDragging(const WebDropData& drop_data, - WebKit::WebDragOperationsMask allowed_ops) {} + WebKit::WebDragOperationsMask allowed_ops, + const SkBitmap& image, + const gfx::Point& image_offset) {} virtual void UpdateDragCursor(WebKit::WebDragOperation operation) {} virtual void GotFocus() {} virtual void TakeFocus(bool reverse) {} diff --git a/chrome/browser/views/tab_contents/tab_contents_view_gtk.cc b/chrome/browser/views/tab_contents/tab_contents_view_gtk.cc index 91b25ce..4a9870e 100644 --- a/chrome/browser/views/tab_contents/tab_contents_view_gtk.cc +++ b/chrome/browser/views/tab_contents/tab_contents_view_gtk.cc @@ -219,8 +219,11 @@ void TabContentsViewGtk::GetContainerBounds(gfx::Rect* out) const { } void TabContentsViewGtk::StartDragging(const WebDropData& drop_data, - WebDragOperationsMask ops) { - drag_source_->StartDragging(drop_data, &last_mouse_down_); + WebDragOperationsMask ops, + const SkBitmap& image, + const gfx::Point& image_offset) { + drag_source_->StartDragging(drop_data, &last_mouse_down_, + image, image_offset); // TODO(snej): Make use of WebDragOperationsMask } diff --git a/chrome/browser/views/tab_contents/tab_contents_view_gtk.h b/chrome/browser/views/tab_contents/tab_contents_view_gtk.h index 3439ec5..e88c3f9 100644 --- a/chrome/browser/views/tab_contents/tab_contents_view_gtk.h +++ b/chrome/browser/views/tab_contents/tab_contents_view_gtk.h @@ -16,8 +16,12 @@ class ConstrainedWindowGtk; typedef struct _GtkFloatingContainer GtkFloatingContainer; class RenderViewContextMenuGtk; class SadTabView; +class SkBitmap; class TabContentsDragSource; class WebDragDestGtk; +namespace gfx { +class Point; +} namespace views { class NativeViewHost; } @@ -61,7 +65,9 @@ class TabContentsViewGtk : public TabContentsView, // Backend implementation of RenderViewHostDelegate::View. virtual void ShowContextMenu(const ContextMenuParams& params); virtual void StartDragging(const WebDropData& drop_data, - WebKit::WebDragOperationsMask ops_allowed); + WebKit::WebDragOperationsMask ops_allowed, + const SkBitmap& image, + const gfx::Point& image_offset); virtual void UpdateDragCursor(WebKit::WebDragOperation operation); virtual void GotFocus(); virtual void TakeFocus(bool reverse); diff --git a/chrome/browser/views/tab_contents/tab_contents_view_win.cc b/chrome/browser/views/tab_contents/tab_contents_view_win.cc index 5af44c6..243017e 100644 --- a/chrome/browser/views/tab_contents/tab_contents_view_win.cc +++ b/chrome/browser/views/tab_contents/tab_contents_view_win.cc @@ -125,8 +125,11 @@ void TabContentsViewWin::GetContainerBounds(gfx::Rect* out) const { } void TabContentsViewWin::StartDragging(const WebDropData& drop_data, - WebDragOperationsMask ops) { + WebDragOperationsMask ops, + const SkBitmap& image, + const gfx::Point& image_offset) { drag_handler_ = new TabContentsDragWin(this); + // TODO(estade): make use of |image| and |image_offset|. drag_handler_->StartDragging(drop_data, ops); } diff --git a/chrome/browser/views/tab_contents/tab_contents_view_win.h b/chrome/browser/views/tab_contents/tab_contents_view_win.h index 61177bc..27f50fe 100644 --- a/chrome/browser/views/tab_contents/tab_contents_view_win.h +++ b/chrome/browser/views/tab_contents/tab_contents_view_win.h @@ -13,10 +13,14 @@ class RenderViewContextMenuWin; class SadTabView; +class SkBitmap; class TabContentsDragWin; struct WebDropData; class WebDragSource; class WebDropTarget; +namespace gfx { +class Point; +} // Windows-specific implementation of the TabContentsView. It is a HWND that // contains all of the contents of the tab and associated child views. @@ -55,7 +59,9 @@ class TabContentsViewWin : public TabContentsView, // Backend implementation of RenderViewHostDelegate::View. virtual void ShowContextMenu(const ContextMenuParams& params); virtual void StartDragging(const WebDropData& drop_data, - WebKit::WebDragOperationsMask operations); + WebKit::WebDragOperationsMask operations, + const SkBitmap& image, + const gfx::Point& image_offset); virtual void UpdateDragCursor(WebKit::WebDragOperation operation); virtual void GotFocus(); virtual void TakeFocus(bool reverse); |