web_drag_dest_mac.h revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
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/memory/scoped_ptr.h"
8#include "base/string16.h"
9#include "content/common/content_export.h"
10#include "webkit/glue/webdropdata.h"
11
12
13namespace content {
14class RenderViewHost;
15class WebContentsImpl;
16class WebDragDestDelegate;
17}
18
19// A typedef for a RenderViewHost used for comparison purposes only.
20typedef content::RenderViewHost* RenderViewHostIdentifier;
21
22// A class that handles tracking and event processing for a drag and drop
23// over the content area. Assumes something else initiates the drag, this is
24// only for processing during a drag.
25CONTENT_EXPORT
26@interface WebDragDest : NSObject {
27 @private
28  // Our associated WebContentsImpl. Weak reference.
29  content::WebContentsImpl* webContents_;
30
31  // Delegate; weak.
32  content::WebDragDestDelegate* delegate_;
33
34  // Updated asynchronously during a drag to tell us whether or not we should
35  // allow the drop.
36  NSDragOperation currentOperation_;
37
38  // Keep track of the render view host we're dragging over.  If it changes
39  // during a drag, we need to re-send the DragEnter message.
40  RenderViewHostIdentifier currentRVH_;
41
42  // The data for the current drag, or NULL if none is in progress.
43  scoped_ptr<WebDropData> dropData_;
44}
45
46// |contents| is the WebContentsImpl representing this tab, used to communicate
47// drag&drop messages to WebCore and handle navigation on a successful drop
48// (if necessary).
49- (id)initWithWebContentsImpl:(content::WebContentsImpl*)contents;
50
51- (WebDropData*)currentDropData;
52
53- (void)setDragDelegate:(content::WebDragDestDelegate*)delegate;
54
55// Sets the current operation negotiated by the source and destination,
56// which determines whether or not we should allow the drop. Takes effect the
57// next time |-draggingUpdated:| is called.
58- (void)setCurrentOperation:(NSDragOperation)operation;
59
60// Messages to send during the tracking of a drag, ususally upon receiving
61// calls from the view system. Communicates the drag messages to WebCore.
62- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)info
63                              view:(NSView*)view;
64- (void)draggingExited:(id<NSDraggingInfo>)info;
65- (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)info
66                              view:(NSView*)view;
67- (BOOL)performDragOperation:(id<NSDraggingInfo>)info
68                              view:(NSView*)view;
69
70@end
71
72// Public use only for unit tests.
73@interface WebDragDest(Testing)
74// Given |data|, which should not be nil, fill it in using the contents of the
75// given pasteboard.
76- (void)populateWebDropData:(WebDropData*)data
77             fromPasteboard:(NSPasteboard*)pboard;
78// Given a point in window coordinates and a view in that window, return a
79// flipped point in the coordinate system of |view|.
80- (NSPoint)flipWindowPointToView:(const NSPoint&)windowPoint
81                            view:(NSView*)view;
82// Given a point in window coordinates and a view in that window, return a
83// flipped point in screen coordinates.
84- (NSPoint)flipWindowPointToScreen:(const NSPoint&)windowPoint
85                              view:(NSView*)view;
86@end
87