blob: 53d88faa808823dc71be26e97d82594261b7e567 [file] [log] [blame]
[email protected]02bae0f2011-01-19 20:22:001// Copyright (c) 2011 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]02bae0f2011-01-19 20:22:005#ifndef UI_BASE_DRAGDROP_DROP_TARGET_H_
6#define UI_BASE_DRAGDROP_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]3b63f8f42011-03-28 01:54:1511#include "base/memory/ref_counted.h"
[email protected]ea47b6a2011-07-17 19:39:4212#include "ui/ui_api.h"
[email protected]c7f4b6272008-09-30 20:50:5113
[email protected]79a4c1e2010-10-17 20:44:3814// Windows interface.
[email protected]c7f4b6272008-09-30 20:50:5115struct IDropTargetHelper;
initial.commitd7cae122008-07-26 21:49:3816
[email protected]02bae0f2011-01-19 20:22:0017namespace ui {
[email protected]79a4c1e2010-10-17 20:44:3818
initial.commitd7cae122008-07-26 21:49:3819// 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]79a4c1e2010-10-17 20:44:3823// Because DropTarget is ref counted you shouldn't delete it directly,
initial.commitd7cae122008-07-26 21:49:3824// rather wrap it in a scoped_refptr. Be sure and invoke RevokeDragDrop(m_hWnd)
25// before the HWND is deleted too.
[email protected]c7f4b6272008-09-30 20:50:5126//
27// This class is meant to be used in a STA and is not multithread-safe.
[email protected]ea47b6a2011-07-17 19:39:4228class UI_API DropTarget : public IDropTarget {
initial.commitd7cae122008-07-26 21:49:3829 public:
[email protected]79a4c1e2010-10-17 20:44:3830 // Create a new DropTarget associating it with the given HWND.
31 explicit DropTarget(HWND hwnd);
32 virtual ~DropTarget();
initial.commitd7cae122008-07-26 21:49:3833
[email protected]6aa4a1c02010-01-15 18:49:5834 // When suspended is set to |true|, the drop target does not receive drops
35 // from drags initiated within the owning HWND.
[email protected]6aa4a1c02010-01-15 18:49:5836 bool suspended() const { return suspended_; }
37 void set_suspended(bool suspended) { suspended_ = suspended; }
initial.commitd7cae122008-07-26 21:49:3838
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]c7f4b6272008-09-30 20:50:5197 scoped_refptr<IDataObject> current_data_object_;
initial.commitd7cae122008-07-26 21:49:3898
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]6aa4a1c02010-01-15 18:49:58115 bool suspended_;
initial.commitd7cae122008-07-26 21:49:38116
117 LONG ref_count_;
118
[email protected]79a4c1e2010-10-17 20:44:38119 DISALLOW_COPY_AND_ASSIGN(DropTarget);
initial.commitd7cae122008-07-26 21:49:38120};
121
[email protected]02bae0f2011-01-19 20:22:00122} // namespace ui
[email protected]79a4c1e2010-10-17 20:44:38123
[email protected]02bae0f2011-01-19 20:22:00124#endif // UI_BASE_DRAGDROP_DROP_TARGET_H_