1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 #ifndef _nsNativeDragTarget_h_ 6 #define _nsNativeDragTarget_h_ 7 8 #include "nsCOMPtr.h" 9 #include "nsIDragSession.h" 10 #include <ole2.h> 11 #include <shlobj.h> 12 13 #ifndef IDropTargetHelper 14 #include <shobjidl.h> // Vista drag image interfaces 15 #undef LogSeverity // SetupAPI.h #defines this as DWORD 16 #endif 17 18 #include "mozilla/Attributes.h" 19 #include "mozilla/EventForwards.h" 20 21 class nsIDragService; 22 class nsIWidget; 23 24 /* 25 * nsNativeDragTarget implements the IDropTarget interface and gets most of its 26 * behavior from the associated adapter (m_dragDrop). 27 */ 28 29 class nsNativeDragTarget final : public IDropTarget { 30 public: 31 explicit nsNativeDragTarget(nsIWidget* aWidget); 32 ~nsNativeDragTarget(); 33 34 // IUnknown members - see iunknown.h for documentation 35 STDMETHODIMP QueryInterface(REFIID, void**); 36 STDMETHODIMP_(ULONG) AddRef(); 37 STDMETHODIMP_(ULONG) Release(); 38 39 // IDataTarget members 40 41 // Set pEffect based on whether this object can support a drop based on 42 // the data available from pSource, the key and mouse states specified 43 // in grfKeyState, and the coordinates specified by point. This is 44 // called by OLE when a drag enters this object's window (as registered 45 // by Initialize). 46 STDMETHODIMP DragEnter(LPDATAOBJECT pSource, DWORD grfKeyState, POINTL point, 47 DWORD* pEffect); 48 49 // Similar to DragEnter except it is called frequently while the drag 50 // is over this object's window. 51 STDMETHODIMP DragOver(DWORD grfKeyState, POINTL point, DWORD* pEffect); 52 53 // Release the drag-drop source and put internal state back to the point 54 // before the call to DragEnter. This is called when the drag leaves 55 // without a drop occurring. 56 STDMETHODIMP DragLeave(); 57 58 // If point is within our region of interest and pSource's data supports 59 // one of our formats, get the data and set pEffect according to 60 // grfKeyState (DROPEFFECT_MOVE if the control key was not pressed, 61 // DROPEFFECT_COPY if the control key was pressed). Otherwise return 62 // E_FAIL. 63 STDMETHODIMP Drop(LPDATAOBJECT pSource, DWORD grfKeyState, POINTL point, 64 DWORD* pEffect); 65 /** 66 * Cancel the current drag session, if any. 67 */ 68 void DragCancel(); 69 DragImageChanged()70 static void DragImageChanged() { gDragImageChanged = true; } 71 72 protected: 73 void GetGeckoDragAction(DWORD grfKeyState, LPDWORD pdwEffect, 74 uint32_t* aGeckoAction); 75 void ProcessDrag(mozilla::EventMessage aEventMessage, DWORD grfKeyState, 76 POINTL pt, DWORD* pdwEffect); 77 void DispatchDragDropEvent(mozilla::EventMessage aEventMessage, 78 const POINTL& aPT); 79 void AddLinkSupportIfCanBeGenerated(LPDATAOBJECT aIDataSource); 80 81 // Native Stuff 82 ULONG m_cRef; // reference count 83 HWND mHWnd; 84 DWORD mEffectsAllowed; 85 DWORD mEffectsPreferred; 86 bool mTookOwnRef; 87 88 // Gecko Stuff 89 nsIWidget* mWidget; 90 nsIDragService* mDragService; 91 // Drag target helper 92 IDropTargetHelper* GetDropTargetHelper(); 93 94 private: 95 // Drag target helper 96 IDropTargetHelper* mDropTargetHelper; 97 98 static bool gDragImageChanged; 99 }; 100 101 #endif // _nsNativeDragTarget_h_ 102