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/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
10 #import "chrome/browser/ui/cocoa/dock_icon.h" | |
11 #include "content/public/browser/download_item.h" | 10 #include "content/public/browser/download_item.h" |
12 #include "content/public/browser/download_manager.h" | 11 #include "content/public/browser/download_manager.h" |
13 #include "ui/gfx/image/image.h" | 12 #include "ui/gfx/image/image.h" |
14 #include "ui/gfx/native_widget_types.h" | 13 #include "ui/gfx/native_widget_types.h" |
15 | 14 |
16 using content::DownloadItem; | 15 using content::DownloadItem; |
17 | 16 |
18 namespace download_util { | 17 namespace download_util { |
19 | 18 |
20 void AddFileToPasteboard(NSPasteboard* pasteboard, const FilePath& path) { | 19 void AddFileToPasteboard(NSPasteboard* pasteboard, const FilePath& path) { |
21 // Write information about the file being dragged to the pasteboard. | 20 // Write information about the file being dragged to the pasteboard. |
22 NSString* file = base::SysUTF8ToNSString(path.value()); | 21 NSString* file = base::SysUTF8ToNSString(path.value()); |
23 NSArray* fileList = [NSArray arrayWithObject:file]; | 22 NSArray* fileList = [NSArray arrayWithObject:file]; |
24 [pasteboard declareTypes:[NSArray arrayWithObject:NSFilenamesPboardType] | 23 [pasteboard declareTypes:[NSArray arrayWithObject:NSFilenamesPboardType] |
25 owner:nil]; | 24 owner:nil]; |
26 [pasteboard setPropertyList:fileList forType:NSFilenamesPboardType]; | 25 [pasteboard setPropertyList:fileList forType:NSFilenamesPboardType]; |
27 } | 26 } |
28 | 27 |
29 void NotifySystemOfDownloadComplete(const FilePath& path) { | |
30 NSString* filePath = base::SysUTF8ToNSString(path.value()); | |
31 [[NSDistributedNotificationCenter defaultCenter] | |
32 postNotificationName:@"com.apple.DownloadFileFinished" | |
33 object:filePath]; | |
34 | |
35 NSString* parentPath = [filePath stringByDeletingLastPathComponent]; | |
36 FNNotifyByPath( | |
37 reinterpret_cast<const UInt8*>([parentPath fileSystemRepresentation]), | |
38 kFNDirectoryModifiedMessage, | |
39 kNilOptions); | |
40 } | |
41 | |
42 void DragDownload(const DownloadItem* download, | 28 void DragDownload(const DownloadItem* download, |
43 gfx::Image* icon, | 29 gfx::Image* icon, |
44 gfx::NativeView view) { | 30 gfx::NativeView view) { |
45 NSPasteboard* pasteboard = [NSPasteboard pasteboardWithName:NSDragPboard]; | 31 NSPasteboard* pasteboard = [NSPasteboard pasteboardWithName:NSDragPboard]; |
46 AddFileToPasteboard(pasteboard, download->GetFullPath()); | 32 AddFileToPasteboard(pasteboard, download->GetFullPath()); |
47 | 33 |
48 // Synthesize a drag event, since we don't have access to the actual event | 34 // Synthesize a drag event, since we don't have access to the actual event |
49 // that initiated a drag (possibly consumed by the Web UI, for example). | 35 // that initiated a drag (possibly consumed by the Web UI, for example). |
50 NSPoint position = [[view window] mouseLocationOutsideOfEventStream]; | 36 NSPoint position = [[view window] mouseLocationOutsideOfEventStream]; |
51 NSTimeInterval eventTime = [[NSApp currentEvent] timestamp]; | 37 NSTimeInterval eventTime = [[NSApp currentEvent] timestamp]; |
(...skipping 10 matching lines...) Expand all Loading... |
62 // Run the drag operation. | 48 // Run the drag operation. |
63 [[view window] dragImage:*icon | 49 [[view window] dragImage:*icon |
64 at:position | 50 at:position |
65 offset:NSZeroSize | 51 offset:NSZeroSize |
66 event:dragEvent | 52 event:dragEvent |
67 pasteboard:pasteboard | 53 pasteboard:pasteboard |
68 source:view | 54 source:view |
69 slideBack:YES]; | 55 slideBack:YES]; |
70 } | 56 } |
71 | 57 |
72 void UpdateAppIconDownloadProgress(int download_count, | |
73 bool progress_known, | |
74 float progress) { | |
75 DockIcon* dock_icon = [DockIcon sharedDockIcon]; | |
76 [dock_icon setDownloads:download_count]; | |
77 [dock_icon setIndeterminate:!progress_known]; | |
78 [dock_icon setProgress:progress]; | |
79 [dock_icon updateIcon]; | |
80 } | |
81 | |
82 } // namespace download_util | 58 } // namespace download_util |
OLD | NEW |