OLD | NEW |
---|---|
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_BASE_DROP_TARGET_H__ | 5 #ifndef BASE_BASE_DROP_TARGET_H_ |
6 #define BASE_BASE_DROP_TARGET_H__ | 6 #define BASE_BASE_DROP_TARGET_H_ |
7 | 7 |
8 #include <atlbase.h> | |
9 #include <objidl.h> | 8 #include <objidl.h> |
10 #include <shobjidl.h> | |
11 | 9 |
12 #include "base/basictypes.h" | 10 #include "base/ref_counted.h" |
11 | |
12 struct IDropTargetHelper; | |
13 | 13 |
14 // A DropTarget implementation that takes care of the nitty gritty | 14 // A DropTarget implementation that takes care of the nitty gritty |
15 // of dnd. While this class is concrete, subclasses will most likely | 15 // of dnd. While this class is concrete, subclasses will most likely |
16 // want to override various OnXXX methods. | 16 // want to override various OnXXX methods. |
17 // | 17 // |
18 // Because BaseDropTarget is ref counted you shouldn't delete it directly, | 18 // Because BaseDropTarget is ref counted you shouldn't delete it directly, |
19 // rather wrap it in a scoped_refptr. Be sure and invoke RevokeDragDrop(m_hWnd) | 19 // rather wrap it in a scoped_refptr. Be sure and invoke RevokeDragDrop(m_hWnd) |
20 // before the HWND is deleted too. | 20 // before the HWND is deleted too. |
21 // | |
22 // This class is meant to be used in a STA and is not multithread-safe. | |
Dean McNamee
2008/09/30 20:47:26
an STA, I think
| |
21 class BaseDropTarget : public IDropTarget { | 23 class BaseDropTarget : public IDropTarget { |
22 public: | 24 public: |
23 // Create a new BaseDropTarget associating it with the given HWND. | 25 // Create a new BaseDropTarget associating it with the given HWND. |
24 explicit BaseDropTarget(HWND hwnd); | 26 explicit BaseDropTarget(HWND hwnd); |
25 virtual ~BaseDropTarget(); | 27 virtual ~BaseDropTarget(); |
26 | 28 |
27 // When suspend is set to |true|, the drop target does not receive drops from | 29 // When suspend is set to |true|, the drop target does not receive drops from |
28 // drags initiated within the owning HWND. | 30 // drags initiated within the owning HWND. |
29 // TODO(beng): (http://b/1085385) figure out how we will handle legitimate | 31 // TODO(beng): (http://b/1085385) figure out how we will handle legitimate |
30 // drag-drop operations within the same HWND, such as dragging | 32 // drag-drop operations within the same HWND, such as dragging |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 DWORD key_state, | 84 DWORD key_state, |
83 POINT cursor_position, | 85 POINT cursor_position, |
84 DWORD effect); | 86 DWORD effect); |
85 | 87 |
86 private: | 88 private: |
87 // Returns the cached drop helper, creating one if necessary. The returned | 89 // Returns the cached drop helper, creating one if necessary. The returned |
88 // object is not addrefed. May return NULL if the object couldn't be created. | 90 // object is not addrefed. May return NULL if the object couldn't be created. |
89 static IDropTargetHelper* DropHelper(); | 91 static IDropTargetHelper* DropHelper(); |
90 | 92 |
91 // The data object currently being dragged over this drop target. | 93 // The data object currently being dragged over this drop target. |
92 CComPtr<IDataObject> current_data_object_; | 94 scoped_refptr<IDataObject> current_data_object_; |
93 | 95 |
94 // A helper object that is used to provide drag image support while the mouse | 96 // A helper object that is used to provide drag image support while the mouse |
95 // is dragging over the content area. | 97 // is dragging over the content area. |
96 // | 98 // |
97 // DO NOT ACCESS DIRECTLY! Use DropHelper() instead, which will lazily create | 99 // DO NOT ACCESS DIRECTLY! Use DropHelper() instead, which will lazily create |
98 // this if it doesn't exist yet. This object can take tens of milliseconds to | 100 // this if it doesn't exist yet. This object can take tens of milliseconds to |
99 // create, and we don't want to block any window opening for this, especially | 101 // create, and we don't want to block any window opening for this, especially |
100 // since often, DnD will never be used. Instead, we force this penalty to the | 102 // since often, DnD will never be used. Instead, we force this penalty to the |
101 // first time it is actually used. | 103 // first time it is actually used. |
102 static IDropTargetHelper* cached_drop_target_helper_; | 104 static IDropTargetHelper* cached_drop_target_helper_; |
103 | 105 |
104 // The HWND of the source. This HWND is used to determine coordinates for | 106 // The HWND of the source. This HWND is used to determine coordinates for |
105 // mouse events that are sent to the renderer notifying various drag states. | 107 // mouse events that are sent to the renderer notifying various drag states. |
106 HWND hwnd_; | 108 HWND hwnd_; |
107 | 109 |
108 // Whether or not we are currently processing drag notifications for drags | 110 // Whether or not we are currently processing drag notifications for drags |
109 // initiated in this window. | 111 // initiated in this window. |
110 bool suspend_; | 112 bool suspend_; |
111 | 113 |
112 LONG ref_count_; | 114 LONG ref_count_; |
113 | 115 |
114 DISALLOW_EVIL_CONSTRUCTORS(BaseDropTarget); | 116 DISALLOW_EVIL_CONSTRUCTORS(BaseDropTarget); |
115 }; | 117 }; |
116 | 118 |
117 #endif // BASE_BASE_DROP_TARGET_H__ | 119 #endif // BASE_BASE_DROP_TARGET_H_ |
118 | |
OLD | NEW |