Also ran 'git cl format' on this file since I was touching a lot of it anyway.
[chromium-blink-merge.git] / ui / base / dragdrop / drop_target_win.h
blob4536f1d6aa6ce5c95838ffe32f2a2b29a0843b02
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_
8 #include <objidl.h>
10 #include "base/memory/ref_counted.h"
11 #include "ui/base/ui_base_export.h"
13 // Windows interface.
14 struct IDropTargetHelper;
16 namespace ui {
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 {
28 public:
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,
35 DWORD key_state,
36 POINTL cursor_position,
37 DWORD* effect);
38 HRESULT __stdcall DragOver(DWORD key_state,
39 POINTL cursor_position,
40 DWORD* effect);
41 HRESULT __stdcall DragLeave();
42 HRESULT __stdcall Drop(IDataObject* data_object,
43 DWORD key_state,
44 POINTL cursor_position,
45 DWORD* effect);
47 // IUnknown implementation:
48 HRESULT __stdcall QueryInterface(const IID& iid, void** object);
49 ULONG __stdcall AddRef();
50 ULONG __stdcall Release();
52 protected:
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
59 // DROPEFFECT_MOVE.
60 virtual DWORD OnDragEnter(IDataObject* data_object,
61 DWORD key_state,
62 POINT cursor_position,
63 DWORD effect);
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
68 // DROPEFFECT_MOVE.
69 virtual DWORD OnDragOver(IDataObject* data_object,
70 DWORD key_state,
71 POINT cursor_position,
72 DWORD effect);
74 // Invoked when the cursor moves outside the bounds of the hwnd during a
75 // dnd session.
76 virtual void OnDragLeave(IDataObject* data_object);
78 // Invoked when the drop ends on the window. This should return the operation
79 // that was taken.
80 virtual DWORD OnDrop(IDataObject* data_object,
81 DWORD key_state,
82 POINT cursor_position,
83 DWORD effect);
85 private:
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.
105 HWND hwnd_;
107 LONG ref_count_;
109 DISALLOW_COPY_AND_ASSIGN(DropTargetWin);
112 } // namespace ui
114 #endif // UI_BASE_DRAGDROP_DROP_TARGET_WIN_H_