web_drag_dest_mac.h revision 7d4cd473f85ac64c3747c96c277f9e506a0d2246
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/strings/string16.h"
9#include "content/common/content_export.h"
10#include "webkit/common/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  // True if the drag has been canceled.
46  bool canceled_;
47}
48
49// |contents| is the WebContentsImpl representing this tab, used to communicate
50// drag&drop messages to WebCore and handle navigation on a successful drop
51// (if necessary).
52- (id)initWithWebContentsImpl:(content::WebContentsImpl*)contents;
53
54- (WebDropData*)currentDropData;
55
56- (void)setDragDelegate:(content::WebDragDestDelegate*)delegate;
57
58// Sets the current operation negotiated by the source and destination,
59// which determines whether or not we should allow the drop. Takes effect the
60// next time |-draggingUpdated:| is called.
61- (void)setCurrentOperation:(NSDragOperation)operation;
62
63// Messages to send during the tracking of a drag, ususally upon receiving
64// calls from the view system. Communicates the drag messages to WebCore.
65- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)info
66                              view:(NSView*)view;
67- (void)draggingExited:(id<NSDraggingInfo>)info;
68- (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)info
69                              view:(NSView*)view;
70- (BOOL)performDragOperation:(id<NSDraggingInfo>)info
71                              view:(NSView*)view;
72
73@end
74
75// Public use only for unit tests.
76@interface WebDragDest(Testing)
77// Given |data|, which should not be nil, fill it in using the contents of the
78// given pasteboard.
79- (void)populateWebDropData:(WebDropData*)data
80             fromPasteboard:(NSPasteboard*)pboard;
81// Given a point in window coordinates and a view in that window, return a
82// flipped point in the coordinate system of |view|.
83- (NSPoint)flipWindowPointToView:(const NSPoint&)windowPoint
84                            view:(NSView*)view;
85// Given a point in window coordinates and a view in that window, return a
86// flipped point in screen coordinates.
87- (NSPoint)flipWindowPointToScreen:(const NSPoint&)windowPoint
88                              view:(NSView*)view;
89@end
90