Home | History | Annotate | Download | only in cocoa
      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 #ifndef CHROME_BROWSER_UI_COCOA_URL_DROP_TARGET_H_
      6 #define CHROME_BROWSER_UI_COCOA_URL_DROP_TARGET_H_
      7 
      8 #import <Cocoa/Cocoa.h>
      9 
     10 @protocol URLDropTarget;
     11 @protocol URLDropTargetController;
     12 
     13 // Object which coordinates the dropping of URLs on a given view, sending data
     14 // and updates to a controller.
     15 @interface URLDropTargetHandler : NSObject {
     16  @private
     17   NSView<URLDropTarget>* view_;  // weak
     18 }
     19 
     20 // Returns an array of drag types that can be handled.
     21 + (NSArray*)handledDragTypes;
     22 
     23 // Initialize the given view, which must implement the |URLDropTarget| (below),
     24 // to accept drops of URLs.
     25 - (id)initWithView:(NSView<URLDropTarget>*)view;
     26 
     27 // The owner view should implement the following methods by calling the
     28 // |URLDropTargetHandler|'s version, and leave the others to the default
     29 // implementation provided by |NSView|/|NSWindow|.
     30 - (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender;
     31 - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender;
     32 - (void)draggingExited:(id<NSDraggingInfo>)sender;
     33 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender;
     34 
     35 @end  // @interface URLDropTargetHandler
     36 
     37 // Protocol which views that are URL drop targets and use |URLDropTargetHandler|
     38 // must implement.
     39 @protocol URLDropTarget
     40 
     41 // Returns the controller which handles the drop.
     42 - (id<URLDropTargetController>)urlDropController;
     43 
     44 // The following, which come from |NSDraggingDestination|, must be implemented
     45 // by calling the |URLDropTargetHandler|'s implementations.
     46 - (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender;
     47 - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender;
     48 - (void)draggingExited:(id<NSDraggingInfo>)sender;
     49 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender;
     50 
     51 @end  // @protocol URLDropTarget
     52 
     53 // Protocol for the controller which handles the actual drop data/drop updates.
     54 @protocol URLDropTargetController
     55 
     56 // Determines whether the given drag and drop operation contains content that
     57 // is supported by the web view. In particular, if the content is a local file
     58 // URL, this checks if it is of a type that can be shown in the tab contents.
     59 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info;
     60 
     61 // The given URLs (an |NSArray| of |NSString|s) were dropped in the given view
     62 // at the given point (in that view's coordinates).
     63 - (void)dropURLs:(NSArray*)urls inView:(NSView*)view at:(NSPoint)point;
     64 
     65 // The given text was dropped in the given view at the given point (in that
     66 // view's coordinates).
     67 - (void)dropText:(NSString*)text inView:(NSView*)view at:(NSPoint)point;
     68 
     69 // Dragging is in progress over the owner view (at the given point, in view
     70 // coordinates) and any indicator of location -- e.g., an arrow -- should be
     71 // updated/shown.
     72 - (void)indicateDropURLsInView:(NSView*)view at:(NSPoint)point;
     73 
     74 // Dragging is over, and any indicator should be hidden.
     75 - (void)hideDropURLsIndicatorInView:(NSView*)view;
     76 
     77 @end  // @protocol URLDropTargetController
     78 
     79 #endif  // CHROME_BROWSER_UI_COCOA_URL_DROP_TARGET_H_
     80