blob: de66ce28a1bf167a25f2283b4fd6a6445aaccf76 [file] [log] [blame]
[email protected]fc29bc702010-06-04 16:13:511// Copyright (c) 2010 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commitd7cae122008-07-26 21:49:384
[email protected]c7f4b6272008-09-30 20:50:515#ifndef BASE_BASE_DROP_TARGET_H_
6#define BASE_BASE_DROP_TARGET_H_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
initial.commitd7cae122008-07-26 21:49:388
initial.commitd7cae122008-07-26 21:49:389#include <objidl.h>
initial.commitd7cae122008-07-26 21:49:3810
[email protected]c7f4b6272008-09-30 20:50:5111#include "base/ref_counted.h"
12
13struct IDropTargetHelper;
initial.commitd7cae122008-07-26 21:49:3814
15// A DropTarget implementation that takes care of the nitty gritty
16// of dnd. While this class is concrete, subclasses will most likely
17// want to override various OnXXX methods.
18//
19// Because BaseDropTarget is ref counted you shouldn't delete it directly,
20// rather wrap it in a scoped_refptr. Be sure and invoke RevokeDragDrop(m_hWnd)
21// before the HWND is deleted too.
[email protected]c7f4b6272008-09-30 20:50:5122//
23// This class is meant to be used in a STA and is not multithread-safe.
initial.commitd7cae122008-07-26 21:49:3824class BaseDropTarget : public IDropTarget {
25 public:
26 // Create a new BaseDropTarget associating it with the given HWND.
27 explicit BaseDropTarget(HWND hwnd);
28 virtual ~BaseDropTarget();
29
[email protected]6aa4a1c02010-01-15 18:49:5830 // When suspended is set to |true|, the drop target does not receive drops
31 // from drags initiated within the owning HWND.
[email protected]6aa4a1c02010-01-15 18:49:5832 bool suspended() const { return suspended_; }
33 void set_suspended(bool suspended) { suspended_ = suspended; }
initial.commitd7cae122008-07-26 21:49:3834
35 // IDropTarget implementation:
36 HRESULT __stdcall DragEnter(IDataObject* data_object,
37 DWORD key_state,
38 POINTL cursor_position,
39 DWORD* effect);
40 HRESULT __stdcall DragOver(DWORD key_state,
41 POINTL cursor_position,
42 DWORD* effect);
43 HRESULT __stdcall DragLeave();
44 HRESULT __stdcall Drop(IDataObject* data_object,
45 DWORD key_state,
46 POINTL cursor_position,
47 DWORD* effect);
48
49 // IUnknown implementation:
50 HRESULT __stdcall QueryInterface(const IID& iid, void** object);
51 ULONG __stdcall AddRef();
52 ULONG __stdcall Release();
53
54 protected:
55 // Returns the hosting HWND.
56 HWND GetHWND() { return hwnd_; }
57
58 // Invoked when the cursor first moves over the hwnd during a dnd session.
59 // This should return a bitmask of the supported drop operations:
60 // DROPEFFECT_NONE, DROPEFFECT_COPY, DROPEFFECT_LINK and/or
61 // DROPEFFECT_MOVE.
62 virtual DWORD OnDragEnter(IDataObject* data_object,
63 DWORD key_state,
64 POINT cursor_position,
65 DWORD effect);
66
67 // Invoked when the cursor moves over the window during a dnd session.
68 // This should return a bitmask of the supported drop operations:
69 // DROPEFFECT_NONE, DROPEFFECT_COPY, DROPEFFECT_LINK and/or
70 // DROPEFFECT_MOVE.
71 virtual DWORD OnDragOver(IDataObject* data_object,
72 DWORD key_state,
73 POINT cursor_position,
74 DWORD effect);
75
76 // Invoked when the cursor moves outside the bounds of the hwnd during a
77 // dnd session.
78 virtual void OnDragLeave(IDataObject* data_object);
79
80 // Invoked when the drop ends on the window. This should return the operation
81 // that was taken.
82 virtual DWORD OnDrop(IDataObject* data_object,
83 DWORD key_state,
84 POINT cursor_position,
85 DWORD effect);
86
[email protected]58377e22009-02-26 01:27:5587 // Return the drag identity.
88 static int32 GetDragIdentity() { return drag_identity_; }
89
initial.commitd7cae122008-07-26 21:49:3890 private:
91 // Returns the cached drop helper, creating one if necessary. The returned
92 // object is not addrefed. May return NULL if the object couldn't be created.
93 static IDropTargetHelper* DropHelper();
94
95 // The data object currently being dragged over this drop target.
[email protected]c7f4b6272008-09-30 20:50:5196 scoped_refptr<IDataObject> current_data_object_;
initial.commitd7cae122008-07-26 21:49:3897
98 // A helper object that is used to provide drag image support while the mouse
99 // is dragging over the content area.
100 //
101 // DO NOT ACCESS DIRECTLY! Use DropHelper() instead, which will lazily create
102 // this if it doesn't exist yet. This object can take tens of milliseconds to
103 // create, and we don't want to block any window opening for this, especially
104 // since often, DnD will never be used. Instead, we force this penalty to the
105 // first time it is actually used.
106 static IDropTargetHelper* cached_drop_target_helper_;
107
[email protected]58377e22009-02-26 01:27:55108 // The drag identity (id). An up-counter that increases when the cursor first
109 // moves over the HWND in a DnD session (OnDragEnter). 0 is reserved to mean
110 // the "no/unknown" identity, and is used for initialization. The identity is
111 // sent to the renderer in drag enter notifications. Note: the identity value
112 // is passed over the renderer NPAPI interface to gears, so use int32 instead
113 // of int here.
114 static int32 drag_identity_;
115
initial.commitd7cae122008-07-26 21:49:38116 // The HWND of the source. This HWND is used to determine coordinates for
117 // mouse events that are sent to the renderer notifying various drag states.
118 HWND hwnd_;
119
120 // Whether or not we are currently processing drag notifications for drags
121 // initiated in this window.
[email protected]6aa4a1c02010-01-15 18:49:58122 bool suspended_;
initial.commitd7cae122008-07-26 21:49:38123
124 LONG ref_count_;
125
[email protected]fc29bc702010-06-04 16:13:51126 DISALLOW_COPY_AND_ASSIGN(BaseDropTarget);
initial.commitd7cae122008-07-26 21:49:38127};
128
[email protected]c7f4b6272008-09-30 20:50:51129#endif // BASE_BASE_DROP_TARGET_H_