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

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

Issue 164459: Implement drag and drop of downloads for the Mac downloads page (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 4 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
Property Changes:
Name: svn:eol-style
+ LF
OLDNEW
(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
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/download_util_mac.h ('k') | chrome/browser/cocoa/download_util_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698