| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // Download utility implementation for Mac OS X. |
| 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 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 NSString* file = base::SysUTF8ToNSString(path.value()); | 22 NSString* file = base::SysUTF8ToNSString(path.value()); |
| 23 NSArray* fileList = [NSArray arrayWithObject:file]; | 23 NSArray* fileList = [NSArray arrayWithObject:file]; |
| 24 [pasteboard declareTypes:[NSArray arrayWithObject:NSFilenamesPboardType] | 24 [pasteboard declareTypes:[NSArray arrayWithObject:NSFilenamesPboardType] |
| 25 owner:nil]; | 25 owner:nil]; |
| 26 [pasteboard setPropertyList:fileList forType:NSFilenamesPboardType]; | 26 [pasteboard setPropertyList:fileList forType:NSFilenamesPboardType]; |
| 27 } | 27 } |
| 28 | 28 |
| 29 void DragDownload(const DownloadItem* download, | 29 void DragDownload(const DownloadItem* download, |
| 30 gfx::Image* icon, | 30 gfx::Image* icon, |
| 31 gfx::NativeView view) { | 31 gfx::NativeView view) { |
| 32 DCHECK(download->IsComplete()); | 32 DCHECK_EQ(DownloadItem::COMPLETE, download->GetState()); |
| 33 NSPasteboard* pasteboard = [NSPasteboard pasteboardWithName:NSDragPboard]; | 33 NSPasteboard* pasteboard = [NSPasteboard pasteboardWithName:NSDragPboard]; |
| 34 AddFileToPasteboard(pasteboard, download->GetTargetFilePath()); | 34 AddFileToPasteboard(pasteboard, download->GetTargetFilePath()); |
| 35 | 35 |
| 36 // Synthesize a drag event, since we don't have access to the actual event | 36 // 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). | 37 // that initiated a drag (possibly consumed by the Web UI, for example). |
| 38 NSPoint position = [[view window] mouseLocationOutsideOfEventStream]; | 38 NSPoint position = [[view window] mouseLocationOutsideOfEventStream]; |
| 39 NSTimeInterval eventTime = [[NSApp currentEvent] timestamp]; | 39 NSTimeInterval eventTime = [[NSApp currentEvent] timestamp]; |
| 40 NSEvent* dragEvent = [NSEvent mouseEventWithType:NSLeftMouseDragged | 40 NSEvent* dragEvent = [NSEvent mouseEventWithType:NSLeftMouseDragged |
| 41 location:position | 41 location:position |
| 42 modifierFlags:NSLeftMouseDraggedMask | 42 modifierFlags:NSLeftMouseDraggedMask |
| 43 timestamp:eventTime | 43 timestamp:eventTime |
| 44 windowNumber:[[view window] windowNumber] | 44 windowNumber:[[view window] windowNumber] |
| 45 context:nil | 45 context:nil |
| 46 eventNumber:0 | 46 eventNumber:0 |
| 47 clickCount:1 | 47 clickCount:1 |
| 48 pressure:1.0]; | 48 pressure:1.0]; |
| 49 | 49 |
| 50 // Run the drag operation. | 50 // Run the drag operation. |
| 51 [[view window] dragImage:icon->ToNSImage() | 51 [[view window] dragImage:icon->ToNSImage() |
| 52 at:position | 52 at:position |
| 53 offset:NSZeroSize | 53 offset:NSZeroSize |
| 54 event:dragEvent | 54 event:dragEvent |
| 55 pasteboard:pasteboard | 55 pasteboard:pasteboard |
| 56 source:view | 56 source:view |
| 57 slideBack:YES]; | 57 slideBack:YES]; |
| 58 } | 58 } |
| 59 | 59 |
| 60 } // namespace download_util | 60 } // namespace download_util |
| OLD | NEW |