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