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