| OLD | NEW |
| (Empty) |
| 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 UI_VIEWS_WIDGET_DROP_HELPER_H_ | |
| 6 #define UI_VIEWS_WIDGET_DROP_HELPER_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 | |
| 10 namespace gfx { | |
| 11 class Point; | |
| 12 } // namespace gfx | |
| 13 | |
| 14 namespace ui { | |
| 15 class OSExchangeData; | |
| 16 } // namespace ui | |
| 17 using ui::OSExchangeData; | |
| 18 | |
| 19 namespace views { | |
| 20 | |
| 21 class RootView; | |
| 22 class View; | |
| 23 | |
| 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. | |
| 29 class DropHelper { | |
| 30 public: | |
| 31 explicit DropHelper(View* root_view); | |
| 32 ~DropHelper(); | |
| 33 | |
| 34 // Current view drop events are targeted at, may be NULL. | |
| 35 View* target_view() const { return target_view_; } | |
| 36 | |
| 37 // Returns the RootView the DropHelper was created with. | |
| 38 View* root_view() const { return root_view_; } | |
| 39 | |
| 40 // Resets the target_view_ to NULL if it equals view. | |
| 41 // | |
| 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); | |
| 45 | |
| 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, | |
| 51 int drag_operation); | |
| 52 | |
| 53 // Invoked when a the mouse is dragged out of the root view during a drag and | |
| 54 // drop operation. | |
| 55 void OnDragExit(); | |
| 56 | |
| 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. | |
| 59 // | |
| 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, | |
| 64 int drag_operation); | |
| 65 | |
| 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 | |
| 69 // target_view_. | |
| 70 View* CalculateTargetView(const gfx::Point& root_view_location, | |
| 71 const OSExchangeData& data, | |
| 72 bool check_can_drop); | |
| 73 | |
| 74 private: | |
| 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, | |
| 80 bool check_can_drop, | |
| 81 View** deepest_view); | |
| 82 | |
| 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, | |
| 87 int drag_operation); | |
| 88 int NotifyDragOver(const OSExchangeData& data, | |
| 89 const gfx::Point& root_view_location, | |
| 90 int drag_operation); | |
| 91 void NotifyDragExit(); | |
| 92 | |
| 93 // RootView we were created for. | |
| 94 View* root_view_; | |
| 95 | |
| 96 // View we're targeting events at. | |
| 97 View* target_view_; | |
| 98 | |
| 99 // The deepest view under the current drop coordinate. | |
| 100 View* deepest_view_; | |
| 101 | |
| 102 DISALLOW_COPY_AND_ASSIGN(DropHelper); | |
| 103 }; | |
| 104 | |
| 105 } // namespace views | |
| 106 | |
| 107 #endif // UI_VIEWS_WIDGET_DROP_HELPER_H_ | |
| OLD | NEW |