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_BASE_DRAGDROP_DROP_TARGET_WIN_H_
6 #define UI_BASE_DRAGDROP_DROP_TARGET_WIN_H_
10 #include "base/memory/ref_counted.h"
11 #include "ui/base/ui_base_export.h"
14 struct IDropTargetHelper
;
18 // A DropTarget implementation that takes care of the nitty gritty
19 // of dnd. While this class is concrete, subclasses will most likely
20 // want to override various OnXXX methods.
22 // Because DropTarget is ref counted you shouldn't delete it directly,
23 // rather wrap it in a scoped_refptr. Be sure and invoke RevokeDragDrop(m_hWnd)
24 // before the HWND is deleted too.
26 // This class is meant to be used in a STA and is not multithread-safe.
27 class UI_BASE_EXPORT DropTargetWin
: public IDropTarget
{
29 // Create a new DropTarget associating it with the given HWND.
30 explicit DropTargetWin(HWND hwnd
);
31 virtual ~DropTargetWin();
33 // IDropTarget implementation:
34 HRESULT __stdcall
DragEnter(IDataObject
* data_object
,
36 POINTL cursor_position
,
38 HRESULT __stdcall
DragOver(DWORD key_state
,
39 POINTL cursor_position
,
41 HRESULT __stdcall
DragLeave();
42 HRESULT __stdcall
Drop(IDataObject
* data_object
,
44 POINTL cursor_position
,
47 // IUnknown implementation:
48 HRESULT __stdcall
QueryInterface(const IID
& iid
, void** object
);
49 ULONG __stdcall
AddRef();
50 ULONG __stdcall
Release();
53 // Returns the hosting HWND.
54 HWND
GetHWND() { return hwnd_
; }
56 // Invoked when the cursor first moves over the hwnd during a dnd session.
57 // This should return a bitmask of the supported drop operations:
58 // DROPEFFECT_NONE, DROPEFFECT_COPY, DROPEFFECT_LINK and/or
60 virtual DWORD
OnDragEnter(IDataObject
* data_object
,
62 POINT cursor_position
,
65 // Invoked when the cursor moves over the window during a dnd session.
66 // This should return a bitmask of the supported drop operations:
67 // DROPEFFECT_NONE, DROPEFFECT_COPY, DROPEFFECT_LINK and/or
69 virtual DWORD
OnDragOver(IDataObject
* data_object
,
71 POINT cursor_position
,
74 // Invoked when the cursor moves outside the bounds of the hwnd during a
76 virtual void OnDragLeave(IDataObject
* data_object
);
78 // Invoked when the drop ends on the window. This should return the operation
80 virtual DWORD
OnDrop(IDataObject
* data_object
,
82 POINT cursor_position
,
86 // Returns the cached drop helper, creating one if necessary. The returned
87 // object is not addrefed. May return NULL if the object couldn't be created.
88 static IDropTargetHelper
* DropHelper();
90 // The data object currently being dragged over this drop target.
91 scoped_refptr
<IDataObject
> current_data_object_
;
93 // A helper object that is used to provide drag image support while the mouse
94 // is dragging over the content area.
96 // DO NOT ACCESS DIRECTLY! Use DropHelper() instead, which will lazily create
97 // this if it doesn't exist yet. This object can take tens of milliseconds to
98 // create, and we don't want to block any window opening for this, especially
99 // since often, DnD will never be used. Instead, we force this penalty to the
100 // first time it is actually used.
101 static IDropTargetHelper
* cached_drop_target_helper_
;
103 // The HWND of the source. This HWND is used to determine coordinates for
104 // mouse events that are sent to the renderer notifying various drag states.
109 DISALLOW_COPY_AND_ASSIGN(DropTargetWin
);
114 #endif // UI_BASE_DRAGDROP_DROP_TARGET_WIN_H_