OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2006-2008 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 VIEWS_WIDGET_DROP_HELPER_H_ |
| 6 #define VIEWS_WIDGET_DROP_HELPER_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "base/basictypes.h" |
| 10 |
| 11 namespace gfx { |
| 12 class Point; |
| 13 } // namespace gfx |
| 14 |
| 15 namespace ui { |
| 16 class OSExchangeData; |
| 17 } // namespace ui |
| 18 using ui::OSExchangeData; |
| 19 |
| 20 namespace views { |
| 21 |
| 22 class RootView; |
| 23 class View; |
| 24 |
| 25 // DropHelper provides support for managing the view a drop is going to occur |
| 26 // at during dnd as well as sending the view the appropriate dnd methods. |
| 27 // DropHelper is intended to be used by a class that interacts with the system |
| 28 // drag and drop. The system class invokes OnDragOver as the mouse moves, |
| 29 // then either OnDragExit or OnDrop when the drop is done. |
| 30 class DropHelper { |
| 31 public: |
| 32 explicit DropHelper(View* root_view); |
| 33 ~DropHelper(); |
| 34 |
| 35 // Current view drop events are targeted at, may be NULL. |
| 36 View* target_view() const { return target_view_; } |
| 37 |
| 38 // Returns the RootView the DropHelper was created with. |
| 39 View* root_view() const { return root_view_; } |
| 40 |
| 41 // Resets the target_view_ to NULL if it equals view. |
| 42 // |
| 43 // This is invoked when a View is removed from the RootView to make sure |
| 44 // we don't target a view that was removed during dnd. |
| 45 void ResetTargetViewIfEquals(View* view); |
| 46 |
| 47 // Invoked when a the mouse is dragged over the root view during a drag and |
| 48 // drop operation. This method returns a bitmask of the types in DragDropTypes |
| 49 // for the target view. If no view wants the drop, DRAG_NONE is returned. |
| 50 int OnDragOver(const OSExchangeData& data, |
| 51 const gfx::Point& root_view_location, |
| 52 int drag_operation); |
| 53 |
| 54 // Invoked when a the mouse is dragged out of the root view during a drag and |
| 55 // drop operation. |
| 56 void OnDragExit(); |
| 57 |
| 58 // Invoked when the user drops data on the root view during a drag and drop |
| 59 // operation. See OnDragOver for details on return type. |
| 60 // |
| 61 // NOTE: implementations must invoke OnDragOver before invoking this, |
| 62 // supplying the return value from OnDragOver as the drag_operation. |
| 63 int OnDrop(const OSExchangeData& data, |
| 64 const gfx::Point& root_view_location, |
| 65 int drag_operation); |
| 66 |
| 67 // Calculates the target view for a drop given the specified location in |
| 68 // the coordinate system of the rootview. This tries to avoid continually |
| 69 // querying CanDrop by returning target_view_ if the mouse is still over |
| 70 // target_view_. |
| 71 View* CalculateTargetView(const gfx::Point& root_view_location, |
| 72 const OSExchangeData& data, |
| 73 bool check_can_drop); |
| 74 |
| 75 private: |
| 76 // Implementation of CalculateTargetView. If |deepest_view| is non-NULL it is |
| 77 // set to the deepest descendant of the RootView that contains the point |
| 78 // |root_view_location| |
| 79 View* CalculateTargetViewImpl(const gfx::Point& root_view_location, |
| 80 const OSExchangeData& data, |
| 81 bool check_can_drop, |
| 82 View** deepest_view); |
| 83 |
| 84 // Methods to send the appropriate drop notification to the targeted view. |
| 85 // These do nothing if the target view is NULL. |
| 86 void NotifyDragEntered(const OSExchangeData& data, |
| 87 const gfx::Point& root_view_location, |
| 88 int drag_operation); |
| 89 int NotifyDragOver(const OSExchangeData& data, |
| 90 const gfx::Point& root_view_location, |
| 91 int drag_operation); |
| 92 void NotifyDragExit(); |
| 93 |
| 94 // RootView we were created for. |
| 95 View* root_view_; |
| 96 |
| 97 // View we're targeting events at. |
| 98 View* target_view_; |
| 99 |
| 100 // The deepest view under the current drop coordinate. |
| 101 View* deepest_view_; |
| 102 |
| 103 DISALLOW_COPY_AND_ASSIGN(DropHelper); |
| 104 }; |
| 105 |
| 106 } // namespace views |
| 107 |
| 108 #endif // VIEWS_WIDGET_DROP_HELPER_H_ |
OLD | NEW |