web_drag_source_mac.h revision c5cede9ae108bb15f6b7a8aea21c7e1fefa2834c
1// Copyright (c) 2012 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#import <Cocoa/Cocoa.h>
6
7#include "base/files/file_path.h"
8#include "base/mac/scoped_cftyperef.h"
9#include "base/mac/scoped_nsobject.h"
10#include "base/memory/scoped_ptr.h"
11#include "content/common/content_export.h"
12#include "url/gurl.h"
13
14namespace content {
15class WebContentsImpl;
16struct DropData;
17}
18
19// A class that handles tracking and event processing for a drag and drop
20// originating from the content area.
21CONTENT_EXPORT
22@interface WebDragSource : NSObject {
23 @private
24  // Our contents. Weak reference (owns or co-owns us).
25  content::WebContentsImpl* contents_;
26
27  // The view from which the drag was initiated. Weak reference.
28  NSView* contentsView_;
29
30  // Our drop data. Should only be initialized once.
31  scoped_ptr<content::DropData> dropData_;
32
33  // The image to show as drag image. Can be nil.
34  base::scoped_nsobject<NSImage> dragImage_;
35
36  // The offset to draw |dragImage_| at.
37  NSPoint imageOffset_;
38
39  // Our pasteboard.
40  base::scoped_nsobject<NSPasteboard> pasteboard_;
41
42  // A mask of the allowed drag operations.
43  NSDragOperation dragOperationMask_;
44
45  // The file name to be saved to for a drag-out download.
46  base::FilePath downloadFileName_;
47
48  // The URL to download from for a drag-out download.
49  GURL downloadURL_;
50
51  // The file UTI associated with the file drag, if any.
52  base::ScopedCFTypeRef<CFStringRef> fileUTI_;
53}
54
55// Initialize a WebDragSource object for a drag (originating on the given
56// contentsView and with the given dropData and pboard). Fill the pasteboard
57// with data types appropriate for dropData.
58- (id)initWithContents:(content::WebContentsImpl*)contents
59                  view:(NSView*)contentsView
60              dropData:(const content::DropData*)dropData
61                 image:(NSImage*)image
62                offset:(NSPoint)offset
63            pasteboard:(NSPasteboard*)pboard
64     dragOperationMask:(NSDragOperation)dragOperationMask;
65
66// Call when the web contents is gone.
67- (void)clearWebContentsView;
68
69// Returns a mask of the allowed drag operations.
70- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal;
71
72// Call when asked to do a lazy write to the pasteboard; hook up to
73// -pasteboard:provideDataForType: (on the contentsView).
74- (void)lazyWriteToPasteboard:(NSPasteboard*)pboard
75                      forType:(NSString*)type;
76
77// Start the drag (on the originally provided contentsView); can do this right
78// after -initWithContentsView:....
79- (void)startDrag;
80
81// End the drag and clear the pasteboard; hook up to
82// -draggedImage:endedAt:operation:.
83- (void)endDragAt:(NSPoint)screenPoint
84        operation:(NSDragOperation)operation;
85
86// Call to drag a promised file to the given path (should be called before
87// -endDragAt:...); hook up to -namesOfPromisedFilesDroppedAtDestination:.
88// Returns the file name (not including path) of the file deposited (or which
89// will be deposited).
90- (NSString*)dragPromisedFileTo:(NSString*)path;
91
92@end
93