Home | History | Annotate | Download | only in tab_contents
      1 // Copyright (c) 2011 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 
     12 @class TabContentsViewCocoa;
     13 struct WebDropData;
     14 
     15 // A class that handles tracking and event processing for a drag and drop
     16 // originating from the content area.
     17 @interface WebDragSource : NSObject {
     18  @private
     19   // Our tab. Weak reference (owns or co-owns us).
     20   TabContentsViewCocoa* contentsView_;
     21 
     22   // Our drop data. Should only be initialized once.
     23   scoped_ptr<WebDropData> dropData_;
     24 
     25   // The image to show as drag image. Can be nil.
     26   scoped_nsobject<NSImage> dragImage_;
     27 
     28   // The offset to draw |dragImage_| at.
     29   NSPoint imageOffset_;
     30 
     31   // Our pasteboard.
     32   scoped_nsobject<NSPasteboard> pasteboard_;
     33 
     34   // A mask of the allowed drag operations.
     35   NSDragOperation dragOperationMask_;
     36 
     37   // The file name to be saved to for a drag-out download.
     38   FilePath downloadFileName_;
     39 
     40   // The URL to download from for a drag-out download.
     41   GURL downloadURL_;
     42 }
     43 
     44 // Initialize a WebDragSource object for a drag (originating on the given
     45 // contentsView and with the given dropData and pboard). Fill the pasteboard
     46 // with data types appropriate for dropData.
     47 - (id)initWithContentsView:(TabContentsViewCocoa*)contentsView
     48                   dropData:(const WebDropData*)dropData
     49                      image:(NSImage*)image
     50                     offset:(NSPoint)offset
     51                 pasteboard:(NSPasteboard*)pboard
     52          dragOperationMask:(NSDragOperation)dragOperationMask;
     53 
     54 // Returns a mask of the allowed drag operations.
     55 - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal;
     56 
     57 // Call when asked to do a lazy write to the pasteboard; hook up to
     58 // -pasteboard:provideDataForType: (on the contentsView).
     59 - (void)lazyWriteToPasteboard:(NSPasteboard*)pboard
     60                       forType:(NSString*)type;
     61 
     62 // Start the drag (on the originally provided contentsView); can do this right
     63 // after -initWithContentsView:....
     64 - (void)startDrag;
     65 
     66 // End the drag and clear the pasteboard; hook up to
     67 // -draggedImage:endedAt:operation:.
     68 - (void)endDragAt:(NSPoint)screenPoint
     69         operation:(NSDragOperation)operation;
     70 
     71 // Drag moved; hook up to -draggedImage:movedTo:.
     72 - (void)moveDragTo:(NSPoint)screenPoint;
     73 
     74 // Call to drag a promised file to the given path (should be called before
     75 // -endDragAt:...); hook up to -namesOfPromisedFilesDroppedAtDestination:.
     76 // Returns the file name (not including path) of the file deposited (or which
     77 // will be deposited).
     78 - (NSString*)dragPromisedFileTo:(NSString*)path;
     79 
     80 @end
     81