[email protected] | 02bae0f | 2011-01-19 20:22:00 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 4 | |
[email protected] | 02bae0f | 2011-01-19 20:22:00 | [diff] [blame] | 5 | #ifndef UI_BASE_DRAGDROP_DROP_TARGET_H_ |
| 6 | #define UI_BASE_DRAGDROP_DROP_TARGET_H_ |
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 8 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 9 | #include <objidl.h> |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 10 | |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 11 | #include "base/memory/ref_counted.h" |
[email protected] | ea47b6a | 2011-07-17 19:39:42 | [diff] [blame^] | 12 | #include "ui/ui_api.h" |
[email protected] | c7f4b627 | 2008-09-30 20:50:51 | [diff] [blame] | 13 | |
[email protected] | 79a4c1e | 2010-10-17 20:44:38 | [diff] [blame] | 14 | // Windows interface. |
[email protected] | c7f4b627 | 2008-09-30 20:50:51 | [diff] [blame] | 15 | struct IDropTargetHelper; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 16 | |
[email protected] | 02bae0f | 2011-01-19 20:22:00 | [diff] [blame] | 17 | namespace ui { |
[email protected] | 79a4c1e | 2010-10-17 20:44:38 | [diff] [blame] | 18 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 19 | // A DropTarget implementation that takes care of the nitty gritty |
| 20 | // of dnd. While this class is concrete, subclasses will most likely |
| 21 | // want to override various OnXXX methods. |
| 22 | // |
[email protected] | 79a4c1e | 2010-10-17 20:44:38 | [diff] [blame] | 23 | // Because DropTarget is ref counted you shouldn't delete it directly, |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 24 | // rather wrap it in a scoped_refptr. Be sure and invoke RevokeDragDrop(m_hWnd) |
| 25 | // before the HWND is deleted too. |
[email protected] | c7f4b627 | 2008-09-30 20:50:51 | [diff] [blame] | 26 | // |
| 27 | // This class is meant to be used in a STA and is not multithread-safe. |
[email protected] | ea47b6a | 2011-07-17 19:39:42 | [diff] [blame^] | 28 | class UI_API DropTarget : public IDropTarget { |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 29 | public: |
[email protected] | 79a4c1e | 2010-10-17 20:44:38 | [diff] [blame] | 30 | // Create a new DropTarget associating it with the given HWND. |
| 31 | explicit DropTarget(HWND hwnd); |
| 32 | virtual ~DropTarget(); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 33 | |
[email protected] | 6aa4a1c0 | 2010-01-15 18:49:58 | [diff] [blame] | 34 | // When suspended is set to |true|, the drop target does not receive drops |
| 35 | // from drags initiated within the owning HWND. |
[email protected] | 6aa4a1c0 | 2010-01-15 18:49:58 | [diff] [blame] | 36 | bool suspended() const { return suspended_; } |
| 37 | void set_suspended(bool suspended) { suspended_ = suspended; } |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 38 | |
| 39 | // IDropTarget implementation: |
| 40 | HRESULT __stdcall DragEnter(IDataObject* data_object, |
| 41 | DWORD key_state, |
| 42 | POINTL cursor_position, |
| 43 | DWORD* effect); |
| 44 | HRESULT __stdcall DragOver(DWORD key_state, |
| 45 | POINTL cursor_position, |
| 46 | DWORD* effect); |
| 47 | HRESULT __stdcall DragLeave(); |
| 48 | HRESULT __stdcall Drop(IDataObject* data_object, |
| 49 | DWORD key_state, |
| 50 | POINTL cursor_position, |
| 51 | DWORD* effect); |
| 52 | |
| 53 | // IUnknown implementation: |
| 54 | HRESULT __stdcall QueryInterface(const IID& iid, void** object); |
| 55 | ULONG __stdcall AddRef(); |
| 56 | ULONG __stdcall Release(); |
| 57 | |
| 58 | protected: |
| 59 | // Returns the hosting HWND. |
| 60 | HWND GetHWND() { return hwnd_; } |
| 61 | |
| 62 | // Invoked when the cursor first moves over the hwnd during a dnd session. |
| 63 | // This should return a bitmask of the supported drop operations: |
| 64 | // DROPEFFECT_NONE, DROPEFFECT_COPY, DROPEFFECT_LINK and/or |
| 65 | // DROPEFFECT_MOVE. |
| 66 | virtual DWORD OnDragEnter(IDataObject* data_object, |
| 67 | DWORD key_state, |
| 68 | POINT cursor_position, |
| 69 | DWORD effect); |
| 70 | |
| 71 | // Invoked when the cursor moves over the window during a dnd session. |
| 72 | // This should return a bitmask of the supported drop operations: |
| 73 | // DROPEFFECT_NONE, DROPEFFECT_COPY, DROPEFFECT_LINK and/or |
| 74 | // DROPEFFECT_MOVE. |
| 75 | virtual DWORD OnDragOver(IDataObject* data_object, |
| 76 | DWORD key_state, |
| 77 | POINT cursor_position, |
| 78 | DWORD effect); |
| 79 | |
| 80 | // Invoked when the cursor moves outside the bounds of the hwnd during a |
| 81 | // dnd session. |
| 82 | virtual void OnDragLeave(IDataObject* data_object); |
| 83 | |
| 84 | // Invoked when the drop ends on the window. This should return the operation |
| 85 | // that was taken. |
| 86 | virtual DWORD OnDrop(IDataObject* data_object, |
| 87 | DWORD key_state, |
| 88 | POINT cursor_position, |
| 89 | DWORD effect); |
| 90 | |
| 91 | private: |
| 92 | // Returns the cached drop helper, creating one if necessary. The returned |
| 93 | // object is not addrefed. May return NULL if the object couldn't be created. |
| 94 | static IDropTargetHelper* DropHelper(); |
| 95 | |
| 96 | // The data object currently being dragged over this drop target. |
[email protected] | c7f4b627 | 2008-09-30 20:50:51 | [diff] [blame] | 97 | scoped_refptr<IDataObject> current_data_object_; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 98 | |
| 99 | // A helper object that is used to provide drag image support while the mouse |
| 100 | // is dragging over the content area. |
| 101 | // |
| 102 | // DO NOT ACCESS DIRECTLY! Use DropHelper() instead, which will lazily create |
| 103 | // this if it doesn't exist yet. This object can take tens of milliseconds to |
| 104 | // create, and we don't want to block any window opening for this, especially |
| 105 | // since often, DnD will never be used. Instead, we force this penalty to the |
| 106 | // first time it is actually used. |
| 107 | static IDropTargetHelper* cached_drop_target_helper_; |
| 108 | |
| 109 | // The HWND of the source. This HWND is used to determine coordinates for |
| 110 | // mouse events that are sent to the renderer notifying various drag states. |
| 111 | HWND hwnd_; |
| 112 | |
| 113 | // Whether or not we are currently processing drag notifications for drags |
| 114 | // initiated in this window. |
[email protected] | 6aa4a1c0 | 2010-01-15 18:49:58 | [diff] [blame] | 115 | bool suspended_; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 116 | |
| 117 | LONG ref_count_; |
| 118 | |
[email protected] | 79a4c1e | 2010-10-17 20:44:38 | [diff] [blame] | 119 | DISALLOW_COPY_AND_ASSIGN(DropTarget); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 120 | }; |
| 121 | |
[email protected] | 02bae0f | 2011-01-19 20:22:00 | [diff] [blame] | 122 | } // namespace ui |
[email protected] | 79a4c1e | 2010-10-17 20:44:38 | [diff] [blame] | 123 | |
[email protected] | 02bae0f | 2011-01-19 20:22:00 | [diff] [blame] | 124 | #endif // UI_BASE_DRAGDROP_DROP_TARGET_H_ |