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.
5 #ifndef UI_VIEWS_WIDGET_DROP_HELPER_H_
6 #define UI_VIEWS_WIDGET_DROP_HELPER_H_
8 #include "base/basictypes.h"
17 using ui::OSExchangeData
;
24 // DropHelper provides support for managing the view a drop is going to occur
25 // at during dnd as well as sending the view the appropriate dnd methods.
26 // DropHelper is intended to be used by a class that interacts with the system
27 // drag and drop. The system class invokes OnDragOver as the mouse moves,
28 // then either OnDragExit or OnDrop when the drop is done.
31 explicit DropHelper(View
* root_view
);
34 // Current view drop events are targeted at, may be NULL.
35 View
* target_view() const { return target_view_
; }
37 // Returns the RootView the DropHelper was created with.
38 View
* root_view() const { return root_view_
; }
40 // Resets the target_view_ to NULL if it equals view.
42 // This is invoked when a View is removed from the RootView to make sure
43 // we don't target a view that was removed during dnd.
44 void ResetTargetViewIfEquals(View
* view
);
46 // Invoked when a the mouse is dragged over the root view during a drag and
47 // drop operation. This method returns a bitmask of the types in DragDropTypes
48 // for the target view. If no view wants the drop, DRAG_NONE is returned.
49 int OnDragOver(const OSExchangeData
& data
,
50 const gfx::Point
& root_view_location
,
53 // Invoked when a the mouse is dragged out of the root view during a drag and
57 // Invoked when the user drops data on the root view during a drag and drop
58 // operation. See OnDragOver for details on return type.
60 // NOTE: implementations must invoke OnDragOver before invoking this,
61 // supplying the return value from OnDragOver as the drag_operation.
62 int OnDrop(const OSExchangeData
& data
,
63 const gfx::Point
& root_view_location
,
66 // Calculates the target view for a drop given the specified location in
67 // the coordinate system of the rootview. This tries to avoid continually
68 // querying CanDrop by returning target_view_ if the mouse is still over
70 View
* CalculateTargetView(const gfx::Point
& root_view_location
,
71 const OSExchangeData
& data
,
75 // Implementation of CalculateTargetView. If |deepest_view| is non-NULL it is
76 // set to the deepest descendant of the RootView that contains the point
77 // |root_view_location|
78 View
* CalculateTargetViewImpl(const gfx::Point
& root_view_location
,
79 const OSExchangeData
& data
,
83 // Methods to send the appropriate drop notification to the targeted view.
84 // These do nothing if the target view is NULL.
85 void NotifyDragEntered(const OSExchangeData
& data
,
86 const gfx::Point
& root_view_location
,
88 int NotifyDragOver(const OSExchangeData
& data
,
89 const gfx::Point
& root_view_location
,
91 void NotifyDragExit();
93 // RootView we were created for.
96 // View we're targeting events at.
99 // The deepest view under the current drop coordinate.
102 DISALLOW_COPY_AND_ASSIGN(DropHelper
);
107 #endif // UI_VIEWS_WIDGET_DROP_HELPER_H_