Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Side by Side Diff: chrome/browser/ui/cocoa/download/download_util_mac.mm

Issue 11801022: Allow dragging a download only after the download is complete. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with trunk at 175906 Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/sys_string_conversions.h" 10 #include "base/sys_string_conversions.h"
10 #include "content/public/browser/download_item.h" 11 #include "content/public/browser/download_item.h"
11 #include "content/public/browser/download_manager.h" 12 #include "content/public/browser/download_manager.h"
12 #include "ui/gfx/image/image.h" 13 #include "ui/gfx/image/image.h"
13 #include "ui/gfx/native_widget_types.h" 14 #include "ui/gfx/native_widget_types.h"
14 15
15 using content::DownloadItem; 16 using content::DownloadItem;
16 17
17 namespace download_util { 18 namespace download_util {
18 19
19 void AddFileToPasteboard(NSPasteboard* pasteboard, const FilePath& path) { 20 void AddFileToPasteboard(NSPasteboard* pasteboard, const FilePath& path) {
20 // Write information about the file being dragged to the pasteboard. 21 // Write information about the file being dragged to the pasteboard.
21 NSString* file = base::SysUTF8ToNSString(path.value()); 22 NSString* file = base::SysUTF8ToNSString(path.value());
22 NSArray* fileList = [NSArray arrayWithObject:file]; 23 NSArray* fileList = [NSArray arrayWithObject:file];
23 [pasteboard declareTypes:[NSArray arrayWithObject:NSFilenamesPboardType] 24 [pasteboard declareTypes:[NSArray arrayWithObject:NSFilenamesPboardType]
24 owner:nil]; 25 owner:nil];
25 [pasteboard setPropertyList:fileList forType:NSFilenamesPboardType]; 26 [pasteboard setPropertyList:fileList forType:NSFilenamesPboardType];
26 } 27 }
27 28
28 void DragDownload(const DownloadItem* download, 29 void DragDownload(const DownloadItem* download,
29 gfx::Image* icon, 30 gfx::Image* icon,
30 gfx::NativeView view) { 31 gfx::NativeView view) {
32 DCHECK(download->IsComplete());
31 NSPasteboard* pasteboard = [NSPasteboard pasteboardWithName:NSDragPboard]; 33 NSPasteboard* pasteboard = [NSPasteboard pasteboardWithName:NSDragPboard];
32 AddFileToPasteboard(pasteboard, download->GetFullPath()); 34 AddFileToPasteboard(pasteboard, download->GetTargetFilePath());
33 35
34 // 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
35 // 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).
36 NSPoint position = [[view window] mouseLocationOutsideOfEventStream]; 38 NSPoint position = [[view window] mouseLocationOutsideOfEventStream];
37 NSTimeInterval eventTime = [[NSApp currentEvent] timestamp]; 39 NSTimeInterval eventTime = [[NSApp currentEvent] timestamp];
38 NSEvent* dragEvent = [NSEvent mouseEventWithType:NSLeftMouseDragged 40 NSEvent* dragEvent = [NSEvent mouseEventWithType:NSLeftMouseDragged
39 location:position 41 location:position
40 modifierFlags:NSLeftMouseDraggedMask 42 modifierFlags:NSLeftMouseDraggedMask
41 timestamp:eventTime 43 timestamp:eventTime
42 windowNumber:[[view window] windowNumber] 44 windowNumber:[[view window] windowNumber]
43 context:nil 45 context:nil
44 eventNumber:0 46 eventNumber:0
45 clickCount:1 47 clickCount:1
46 pressure:1.0]; 48 pressure:1.0];
47 49
48 // Run the drag operation. 50 // Run the drag operation.
49 [[view window] dragImage:icon->ToNSImage() 51 [[view window] dragImage:icon->ToNSImage()
50 at:position 52 at:position
51 offset:NSZeroSize 53 offset:NSZeroSize
52 event:dragEvent 54 event:dragEvent
53 pasteboard:pasteboard 55 pasteboard:pasteboard
54 source:view 56 source:view
55 slideBack:YES]; 57 slideBack:YES];
56 } 58 }
57 59
58 } // namespace download_util 60 } // namespace download_util
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/download/download_item_controller.mm ('k') | chrome/browser/ui/gtk/custom_drag.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698