summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-23 21:42:58 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-23 21:42:58 +0000
commitb6d432335f59500e092de2be4fcf42ed303ae1c5 (patch)
tree0dae24ec6c0f89442ee37d18aeb17f5dcf48d6e0 /chrome
parent599ea9fd7f5f029661916c191ff89b7358719f81 (diff)
downloadchromium_src-b6d432335f59500e092de2be4fcf42ed303ae1c5.zip
chromium_src-b6d432335f59500e092de2be4fcf42ed303ae1c5.tar.gz
chromium_src-b6d432335f59500e092de2be4fcf42ed303ae1c5.tar.bz2
Implements file contents support in OSExchangeData and DropTarget
for gtk. Makes html and file contents support in OSExchangeData only for windows (as that is the only place we need it), and makes dragging files work. BUG=none TEST=none Review URL: http://codereview.chromium.org/232002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26995 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/download/download_util.cc48
-rw-r--r--chrome/browser/download/download_util.h8
-rw-r--r--chrome/browser/views/download_item_view.cc7
3 files changed, 40 insertions, 23 deletions
diff --git a/chrome/browser/download/download_util.cc b/chrome/browser/download/download_util.cc
index 9a3f943..6b3b2f1 100644
--- a/chrome/browser/download/download_util.cc
+++ b/chrome/browser/download/download_util.cc
@@ -24,14 +24,19 @@
#include "third_party/skia/include/core/SkPath.h"
#include "third_party/skia/include/core/SkShader.h"
-#if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
+#if defined(TOOLKIT_VIEWS)
#include "app/os_exchange_data.h"
+#include "views/drag_utils.h"
+#endif
+
+#if defined(TOOLKIT_VIEWS) && defined(OS_LINUX)
+#include "app/drag_drop_types.h"
+#include "views/widget/widget_gtk.h"
#endif
#if defined(OS_WIN)
#include "app/os_exchange_data_provider_win.h"
#include "base/base_drag_source.h"
-#include "views/drag_utils.h"
#endif
namespace download_util {
@@ -72,7 +77,7 @@ SkBitmap* g_foreground_32 = NULL;
SkBitmap* g_background_32 = NULL;
void PaintDownloadProgress(gfx::Canvas* canvas,
-#if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
+#if defined(TOOLKIT_VIEWS)
views::View* containing_view,
#endif
int origin_x,
@@ -102,7 +107,7 @@ void PaintDownloadProgress(gfx::Canvas* canvas,
gfx::Rect foreground_bounds(origin_x, origin_y,
foreground->width(), foreground->height());
-#if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
+#if defined(TOOLKIT_VIEWS)
// Mirror the positions if necessary.
int mirrored_x = containing_view->MirroredLeftPointForRect(background_bounds);
background_bounds.set_x(mirrored_x);
@@ -171,7 +176,7 @@ void PaintDownloadProgress(gfx::Canvas* canvas,
}
void PaintDownloadComplete(gfx::Canvas* canvas,
-#if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
+#if defined(TOOLKIT_VIEWS)
views::View* containing_view,
#endif
int origin_x,
@@ -189,7 +194,7 @@ void PaintDownloadComplete(gfx::Canvas* canvas,
gfx::Rect complete_bounds(origin_x, origin_y,
complete->width(), complete->height());
-#if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
+#if defined(TOOLKIT_VIEWS)
// Mirror the positions if necessary.
complete_bounds.set_x(
containing_view->MirroredLeftPointForRect(complete_bounds));
@@ -235,41 +240,50 @@ int GetBigProgressIconOffset() {
return (GetBigProgressIconSize() - kBigIconSize) / 2;
}
-#if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
+#if defined(TOOLKIT_VIEWS)
// Download dragging
void DragDownload(const DownloadItem* download,
SkBitmap* icon,
gfx::NativeView view) {
-#if defined(OS_WIN)
DCHECK(download);
// Set up our OLE machinery
OSExchangeData data;
- const FilePath::StringType file_name = download->file_name().value();
- if (icon)
- drag_utils::CreateDragImageForFile(file_name, icon, &data);
- data.SetFilename(download->full_path().ToWStringHack());
+ if (icon) {
+ drag_utils::CreateDragImageForFile(download->file_name().value(), icon,
+ &data);
+ }
const FilePath full_path = download->full_path();
- data.SetFilename(full_path.value());
+ data.SetFilename(full_path.ToWStringHack());
std::string mime_type = download->mime_type();
if (mime_type.empty())
net::GetMimeTypeFromFile(full_path, &mime_type);
// Add URL so that we can load supported files when dragged to TabContents.
- if (net::IsSupportedMimeType(mime_type))
- data.SetURL(GURL(full_path.value()), file_name);
+ if (net::IsSupportedMimeType(mime_type)) {
+ data.SetURL(GURL(WideToUTF8(full_path.ToWStringHack())),
+ download->file_name().ToWStringHack());
+ }
+#if defined(OS_WIN)
scoped_refptr<BaseDragSource> drag_source(new BaseDragSource);
// Run the drag and drop loop
DWORD effects;
DoDragDrop(OSExchangeDataProviderWin::GetIDataObject(data), drag_source.get(),
DROPEFFECT_COPY | DROPEFFECT_LINK, &effects);
-#else
- NOTIMPLEMENTED();
+#elif defined(OS_LINUX)
+ GtkWidget* root = gtk_widget_get_toplevel(view);
+ if (!root)
+ return;
+ views::WidgetGtk* widget = views::WidgetGtk::GetViewForNative(root);
+ if (!widget)
+ return;
+
+ widget->DoDrag(data, DragDropTypes::DRAG_COPY | DragDropTypes::DRAG_LINK);
#endif // OS_WIN
}
#endif
diff --git a/chrome/browser/download/download_util.h b/chrome/browser/download/download_util.h
index 2093f34..0a320db 100644
--- a/chrome/browser/download/download_util.h
+++ b/chrome/browser/download/download_util.h
@@ -14,7 +14,7 @@
#include "base/gfx/native_widget_types.h"
#include "base/task.h"
-#if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
+#if defined(TOOLKIT_VIEWS)
#include "views/view.h"
#endif
@@ -102,7 +102,7 @@ enum PaintDownloadProgressSize {
// drawing in a right-to-left locale, we need to mirror the position of the
// progress animation within the containing View.
void PaintDownloadProgress(gfx::Canvas* canvas,
-#if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
+#if defined(TOOLKIT_VIEWS)
views::View* containing_view,
#endif
int origin_x,
@@ -112,7 +112,7 @@ void PaintDownloadProgress(gfx::Canvas* canvas,
PaintDownloadProgressSize size);
void PaintDownloadComplete(gfx::Canvas* canvas,
-#if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
+#if defined(TOOLKIT_VIEWS)
views::View* containing_view,
#endif
int origin_x,
@@ -120,12 +120,12 @@ void PaintDownloadComplete(gfx::Canvas* canvas,
double animation_progress,
PaintDownloadProgressSize size);
-#if defined(OS_WIN) || defined(TOOLKIT_VIEWS) || defined(OS_MACOSX)
// Drag support ----------------------------------------------------------------
// Helper function for download views to use when acting as a drag source for a
// DownloadItem. If |icon| is NULL, no image will be accompany the drag. |view|
// is only required for Mac OS X, elsewhere it can be NULL.
+#if defined(TOOLKIT_VIEWS) || defined(OS_MACOSX)
void DragDownload(const DownloadItem* download,
SkBitmap* icon,
gfx::NativeView view);
diff --git a/chrome/browser/views/download_item_view.cc b/chrome/browser/views/download_item_view.cc
index 65fa198..61650b3 100644
--- a/chrome/browser/views/download_item_view.cc
+++ b/chrome/browser/views/download_item_view.cc
@@ -910,8 +910,11 @@ bool DownloadItemView::OnMouseDragged(const views::MouseEvent& event) {
IconManager* im = g_browser_process->icon_manager();
SkBitmap* icon = im->LookupIcon(download_->full_path(),
IconLoader::SMALL);
- if (icon)
- download_util::DragDownload(download_, icon, NULL);
+ if (icon) {
+ views::Widget* widget = GetWidget();
+ download_util::DragDownload(download_, icon,
+ widget ? widget->GetNativeView() : NULL);
+ }
}
} else if (ExceededDragThreshold(
event.location().x() - drag_start_point_.x(),