| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 |
| 5 // Download utility implementation for Mac OS X. | 5 #include "chrome/browser/download/drag_download_item.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/cocoa/download/download_util_mac.h" | 7 #include "chrome/browser/ui/cocoa/download/download_util_mac.h" |
| 8 #include "content/public/browser/download_item.h" |
| 9 #include "ui/gfx/image/image.h" |
| 8 | 10 |
| 9 #include "base/logging.h" | 11 void DragDownloadItem(const content::DownloadItem* download, |
| 10 #include "base/strings/sys_string_conversions.h" | 12 gfx::Image* icon, |
| 11 #include "content/public/browser/download_item.h" | 13 gfx::NativeView view) { |
| 12 #include "content/public/browser/download_manager.h" | 14 DCHECK_EQ(content::DownloadItem::COMPLETE, download->GetState()); |
| 13 #include "ui/gfx/image/image.h" | |
| 14 #include "ui/gfx/native_widget_types.h" | |
| 15 | |
| 16 using content::DownloadItem; | |
| 17 | |
| 18 namespace download_util { | |
| 19 | |
| 20 void AddFileToPasteboard(NSPasteboard* pasteboard, const base::FilePath& path) { | |
| 21 // Write information about the file being dragged to the pasteboard. | |
| 22 NSString* file = base::SysUTF8ToNSString(path.value()); | |
| 23 NSArray* fileList = [NSArray arrayWithObject:file]; | |
| 24 [pasteboard declareTypes:[NSArray arrayWithObject:NSFilenamesPboardType] | |
| 25 owner:nil]; | |
| 26 [pasteboard setPropertyList:fileList forType:NSFilenamesPboardType]; | |
| 27 } | |
| 28 | |
| 29 void DragDownload(const DownloadItem* download, | |
| 30 gfx::Image* icon, | |
| 31 gfx::NativeView view) { | |
| 32 DCHECK_EQ(DownloadItem::COMPLETE, download->GetState()); | |
| 33 NSPasteboard* pasteboard = [NSPasteboard pasteboardWithName:NSDragPboard]; | 15 NSPasteboard* pasteboard = [NSPasteboard pasteboardWithName:NSDragPboard]; |
| 34 AddFileToPasteboard(pasteboard, download->GetTargetFilePath()); | 16 download_util::AddFileToPasteboard(pasteboard, download->GetTargetFilePath()); |
| 35 | 17 |
| 36 // Synthesize a drag event, since we don't have access to the actual event | 18 // Synthesize a drag event, since we don't have access to the actual event |
| 37 // that initiated a drag (possibly consumed by the Web UI, for example). | 19 // that initiated a drag (possibly consumed by the Web UI, for example). |
| 38 NSPoint position = [[view window] mouseLocationOutsideOfEventStream]; | 20 NSPoint position = [[view window] mouseLocationOutsideOfEventStream]; |
| 39 NSTimeInterval eventTime = [[NSApp currentEvent] timestamp]; | 21 NSTimeInterval eventTime = [[NSApp currentEvent] timestamp]; |
| 40 NSEvent* dragEvent = [NSEvent mouseEventWithType:NSLeftMouseDragged | 22 NSEvent* dragEvent = [NSEvent mouseEventWithType:NSLeftMouseDragged |
| 41 location:position | 23 location:position |
| 42 modifierFlags:NSLeftMouseDraggedMask | 24 modifierFlags:NSLeftMouseDraggedMask |
| 43 timestamp:eventTime | 25 timestamp:eventTime |
| 44 windowNumber:[[view window] windowNumber] | 26 windowNumber:[[view window] windowNumber] |
| 45 context:nil | 27 context:nil |
| 46 eventNumber:0 | 28 eventNumber:0 |
| 47 clickCount:1 | 29 clickCount:1 |
| 48 pressure:1.0]; | 30 pressure:1.0]; |
| 49 | 31 |
| 50 // Run the drag operation. | 32 // Run the drag operation. |
| 51 [[view window] dragImage:icon->ToNSImage() | 33 [[view window] dragImage:icon->ToNSImage() |
| 52 at:position | 34 at:position |
| 53 offset:NSZeroSize | 35 offset:NSZeroSize |
| 54 event:dragEvent | 36 event:dragEvent |
| 55 pasteboard:pasteboard | 37 pasteboard:pasteboard |
| 56 source:view | 38 source:view |
| 57 slideBack:YES]; | 39 slideBack:YES]; |
| 58 } | 40 } |
| 59 | |
| 60 } // namespace download_util | |
| OLD | NEW |