Home | History | Annotate | Download | only in tab_contents
      1 // Copyright (c) 2009 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/string16.h"
      8 
      9 class GURL;
     10 class RenderViewHost;
     11 class TabContents;
     12 struct WebDropData;
     13 
     14 // A typedef for a RenderViewHost used for comparison purposes only.
     15 typedef RenderViewHost* RenderViewHostIdentifier;
     16 
     17 // A class that handles tracking and event processing for a drag and drop
     18 // over the content area. Assumes something else initiates the drag, this is
     19 // only for processing during a drag.
     20 
     21 @interface WebDropTarget : NSObject {
     22  @private
     23   // Our associated TabContents. Weak reference.
     24   TabContents* tabContents_;
     25 
     26   // Updated asynchronously during a drag to tell us whether or not we should
     27   // allow the drop.
     28   NSDragOperation current_operation_;
     29 
     30   // Keep track of the render view host we're dragging over.  If it changes
     31   // during a drag, we need to re-send the DragEnter message.
     32   RenderViewHostIdentifier currentRVH_;
     33 }
     34 
     35 // |contents| is the TabContents representing this tab, used to communicate
     36 // drag&drop messages to WebCore and handle navigation on a successful drop
     37 // (if necessary).
     38 - (id)initWithTabContents:(TabContents*)contents;
     39 
     40 // Sets the current operation negotiated by the source and destination,
     41 // which determines whether or not we should allow the drop. Takes effect the
     42 // next time |-draggingUpdated:| is called.
     43 - (void)setCurrentOperation: (NSDragOperation)operation;
     44 
     45 // Messages to send during the tracking of a drag, ususally upon receiving
     46 // calls from the view system. Communicates the drag messages to WebCore.
     47 - (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)info
     48                               view:(NSView*)view;
     49 - (void)draggingExited:(id<NSDraggingInfo>)info;
     50 - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)info
     51                               view:(NSView*)view;
     52 - (BOOL)performDragOperation:(id<NSDraggingInfo>)info
     53                               view:(NSView*)view;
     54 
     55 @end
     56 
     57 // Public use only for unit tests.
     58 @interface WebDropTarget(Testing)
     59 // Populate the |url| and |title| with URL data in |pboard|. There may be more
     60 // than one, but we only handle dropping the first. |url| must not be |NULL|;
     61 // |title| is an optional parameter. Returns |YES| if URL data was obtained from
     62 // the pasteboard, |NO| otherwise. If |convertFilenames| is |YES|, the function
     63 // will also attempt to convert filenames in |pboard| to file URLs.
     64 - (BOOL)populateURL:(GURL*)url
     65     andTitle:(string16*)title
     66     fromPasteboard:(NSPasteboard*)pboard
     67     convertingFilenames:(BOOL)convertFilenames;
     68 // Given |data|, which should not be nil, fill it in using the contents of the
     69 // given pasteboard.
     70 - (void)populateWebDropData:(WebDropData*)data
     71              fromPasteboard:(NSPasteboard*)pboard;
     72 // Given a point in window coordinates and a view in that window, return a
     73 // flipped point in the coordinate system of |view|.
     74 - (NSPoint)flipWindowPointToView:(const NSPoint&)windowPoint
     75                             view:(NSView*)view;
     76 // Given a point in window coordinates and a view in that window, return a
     77 // flipped point in screen coordinates.
     78 - (NSPoint)flipWindowPointToScreen:(const NSPoint&)windowPoint
     79                               view:(NSView*)view;
     80 @end
     81