web_drag_source_mac.h revision 7dbb3d5cf0c15f500944d211057644d6a2f37371
13839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o// Copyright (c) 2012 The Chromium Authors. All rights reserved. 23839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o// Use of this source code is governed by a BSD-style license that can be 33839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o// found in the LICENSE file. 43839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o 53839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o#import <Cocoa/Cocoa.h> 63839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o 73839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o#include "base/files/file_path.h" 83839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o#include "base/mac/scoped_cftyperef.h" 93839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o#include "base/mac/scoped_nsobject.h" 103839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o#include "base/memory/scoped_ptr.h" 113839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o#include "content/common/content_export.h" 123839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o#include "url/gurl.h" 133839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o 143839e65723771b85975f4263102dd3ceec4523cTheodore Ts'onamespace content { 153839e65723771b85975f4263102dd3ceec4523cTheodore Ts'oclass WebContentsImpl; 163839e65723771b85975f4263102dd3ceec4523cTheodore Ts'ostruct DropData; 173839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o} 183839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o 193839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o// A class that handles tracking and event processing for a drag and drop 203839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o// originating from the content area. 213839e65723771b85975f4263102dd3ceec4523cTheodore Ts'oCONTENT_EXPORT 223839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o@interface WebDragSource : NSObject { 233839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o @private 243839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o // Our contents. Weak reference (owns or co-owns us). 253839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o content::WebContentsImpl* contents_; 263839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o 273839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o // The view from which the drag was initiated. Weak reference. 283839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o NSView* contentsView_; 293839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o 303839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o // Our drop data. Should only be initialized once. 313839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o scoped_ptr<content::DropData> dropData_; 323839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o 333839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o // The image to show as drag image. Can be nil. 343839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o base::scoped_nsobject<NSImage> dragImage_; 353839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o 363839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o // The offset to draw |dragImage_| at. 373839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o NSPoint imageOffset_; 383839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o 393839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o // Our pasteboard. 403839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o base::scoped_nsobject<NSPasteboard> pasteboard_; 413839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o 423839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o // A mask of the allowed drag operations. 433839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o NSDragOperation dragOperationMask_; 443839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o 453839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o // The file name to be saved to for a drag-out download. 463839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o base::FilePath downloadFileName_; 473839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o 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// Drag moved; hook up to -draggedImage:movedTo:. 87- (void)moveDragTo:(NSPoint)screenPoint; 88 89@end 90