summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/views/tab_contents/tab_contents_drag_win.cc27
-rw-r--r--chrome/browser/views/tab_contents/tab_contents_drag_win.h14
-rw-r--r--chrome/browser/views/tab_contents/tab_contents_view_win.cc3
-rw-r--r--views/drag_utils.cc8
-rw-r--r--views/drag_utils.h8
-rw-r--r--views/drag_utils_gtk.cc6
-rw-r--r--views/drag_utils_win.cc11
7 files changed, 58 insertions, 19 deletions
diff --git a/chrome/browser/views/tab_contents/tab_contents_drag_win.cc b/chrome/browser/views/tab_contents/tab_contents_drag_win.cc
index 37bebf5..f1e22da 100644
--- a/chrome/browser/views/tab_contents/tab_contents_drag_win.cc
+++ b/chrome/browser/views/tab_contents/tab_contents_drag_win.cc
@@ -24,6 +24,7 @@
#include "chrome/browser/views/tab_contents/tab_contents_view_win.h"
#include "chrome/common/url_constants.h"
#include "net/base/net_util.h"
+#include "views/drag_utils.h"
#include "webkit/glue/webdropdata.h"
using WebKit::WebDragOperationsMask;
@@ -108,7 +109,9 @@ TabContentsDragWin::~TabContentsDragWin() {
}
void TabContentsDragWin::StartDragging(const WebDropData& drop_data,
- WebDragOperationsMask ops) {
+ WebDragOperationsMask ops,
+ const SkBitmap& image,
+ const gfx::Point& image_offset) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
drag_source_ = new WebDragSource(view_->GetNativeView(),
@@ -119,7 +122,7 @@ void TabContentsDragWin::StartDragging(const WebDropData& drop_data,
// If it is not drag-out, do the drag-and-drop in the current UI thread.
if (drop_data.download_metadata.empty()) {
- DoDragging(drop_data, ops, page_url, page_encoding);
+ DoDragging(drop_data, ops, page_url, page_encoding, image, image_offset);
EndDragging(false);
return;
}
@@ -141,7 +144,9 @@ void TabContentsDragWin::StartDragging(const WebDropData& drop_data,
drop_data,
ops,
page_url,
- page_encoding));
+ page_encoding,
+ image,
+ image_offset));
}
// Install a hook procedure to monitor the messages so that we can forward
@@ -163,10 +168,12 @@ void TabContentsDragWin::StartBackgroundDragging(
const WebDropData& drop_data,
WebDragOperationsMask ops,
const GURL& page_url,
- const std::string& page_encoding) {
+ const std::string& page_encoding,
+ const SkBitmap& image,
+ const gfx::Point& image_offset) {
drag_drop_thread_id_ = PlatformThread::CurrentId();
- DoDragging(drop_data, ops, page_url, page_encoding);
+ DoDragging(drop_data, ops, page_url, page_encoding, image, image_offset);
ChromeThread::PostTask(
ChromeThread::UI, FROM_HERE,
NewRunnableMethod(this, &TabContentsDragWin::EndDragging, true));
@@ -260,11 +267,11 @@ void TabContentsDragWin::PrepareDragForUrl(const WebDropData& drop_data,
void TabContentsDragWin::DoDragging(const WebDropData& drop_data,
WebDragOperationsMask ops,
const GURL& page_url,
- const std::string& page_encoding) {
+ const std::string& page_encoding,
+ const SkBitmap& image,
+ const gfx::Point& image_offset) {
OSExchangeData data;
- // TODO(tc): Generate an appropriate drag image.
-
if (!drop_data.download_metadata.empty()) {
PrepareDragForDownload(drop_data, &data, page_url, page_encoding);
@@ -284,6 +291,10 @@ void TabContentsDragWin::DoDragging(const WebDropData& drop_data,
data.SetString(drop_data.plain_text);
}
+ // Set drag image.
+ drag_utils::SetDragImageOnDataObject(
+ image, gfx::Size(image.width(), image.height()), image_offset, &data);
+
// Keep a local reference to drag_source_ in case that EndDragging is called
// before DoDragDrop returns.
scoped_refptr<WebDragSource> drag_source(drag_source_);
diff --git a/chrome/browser/views/tab_contents/tab_contents_drag_win.h b/chrome/browser/views/tab_contents/tab_contents_drag_win.h
index 36f7068..bfa2b12 100644
--- a/chrome/browser/views/tab_contents/tab_contents_drag_win.h
+++ b/chrome/browser/views/tab_contents/tab_contents_drag_win.h
@@ -9,6 +9,8 @@
#include "base/platform_thread.h"
#include "base/ref_counted.h"
#include "base/scoped_ptr.h"
+#include "gfx/point.h"
+#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/WebKit/WebKit/chromium/public/WebDragOperation.h"
class DragDropThread;
@@ -30,7 +32,9 @@ class TabContentsDragWin
// Called on UI thread.
void StartDragging(const WebDropData& drop_data,
- WebKit::WebDragOperationsMask ops);
+ WebKit::WebDragOperationsMask ops,
+ const SkBitmap& image,
+ const gfx::Point& image_offset);
void CancelDrag();
// DataObjectImpl::Observer implementation.
@@ -50,13 +54,17 @@ class TabContentsDragWin
void DoDragging(const WebDropData& drop_data,
WebKit::WebDragOperationsMask ops,
const GURL& page_url,
- const std::string& page_encoding);
+ const std::string& page_encoding,
+ const SkBitmap& image,
+ const gfx::Point& image_offset);
// Called on drag-and-drop thread.
void StartBackgroundDragging(const WebDropData& drop_data,
WebKit::WebDragOperationsMask ops,
const GURL& page_url,
- const std::string& page_encoding);
+ const std::string& page_encoding,
+ const SkBitmap& image,
+ const gfx::Point& image_offset);
// Called on UI thread.
void EndDragging(bool restore_suspended_state);
void CloseThread();
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 0774fea..6c70040 100644
--- a/chrome/browser/views/tab_contents/tab_contents_view_win.cc
+++ b/chrome/browser/views/tab_contents/tab_contents_view_win.cc
@@ -129,8 +129,7 @@ void TabContentsViewWin::StartDragging(const WebDropData& drop_data,
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);
+ drag_handler_->StartDragging(drop_data, ops, image, image_offset);
}
void TabContentsViewWin::EndDragging() {
diff --git a/views/drag_utils.cc b/views/drag_utils.cc
index 8fbd79a..3b9f95b 100644
--- a/views/drag_utils.cc
+++ b/views/drag_utils.cc
@@ -95,4 +95,12 @@ void CreateDragImageForFile(const FilePath::StringType& file_name,
data_object);
}
+void SetDragImageOnDataObject(const gfx::Canvas& canvas,
+ const gfx::Size& size,
+ const gfx::Point& cursor_offset,
+ OSExchangeData* data_object) {
+ SetDragImageOnDataObject(
+ canvas.ExtractBitmap(), size, cursor_offset, data_object);
+}
+
} // namespace drag_utils
diff --git a/views/drag_utils.h b/views/drag_utils.h
index 974d648..cec512a 100644
--- a/views/drag_utils.h
+++ b/views/drag_utils.h
@@ -42,6 +42,14 @@ void SetDragImageOnDataObject(const gfx::Canvas& canvas,
const gfx::Size& size,
const gfx::Point& cursor_offset,
OSExchangeData* data_object);
+//
+// Sets the drag image on data_object from the supplied bitmap. width/height
+// are the size of the image to use, and the offsets give the location of
+// the hotspot for the drag image.
+void SetDragImageOnDataObject(const SkBitmap& bitmap,
+ const gfx::Size& size,
+ const gfx::Point& cursor_offset,
+ OSExchangeData* data_object);
} // namespace drag_utils
#endif // #ifndef VIEWS_DRAG_UTILS_H_
diff --git a/views/drag_utils_gtk.cc b/views/drag_utils_gtk.cc
index a22b0cf..8ab044b 100644
--- a/views/drag_utils_gtk.cc
+++ b/views/drag_utils_gtk.cc
@@ -13,18 +13,18 @@
#include "gfx/gtk_util.h"
#include "gfx/point.h"
#include "gfx/size.h"
+#include "third_party/skia/include/core/SkBitmap.h"
namespace drag_utils {
-void SetDragImageOnDataObject(const gfx::Canvas& canvas,
+void SetDragImageOnDataObject(const SkBitmap& bitmap,
const gfx::Size& size,
const gfx::Point& cursor_offset,
OSExchangeData* data_object) {
OSExchangeDataProviderGtk& provider(
static_cast<OSExchangeDataProviderGtk&>(data_object->provider()));
- // Convert the canvas into a GdkPixbuf.
- SkBitmap bitmap = canvas.ExtractBitmap();
+ // Convert the bitmap into a GdkPixbuf.
GdkPixbuf* canvas_pixbuf = gfx::GdkPixbufFromSkBitmap(&bitmap);
// Make a new pixbuf of the requested size and copy it over.
diff --git a/views/drag_utils_win.cc b/views/drag_utils_win.cc
index 74663a6..84b4ba1 100644
--- a/views/drag_utils_win.cc
+++ b/views/drag_utils_win.cc
@@ -10,8 +10,9 @@
#include "app/os_exchange_data.h"
#include "app/os_exchange_data_provider_win.h"
-#include "gfx/canvas.h"
+#include "gfx/canvas_skia.h"
#include "gfx/gdi_util.h"
+#include "third_party/skia/include/core/SkBitmap.h"
namespace drag_utils {
@@ -34,7 +35,7 @@ static void SetDragImageOnDataObject(HBITMAP hbitmap,
// Blit the contents of the canvas to a new HBITMAP. It is the caller's
// responsibility to release the |bits| buffer.
-static HBITMAP CreateBitmapFromCanvas(const gfx::Canvas& canvas,
+static HBITMAP CreateBitmapFromCanvas(const gfx::CanvasSkia& canvas,
int width,
int height) {
HDC screen_dc = GetDC(NULL);
@@ -55,10 +56,14 @@ static HBITMAP CreateBitmapFromCanvas(const gfx::Canvas& canvas,
return bitmap;
}
-void SetDragImageOnDataObject(const gfx::Canvas& canvas,
+void SetDragImageOnDataObject(const SkBitmap& sk_bitmap,
const gfx::Size& size,
const gfx::Point& cursor_offset,
OSExchangeData* data_object) {
+ gfx::CanvasSkia canvas(sk_bitmap.width(), sk_bitmap.height(),
+ /*is_opaque=*/false);
+ canvas.DrawBitmapInt(sk_bitmap, 0, 0);
+
DCHECK(data_object && !size.IsEmpty());
// SetDragImageOnDataObject(HBITMAP) takes ownership of the bitmap.
HBITMAP bitmap = CreateBitmapFromCanvas(canvas, size.width(), size.height());