summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpaul@chromium.org <paul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-17 18:01:55 +0000
committerpaul@chromium.org <paul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-17 18:01:55 +0000
commitaf066a6a6f9859764a62071a00a401edf76b8024 (patch)
treef8ab2e801a4d65c7314e183b5493b74a5ebfcddd
parente68d6578f6c64a9120eb224aa594eca1c5960df3 (diff)
downloadchromium_src-af066a6a6f9859764a62071a00a401edf76b8024.zip
chromium_src-af066a6a6f9859764a62071a00a401edf76b8024.tar.gz
chromium_src-af066a6a6f9859764a62071a00a401edf76b8024.tar.bz2
Implement drag and drop of downloads for the Mac downloads page.
BUG=15776 (http://crbug.com/15776) TEST=Download an item, open the download page, drag the icon of the download to the desktop. Review URL: http://codereview.chromium.org/164459 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23548 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/cocoa/download_util_mac.h15
-rw-r--r--chrome/browser/cocoa/download_util_mac.mm58
-rw-r--r--chrome/browser/cocoa/download_util_mac_unittest.mm48
-rw-r--r--chrome/browser/dom_ui/downloads_dom_handler.cc6
-rw-r--r--chrome/browser/download/download_util.cc9
-rw-r--r--chrome/browser/download/download_util.h10
-rw-r--r--chrome/browser/views/download_item_view.cc2
-rw-r--r--chrome/chrome.gyp3
-rw-r--r--chrome/common/temp_scaffolding_stubs.cc6
-rw-r--r--chrome/common/temp_scaffolding_stubs.h6
10 files changed, 149 insertions, 14 deletions
diff --git a/chrome/browser/cocoa/download_util_mac.h b/chrome/browser/cocoa/download_util_mac.h
new file mode 100644
index 0000000..18075eb
--- /dev/null
+++ b/chrome/browser/cocoa/download_util_mac.h
@@ -0,0 +1,15 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+// Download utility functions for Mac OS X.
+
+#import <Cocoa/Cocoa.h>
+
+#include "base/file_path.h"
+
+namespace download_util {
+
+void AddFileToPasteboard(NSPasteboard* pasteboard, const FilePath& path);
+
+} // namespace download_util
diff --git a/chrome/browser/cocoa/download_util_mac.mm b/chrome/browser/cocoa/download_util_mac.mm
new file mode 100644
index 0000000..19462c1
--- /dev/null
+++ b/chrome/browser/cocoa/download_util_mac.mm
@@ -0,0 +1,58 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+// Download utility implementation for Mac OS X.
+
+#include "chrome/browser/cocoa/download_util_mac.h"
+
+#include "base/gfx/native_widget_types.h"
+#include "base/sys_string_conversions.h"
+#include "chrome/browser/download/download_manager.h"
+#include "skia/ext/skia_utils_mac.h"
+
+namespace download_util {
+
+void AddFileToPasteboard(NSPasteboard* pasteboard, const FilePath& path) {
+ // Write information about the file being dragged to the pasteboard.
+ NSString* file = base::SysWideToNSString(path.ToWStringHack());
+ NSArray* fileList = [NSArray arrayWithObject:file];
+ [pasteboard declareTypes:[NSArray arrayWithObject:NSFilenamesPboardType]
+ owner:nil];
+ [pasteboard setPropertyList:fileList forType:NSFilenamesPboardType];
+}
+
+void DragDownload(const DownloadItem* download,
+ SkBitmap* icon,
+ gfx::NativeView view) {
+ NSPasteboard* pasteboard = [NSPasteboard pasteboardWithName:NSDragPboard];
+ AddFileToPasteboard(pasteboard, download->full_path());
+
+ // Convert to an NSImage.
+ NSImage* dragImage = gfx::SkBitmapToNSImage(*icon);
+
+ // Synthesize a drag event, since we don't have access to the actual event
+ // that initiated a drag (possibly consumed by the DOM UI, for example).
+ NSPoint position = [[view window] mouseLocationOutsideOfEventStream];
+ NSTimeInterval eventTime = [[NSApp currentEvent] timestamp];
+ NSEvent* dragEvent = [NSEvent mouseEventWithType:NSLeftMouseDragged
+ location:position
+ modifierFlags:NSLeftMouseDraggedMask
+ timestamp:eventTime
+ windowNumber:[[view window] windowNumber]
+ context:nil
+ eventNumber:0
+ clickCount:1
+ pressure:1.0];
+
+ // Run the drag operation.
+ [[view window] dragImage:dragImage
+ at:position
+ offset:NSZeroSize
+ event:dragEvent
+ pasteboard:pasteboard
+ source:view
+ slideBack:YES];
+}
+
+} // namespace download_util
diff --git a/chrome/browser/cocoa/download_util_mac_unittest.mm b/chrome/browser/cocoa/download_util_mac_unittest.mm
new file mode 100644
index 0000000..6789b16
--- /dev/null
+++ b/chrome/browser/cocoa/download_util_mac_unittest.mm
@@ -0,0 +1,48 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+// Download utility test for Mac OS X.
+
+#include "base/path_service.h"
+#include "base/sys_string_conversions.h"
+#import "chrome/browser/cocoa/cocoa_test_helper.h"
+#import "chrome/browser/cocoa/download_util_mac.h"
+#include "chrome/common/chrome_paths.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+class DownloadUtilTest : public testing::Test {
+ public:
+ CocoaTestHelper cocoa_helper_;
+};
+
+// Ensure adding files to the pasteboard methods works as expected.
+TEST_F(DownloadUtilTest, AddFileToPasteboardTest) {
+ // Create a pasteboard.
+ NSPasteboard* pasteboard = [NSPasteboard pasteboardWithUniqueName];
+
+ // Get a download test file for addition to the pasteboard.
+ FilePath testPath;
+ ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &testPath));
+ FilePath testFile(FILE_PATH_LITERAL("download-test1.lib"));
+ testPath = testPath.Append(testFile);
+
+ // Add a test file to the pasteboard via the download_util method.
+ download_util::AddFileToPasteboard(pasteboard, testPath);
+
+ // Test to see that the object type for dragging files is available.
+ NSArray* types = [NSArray arrayWithObject:NSFilenamesPboardType];
+ NSString* available = [pasteboard availableTypeFromArray:types];
+ EXPECT_TRUE(available != nil);
+
+ // Ensure the path is what we expect.
+ NSArray* files = [pasteboard propertyListForType:NSFilenamesPboardType];
+ ASSERT_TRUE(files != nil);
+ NSString* expectedPath = [files objectAtIndex:0];
+ NSString* realPath = base::SysWideToNSString(testPath.ToWStringHack());
+ EXPECT_TRUE([expectedPath isEqualToString:realPath]);
+}
+
+} // namespace
diff --git a/chrome/browser/dom_ui/downloads_dom_handler.cc b/chrome/browser/dom_ui/downloads_dom_handler.cc
index 703d2fb6..aa646c0 100644
--- a/chrome/browser/dom_ui/downloads_dom_handler.cc
+++ b/chrome/browser/dom_ui/downloads_dom_handler.cc
@@ -16,13 +16,14 @@
#include "chrome/browser/dom_ui/fileicon_source.h"
#include "chrome/browser/metrics/user_metrics.h"
#include "chrome/browser/profile.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/common/jstemplate_builder.h"
#include "chrome/common/time_format.h"
#include "chrome/common/url_constants.h"
#include "grit/browser_resources.h"
#include "grit/generated_resources.h"
-#if defined(TOOLKIT_VIEWS)
+#if defined(TOOLKIT_VIEWS) || defined(OS_MACOSX)
// TODO(port): re-enable when download_util is ported
#include "chrome/browser/download/download_util.h"
#else
@@ -169,7 +170,8 @@ void DownloadsDOMHandler::HandleDrag(const Value* value) {
if (file) {
IconManager* im = g_browser_process->icon_manager();
SkBitmap* icon = im->LookupIcon(file->full_path(), IconLoader::NORMAL);
- download_util::DragDownload(file, icon);
+ gfx::NativeView view = dom_ui_->tab_contents()->GetNativeView();
+ download_util::DragDownload(file, icon, view);
}
}
diff --git a/chrome/browser/download/download_util.cc b/chrome/browser/download/download_util.cc
index 23f47c7..9a3f943 100644
--- a/chrome/browser/download/download_util.cc
+++ b/chrome/browser/download/download_util.cc
@@ -220,8 +220,7 @@ int GetBigProgressIconSize() {
static int big_progress_icon_size = 0;
if (big_progress_icon_size == 0) {
string16 locale_size_str =
- WideToUTF16Hack(
- l10n_util::GetString(IDS_DOWNLOAD_BIG_PROGRESS_SIZE));
+ WideToUTF16Hack(l10n_util::GetString(IDS_DOWNLOAD_BIG_PROGRESS_SIZE));
bool rc = StringToInt(locale_size_str, &big_progress_icon_size);
if (!rc || big_progress_icon_size < kBigProgressIconSize) {
NOTREACHED();
@@ -238,7 +237,9 @@ int GetBigProgressIconOffset() {
#if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
// Download dragging
-void DragDownload(const DownloadItem* download, SkBitmap* icon) {
+void DragDownload(const DownloadItem* download,
+ SkBitmap* icon,
+ gfx::NativeView view) {
#if defined(OS_WIN)
DCHECK(download);
@@ -269,7 +270,7 @@ void DragDownload(const DownloadItem* download, SkBitmap* icon) {
DROPEFFECT_COPY | DROPEFFECT_LINK, &effects);
#else
NOTIMPLEMENTED();
-#endif
+#endif // OS_WIN
}
#endif
diff --git a/chrome/browser/download/download_util.h b/chrome/browser/download/download_util.h
index 11edd5e..2093f34 100644
--- a/chrome/browser/download/download_util.h
+++ b/chrome/browser/download/download_util.h
@@ -11,6 +11,7 @@
#include <string>
#include "base/basictypes.h"
+#include "base/gfx/native_widget_types.h"
#include "base/task.h"
#if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
@@ -119,12 +120,15 @@ void PaintDownloadComplete(gfx::Canvas* canvas,
double animation_progress,
PaintDownloadProgressSize size);
-#if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
+#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.
-void DragDownload(const DownloadItem* download, SkBitmap* icon);
+// 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.
+void DragDownload(const DownloadItem* download,
+ SkBitmap* icon,
+ gfx::NativeView view);
#endif
// Executable file support -----------------------------------------------------
diff --git a/chrome/browser/views/download_item_view.cc b/chrome/browser/views/download_item_view.cc
index 54f3a15..ec4d514 100644
--- a/chrome/browser/views/download_item_view.cc
+++ b/chrome/browser/views/download_item_view.cc
@@ -872,7 +872,7 @@ bool DownloadItemView::OnMouseDragged(const views::MouseEvent& event) {
SkBitmap* icon = im->LookupIcon(download_->full_path(),
IconLoader::SMALL);
if (icon)
- download_util::DragDownload(download_, icon);
+ download_util::DragDownload(download_, icon, NULL);
}
} else if (ExceededDragThreshold(
event.location().x() - drag_start_point_.x(),
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index d4e3aca..3152fa5 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -848,6 +848,8 @@
'browser/cocoa/download_shelf_view.h',
'browser/cocoa/download_shelf_view.mm',
'browser/cocoa/download_started_animation_mac.mm',
+ 'browser/cocoa/download_util_mac.h',
+ 'browser/cocoa/download_util_mac.mm',
'browser/cocoa/encoding_menu_controller_delegate_mac.h',
'browser/cocoa/encoding_menu_controller_delegate_mac.mm',
'browser/cocoa/find_bar_bridge.h',
@@ -3806,6 +3808,7 @@
'browser/cocoa/custom_home_pages_model_unittest.mm',
'browser/cocoa/download_shelf_mac_unittest.mm',
'browser/cocoa/download_shelf_view_unittest.mm',
+ 'browser/cocoa/download_util_mac_unittest.mm',
'browser/cocoa/find_bar_bridge_unittest.mm',
'browser/cocoa/find_bar_cocoa_controller_unittest.mm',
'browser/cocoa/find_bar_view_unittest.mm',
diff --git a/chrome/common/temp_scaffolding_stubs.cc b/chrome/common/temp_scaffolding_stubs.cc
index 46aacd0..0f3dfed 100644
--- a/chrome/common/temp_scaffolding_stubs.cc
+++ b/chrome/common/temp_scaffolding_stubs.cc
@@ -259,10 +259,12 @@ DownloadRequestDialogDelegate* DownloadRequestDialogDelegate::Create(
}
#endif
-#if !defined(TOOLKIT_VIEWS)
+#if !defined(TOOLKIT_VIEWS) && !defined(OS_MACOSX)
namespace download_util {
-void DragDownload(const DownloadItem* download, SkBitmap* icon) {
+void DragDownload(const DownloadItem* download,
+ SkBitmap* icon,
+ gfx::NativeView view) {
NOTIMPLEMENTED();
}
diff --git a/chrome/common/temp_scaffolding_stubs.h b/chrome/common/temp_scaffolding_stubs.h
index 898081b..d0b5621 100644
--- a/chrome/common/temp_scaffolding_stubs.h
+++ b/chrome/common/temp_scaffolding_stubs.h
@@ -270,9 +270,11 @@ class BookmarkEditorView {
//---------------------------------------------------------------------------
// These stubs are for Browser
-#if !defined(TOOLKIT_VIEWS)
+#if !defined(TOOLKIT_VIEWS) && !defined(OS_MACOSX)
namespace download_util {
-void DragDownload(const DownloadItem* download, SkBitmap* icon);
+void DragDownload(const DownloadItem* download,
+ SkBitmap* icon,
+ gfx::NativeView view);
} // namespace download_util
#endif