Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / download / download_item_drag_mac.mm
blob6e6af1295db03961cec69348f6534c1c653d8e22
1 // Copyright 2013 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.
5 #include "chrome/browser/download/drag_download_item.h"
7 #include "chrome/browser/ui/cocoa/download/download_util_mac.h"
8 #include "content/public/browser/download_item.h"
9 #include "ui/gfx/image/image.h"
11 void DragDownloadItem(const content::DownloadItem* download,
12                       gfx::Image* icon,
13                       gfx::NativeView view) {
14   DCHECK_EQ(content::DownloadItem::COMPLETE, download->GetState());
15   NSPasteboard* pasteboard = [NSPasteboard pasteboardWithName:NSDragPboard];
16   download_util::AddFileToPasteboard(pasteboard, download->GetTargetFilePath());
18   // Synthesize a drag event, since we don't have access to the actual event
19   // that initiated a drag (possibly consumed by the Web UI, for example).
20   NSPoint position = [[view window] mouseLocationOutsideOfEventStream];
21   NSTimeInterval eventTime = [[NSApp currentEvent] timestamp];
22   NSEvent* dragEvent = [NSEvent mouseEventWithType:NSLeftMouseDragged
23                                           location:position
24                                      modifierFlags:NSLeftMouseDraggedMask
25                                          timestamp:eventTime
26                                       windowNumber:[[view window] windowNumber]
27                                            context:nil
28                                        eventNumber:0
29                                         clickCount:1
30                                           pressure:1.0];
32   // Run the drag operation.
33   [[view window] dragImage:icon->ToNSImage()
34                         at:position
35                     offset:NSZeroSize
36                      event:dragEvent
37                 pasteboard:pasteboard
38                     source:view
39                  slideBack:YES];