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