2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-19 02:01:16 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-04-06 23:39:21 +04:00
|
|
|
*
|
2004-04-19 02:01:16 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1999-04-06 23:39:21 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1999-04-06 23:39:21 +04:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
2004-04-19 02:01:16 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-29 00:14:13 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-19 02:01:16 +04:00
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
2001-09-29 00:14:13 +04:00
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-19 02:01:16 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-29 00:14:13 +04:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-19 02:01:16 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-04-06 23:39:21 +04:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "nsIDragService.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsNativeDragTarget.h"
|
1999-04-17 17:49:39 +04:00
|
|
|
#include "nsDragService.h"
|
1999-04-06 23:39:21 +04:00
|
|
|
#include "nsIServiceManager.h"
|
2005-03-16 18:15:52 +03:00
|
|
|
#include "nsIDOMNode.h"
|
1999-04-23 18:10:39 +04:00
|
|
|
#include "nsCOMPtr.h"
|
1999-04-06 23:39:21 +04:00
|
|
|
|
|
|
|
#include "nsIWidget.h"
|
|
|
|
#include "nsWindow.h"
|
2008-09-10 12:15:54 +04:00
|
|
|
#include "nsClipboard.h"
|
1999-04-06 23:39:21 +04:00
|
|
|
|
|
|
|
/* Define Class IDs */
|
1999-04-17 17:49:39 +04:00
|
|
|
static NS_DEFINE_IID(kCDragServiceCID, NS_DRAGSERVICE_CID);
|
1999-04-06 23:39:21 +04:00
|
|
|
|
|
|
|
/* Define Interface IDs */
|
|
|
|
static NS_DEFINE_IID(kIDragServiceIID, NS_IDRAGSERVICE_IID);
|
|
|
|
|
1999-04-17 17:49:39 +04:00
|
|
|
// This is cached for Leave notification
|
|
|
|
static POINTL gDragLastPoint;
|
1999-04-06 23:39:21 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* class nsNativeDragTarget
|
|
|
|
*/
|
|
|
|
nsNativeDragTarget::nsNativeDragTarget(nsIWidget * aWnd)
|
2011-09-01 17:48:48 +04:00
|
|
|
: m_cRef(0),
|
2011-09-30 17:14:44 +04:00
|
|
|
mEffectsAllowed(DROPEFFECT_MOVE | DROPEFFECT_COPY | DROPEFFECT_LINK),
|
|
|
|
mEffectsPreferred(DROPEFFECT_NONE),
|
2011-10-02 06:16:19 +04:00
|
|
|
mTookOwnRef(false), mWindow(aWnd), mDropTargetHelper(nsnull)
|
1999-04-06 23:39:21 +04:00
|
|
|
{
|
2005-03-15 03:07:46 +03:00
|
|
|
mHWnd = (HWND)mWindow->GetNativeData(NS_NATIVE_WINDOW);
|
1999-04-17 17:49:39 +04:00
|
|
|
|
1999-04-06 23:39:21 +04:00
|
|
|
/*
|
1999-04-23 18:10:39 +04:00
|
|
|
* Create/Get the DragService that we have implemented
|
1999-04-06 23:39:21 +04:00
|
|
|
*/
|
2004-11-08 02:59:35 +03:00
|
|
|
CallGetService(kCDragServiceCID, &mDragService);
|
1999-04-06 23:39:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsNativeDragTarget::~nsNativeDragTarget()
|
|
|
|
{
|
2004-11-08 02:59:35 +03:00
|
|
|
NS_RELEASE(mDragService);
|
2009-01-03 01:06:40 +03:00
|
|
|
|
2007-11-17 07:31:32 +03:00
|
|
|
if (mDropTargetHelper) {
|
|
|
|
mDropTargetHelper->Release();
|
|
|
|
mDropTargetHelper = nsnull;
|
|
|
|
}
|
1999-04-06 23:39:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// IUnknown methods - see iunknown.h for documentation
|
2005-03-15 03:07:46 +03:00
|
|
|
STDMETHODIMP
|
|
|
|
nsNativeDragTarget::QueryInterface(REFIID riid, void** ppv)
|
1999-04-06 23:39:21 +04:00
|
|
|
{
|
2005-03-15 03:07:46 +03:00
|
|
|
*ppv=NULL;
|
1999-04-06 23:39:21 +04:00
|
|
|
|
2005-03-15 03:07:46 +03:00
|
|
|
if (IID_IUnknown == riid || IID_IDropTarget == riid)
|
|
|
|
*ppv=this;
|
1999-04-06 23:39:21 +04:00
|
|
|
|
2005-03-15 03:07:46 +03:00
|
|
|
if (NULL!=*ppv) {
|
|
|
|
((LPUNKNOWN)*ppv)->AddRef();
|
2010-02-20 16:45:19 +03:00
|
|
|
return S_OK;
|
2005-03-15 03:07:46 +03:00
|
|
|
}
|
1999-04-06 23:39:21 +04:00
|
|
|
|
2010-02-20 16:45:19 +03:00
|
|
|
return E_NOINTERFACE;
|
1999-04-06 23:39:21 +04:00
|
|
|
}
|
|
|
|
|
2005-03-15 03:07:46 +03:00
|
|
|
STDMETHODIMP_(ULONG)
|
|
|
|
nsNativeDragTarget::AddRef(void)
|
1999-04-06 23:39:21 +04:00
|
|
|
{
|
2005-03-15 03:07:46 +03:00
|
|
|
++m_cRef;
|
|
|
|
NS_LOG_ADDREF(this, m_cRef, "nsNativeDragTarget", sizeof(*this));
|
|
|
|
return m_cRef;
|
1999-04-06 23:39:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP_(ULONG) nsNativeDragTarget::Release(void)
|
|
|
|
{
|
2005-03-15 03:07:46 +03:00
|
|
|
--m_cRef;
|
|
|
|
NS_LOG_RELEASE(this, m_cRef, "nsNativeDragTarget");
|
|
|
|
if (0 != m_cRef)
|
|
|
|
return m_cRef;
|
1999-04-06 23:39:21 +04:00
|
|
|
|
2005-03-15 03:07:46 +03:00
|
|
|
delete this;
|
|
|
|
return 0;
|
1999-04-06 23:39:21 +04:00
|
|
|
}
|
|
|
|
|
2005-03-15 03:07:46 +03:00
|
|
|
void
|
2011-09-01 17:48:48 +04:00
|
|
|
nsNativeDragTarget::GetGeckoDragAction(DWORD grfKeyState, LPDWORD pdwEffect,
|
2005-03-15 03:07:46 +03:00
|
|
|
PRUint32 * aGeckoAction)
|
2011-09-01 17:48:48 +04:00
|
|
|
{
|
2011-09-30 17:14:44 +04:00
|
|
|
// If a window is disabled or a modal window is on top of it
|
|
|
|
// (which implies it is disabled), then we should not allow dropping.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isEnabled;
|
2011-09-01 17:48:48 +04:00
|
|
|
if (NS_SUCCEEDED(mWindow->IsEnabled(&isEnabled)) && !isEnabled) {
|
|
|
|
*pdwEffect = DROPEFFECT_NONE;
|
|
|
|
*aGeckoAction = nsIDragService::DRAGDROP_ACTION_NONE;
|
2011-09-30 17:14:44 +04:00
|
|
|
return;
|
2011-09-01 17:48:48 +04:00
|
|
|
}
|
2011-09-30 17:14:44 +04:00
|
|
|
|
|
|
|
// If the user explicitly uses a modifier key, they want the associated action
|
|
|
|
// Shift + Control -> LINK, Shift -> MOVE, Ctrl -> COPY
|
|
|
|
DWORD desiredEffect = DROPEFFECT_NONE;
|
|
|
|
if ((grfKeyState & MK_CONTROL) && (grfKeyState & MK_SHIFT)) {
|
|
|
|
desiredEffect = DROPEFFECT_LINK;
|
|
|
|
} else if (grfKeyState & MK_SHIFT) {
|
|
|
|
desiredEffect = DROPEFFECT_MOVE;
|
|
|
|
} else if (grfKeyState & MK_CONTROL) {
|
|
|
|
desiredEffect = DROPEFFECT_COPY;
|
2011-09-01 17:48:48 +04:00
|
|
|
}
|
2011-09-30 17:14:44 +04:00
|
|
|
|
|
|
|
// Determine the desired effect from what is allowed and preferred.
|
|
|
|
if (!(desiredEffect &= mEffectsAllowed)) {
|
|
|
|
// No modifier key effect is set which is also allowed, check
|
|
|
|
// the preference of the data.
|
|
|
|
desiredEffect = mEffectsPreferred & mEffectsAllowed;
|
|
|
|
if (!desiredEffect) {
|
|
|
|
// No preference is set, so just fall back to the allowed effect itself
|
|
|
|
desiredEffect = mEffectsAllowed;
|
|
|
|
}
|
2001-08-01 04:43:11 +04:00
|
|
|
}
|
2011-09-30 17:14:44 +04:00
|
|
|
|
|
|
|
// Otherwise we should specify the first available effect
|
|
|
|
// from MOVE, COPY, or LINK.
|
|
|
|
if (desiredEffect & DROPEFFECT_MOVE) {
|
2011-09-01 17:48:48 +04:00
|
|
|
*pdwEffect = DROPEFFECT_MOVE;
|
|
|
|
*aGeckoAction = nsIDragService::DRAGDROP_ACTION_MOVE;
|
2011-09-30 17:14:44 +04:00
|
|
|
} else if (desiredEffect & DROPEFFECT_COPY) {
|
2011-09-01 17:48:48 +04:00
|
|
|
*pdwEffect = DROPEFFECT_COPY;
|
|
|
|
*aGeckoAction = nsIDragService::DRAGDROP_ACTION_COPY;
|
2011-09-30 17:14:44 +04:00
|
|
|
} else if (desiredEffect & DROPEFFECT_LINK) {
|
2011-09-01 17:48:48 +04:00
|
|
|
*pdwEffect = DROPEFFECT_LINK;
|
|
|
|
*aGeckoAction = nsIDragService::DRAGDROP_ACTION_LINK;
|
2011-09-30 17:14:44 +04:00
|
|
|
} else {
|
|
|
|
*pdwEffect = DROPEFFECT_NONE;
|
|
|
|
*aGeckoAction = nsIDragService::DRAGDROP_ACTION_NONE;
|
|
|
|
}
|
1999-04-23 18:10:39 +04:00
|
|
|
}
|
|
|
|
|
2000-08-04 02:06:10 +04:00
|
|
|
inline
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2005-03-15 03:07:46 +03:00
|
|
|
IsKeyDown(char key)
|
2000-08-04 02:06:10 +04:00
|
|
|
{
|
2004-03-25 22:43:59 +03:00
|
|
|
return GetKeyState(key) < 0;
|
2000-08-04 02:06:10 +04:00
|
|
|
}
|
|
|
|
|
2005-03-15 03:07:46 +03:00
|
|
|
void
|
|
|
|
nsNativeDragTarget::DispatchDragDropEvent(PRUint32 aEventType, POINTL aPT)
|
1999-04-06 23:39:21 +04:00
|
|
|
{
|
|
|
|
nsEventStatus status;
|
2011-10-02 06:16:19 +04:00
|
|
|
nsDragEvent event(true, aEventType, mWindow);
|
1999-04-17 17:49:39 +04:00
|
|
|
|
2007-07-08 11:08:04 +04:00
|
|
|
nsWindow * win = static_cast<nsWindow *>(mWindow);
|
2004-01-12 11:25:18 +03:00
|
|
|
win->InitEvent(event);
|
1999-04-17 17:49:39 +04:00
|
|
|
POINT cpos;
|
|
|
|
|
|
|
|
cpos.x = aPT.x;
|
|
|
|
cpos.y = aPT.y;
|
|
|
|
|
|
|
|
if (mHWnd != NULL) {
|
|
|
|
::ScreenToClient(mHWnd, &cpos);
|
2005-08-23 07:57:07 +04:00
|
|
|
event.refPoint.x = cpos.x;
|
|
|
|
event.refPoint.y = cpos.y;
|
1999-04-17 17:49:39 +04:00
|
|
|
} else {
|
2005-08-23 07:57:07 +04:00
|
|
|
event.refPoint.x = 0;
|
|
|
|
event.refPoint.y = 0;
|
1999-04-17 17:49:39 +04:00
|
|
|
}
|
|
|
|
|
2012-04-25 07:00:01 +04:00
|
|
|
nsModifierKeyState modifierKeyState;
|
|
|
|
modifierKeyState.InitInputEvent(event);
|
|
|
|
|
2010-04-06 16:59:24 +04:00
|
|
|
event.inputSource = static_cast<nsBaseDragService*>(mDragService)->GetInputSource();
|
2000-08-04 02:06:10 +04:00
|
|
|
|
1999-04-06 23:39:21 +04:00
|
|
|
mWindow->DispatchEvent(&event, status);
|
|
|
|
}
|
|
|
|
|
2005-03-15 03:07:46 +03:00
|
|
|
void
|
2011-09-01 17:48:48 +04:00
|
|
|
nsNativeDragTarget::ProcessDrag(PRUint32 aEventType,
|
2005-03-15 03:07:46 +03:00
|
|
|
DWORD grfKeyState,
|
2007-11-17 07:31:32 +03:00
|
|
|
POINTL ptl,
|
2005-03-15 03:07:46 +03:00
|
|
|
DWORD* pdwEffect)
|
1999-04-23 18:10:39 +04:00
|
|
|
{
|
|
|
|
// Before dispatching the event make sure we have the correct drop action set
|
|
|
|
PRUint32 geckoAction;
|
2011-09-01 17:48:48 +04:00
|
|
|
GetGeckoDragAction(grfKeyState, pdwEffect, &geckoAction);
|
1999-04-23 18:10:39 +04:00
|
|
|
|
|
|
|
// Set the current action into the Gecko specific type
|
2000-10-07 04:11:28 +04:00
|
|
|
nsCOMPtr<nsIDragSession> currSession;
|
2005-03-15 03:07:46 +03:00
|
|
|
mDragService->GetCurrentSession(getter_AddRefs(currSession));
|
2008-04-10 16:38:05 +04:00
|
|
|
if (!currSession) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-10-07 04:11:28 +04:00
|
|
|
currSession->SetDragAction(geckoAction);
|
1999-04-23 18:10:39 +04:00
|
|
|
|
|
|
|
// Dispatch the event into Gecko
|
2007-11-17 07:31:32 +03:00
|
|
|
DispatchDragDropEvent(aEventType, ptl);
|
1999-04-23 18:10:39 +04:00
|
|
|
|
2011-09-01 17:48:48 +04:00
|
|
|
if (aEventType != NS_DRAGDROP_DROP) {
|
|
|
|
// Get the cached drag effect from the drag service, the data member should
|
|
|
|
// have been set by whoever handled the nsGUIEvent or nsIDOMEvent on drags.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool canDrop;
|
2011-09-01 17:48:48 +04:00
|
|
|
currSession->GetCanDrop(&canDrop);
|
|
|
|
if (!canDrop) {
|
|
|
|
*pdwEffect = DROPEFFECT_NONE;
|
|
|
|
}
|
|
|
|
}
|
1999-04-23 18:10:39 +04:00
|
|
|
|
|
|
|
// Clear the cached value
|
2011-10-02 06:16:19 +04:00
|
|
|
currSession->SetCanDrop(false);
|
1999-04-23 18:10:39 +04:00
|
|
|
}
|
|
|
|
|
1999-04-06 23:39:21 +04:00
|
|
|
// IDropTarget methods
|
2005-03-15 03:07:46 +03:00
|
|
|
STDMETHODIMP
|
|
|
|
nsNativeDragTarget::DragEnter(LPDATAOBJECT pIDataSource,
|
|
|
|
DWORD grfKeyState,
|
2007-11-17 07:31:32 +03:00
|
|
|
POINTL ptl,
|
2005-03-15 03:07:46 +03:00
|
|
|
DWORD* pdwEffect)
|
1999-04-06 23:39:21 +04:00
|
|
|
{
|
2010-02-20 16:45:19 +03:00
|
|
|
if (!mDragService) {
|
|
|
|
return E_FAIL;
|
2005-03-15 03:07:46 +03:00
|
|
|
}
|
2000-07-26 08:03:42 +04:00
|
|
|
|
2011-09-01 17:48:48 +04:00
|
|
|
mEffectsAllowed = *pdwEffect;
|
|
|
|
AddLinkSupportIfCanBeGenerated(pIDataSource);
|
|
|
|
|
2007-11-17 07:31:32 +03:00
|
|
|
// Drag and drop image helper
|
2012-02-01 18:30:05 +04:00
|
|
|
if (GetDropTargetHelper()) {
|
2007-11-17 07:31:32 +03:00
|
|
|
POINT pt = { ptl.x, ptl.y };
|
2012-02-01 18:30:05 +04:00
|
|
|
GetDropTargetHelper()->DragEnter(mHWnd, pIDataSource, &pt, *pdwEffect);
|
2007-11-17 07:31:32 +03:00
|
|
|
}
|
|
|
|
|
2009-01-03 01:06:40 +03:00
|
|
|
// save a ref to this, in case the window is destroyed underneath us
|
|
|
|
NS_ASSERTION(!mTookOwnRef, "own ref already taken!");
|
|
|
|
this->AddRef();
|
2011-10-02 06:16:19 +04:00
|
|
|
mTookOwnRef = true;
|
2009-01-03 01:06:40 +03:00
|
|
|
|
2005-03-15 03:07:46 +03:00
|
|
|
// tell the drag service about this drag (it may have come from an
|
|
|
|
// outside app).
|
|
|
|
mDragService->StartDragSession();
|
2000-07-26 08:03:42 +04:00
|
|
|
|
2008-09-10 12:15:54 +04:00
|
|
|
void* tempOutData = nsnull;
|
|
|
|
PRUint32 tempDataLen = 0;
|
|
|
|
nsresult loadResult = nsClipboard::GetNativeDataOffClipboard(
|
2008-10-20 19:21:02 +04:00
|
|
|
pIDataSource, 0, ::RegisterClipboardFormat(CFSTR_PREFERREDDROPEFFECT), nsnull, &tempOutData, &tempDataLen);
|
2008-09-10 12:15:54 +04:00
|
|
|
if (NS_SUCCEEDED(loadResult) && tempOutData) {
|
2011-09-30 17:14:44 +04:00
|
|
|
mEffectsPreferred = *((DWORD*)tempOutData);
|
2011-09-13 01:52:37 +04:00
|
|
|
nsMemory::Free(tempOutData);
|
2011-09-01 17:48:48 +04:00
|
|
|
} else {
|
2011-09-30 17:14:44 +04:00
|
|
|
// We have no preference if we can't obtain it
|
|
|
|
mEffectsPreferred = DROPEFFECT_NONE;
|
2008-09-10 12:15:54 +04:00
|
|
|
}
|
|
|
|
|
2005-03-15 03:07:46 +03:00
|
|
|
// Set the native data object into drag service
|
|
|
|
//
|
|
|
|
// This cast is ok because in the constructor we created a
|
|
|
|
// the actual implementation we wanted, so we know this is
|
|
|
|
// a nsDragService. It should be a private interface, though.
|
|
|
|
nsDragService * winDragService =
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<nsDragService *>(mDragService);
|
2005-03-15 03:07:46 +03:00
|
|
|
winDragService->SetIDataObject(pIDataSource);
|
1999-04-24 01:57:44 +04:00
|
|
|
|
2005-03-15 03:07:46 +03:00
|
|
|
// Now process the native drag state and then dispatch the event
|
2011-09-01 17:48:48 +04:00
|
|
|
ProcessDrag(NS_DRAGDROP_ENTER, grfKeyState, ptl, pdwEffect);
|
1999-04-23 18:10:39 +04:00
|
|
|
|
2005-03-15 03:07:46 +03:00
|
|
|
return S_OK;
|
1999-04-06 23:39:21 +04:00
|
|
|
}
|
|
|
|
|
2011-09-01 17:48:48 +04:00
|
|
|
void
|
|
|
|
nsNativeDragTarget::AddLinkSupportIfCanBeGenerated(LPDATAOBJECT aIDataSource)
|
|
|
|
{
|
|
|
|
// If we don't have a link effect, but we can generate one, fix the
|
|
|
|
// drop effect to include it.
|
|
|
|
if (!(mEffectsAllowed & DROPEFFECT_LINK) && aIDataSource) {
|
|
|
|
if (S_OK == ::OleQueryLinkFromData(aIDataSource)) {
|
|
|
|
mEffectsAllowed |= DROPEFFECT_LINK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-15 03:07:46 +03:00
|
|
|
STDMETHODIMP
|
|
|
|
nsNativeDragTarget::DragOver(DWORD grfKeyState,
|
2007-11-17 07:31:32 +03:00
|
|
|
POINTL ptl,
|
2005-03-15 03:07:46 +03:00
|
|
|
LPDWORD pdwEffect)
|
1999-04-06 23:39:21 +04:00
|
|
|
{
|
2010-02-20 16:45:19 +03:00
|
|
|
if (!mDragService) {
|
|
|
|
return E_FAIL;
|
2005-03-15 03:07:46 +03:00
|
|
|
}
|
|
|
|
|
2011-09-01 17:48:48 +04:00
|
|
|
// If a LINK effect could be generated previously from a DragEnter(),
|
|
|
|
// then we should include it as an allowed effect.
|
|
|
|
mEffectsAllowed = (*pdwEffect) | (mEffectsAllowed & DROPEFFECT_LINK);
|
|
|
|
|
2010-06-02 17:02:05 +04:00
|
|
|
nsCOMPtr<nsIDragSession> currentDragSession;
|
|
|
|
mDragService->GetCurrentSession(getter_AddRefs(currentDragSession));
|
|
|
|
if (!currentDragSession) {
|
|
|
|
return S_OK; // Drag was canceled.
|
|
|
|
}
|
|
|
|
|
2007-09-29 02:45:14 +04:00
|
|
|
// without the AddRef() |this| can get destroyed in an event handler
|
|
|
|
this->AddRef();
|
2007-11-17 07:31:32 +03:00
|
|
|
|
|
|
|
// Drag and drop image helper
|
2012-02-01 18:30:05 +04:00
|
|
|
if (GetDropTargetHelper()) {
|
2007-11-17 07:31:32 +03:00
|
|
|
POINT pt = { ptl.x, ptl.y };
|
2012-02-01 18:30:05 +04:00
|
|
|
GetDropTargetHelper()->DragOver(&pt, *pdwEffect);
|
2007-11-17 07:31:32 +03:00
|
|
|
}
|
|
|
|
|
2007-04-12 08:37:39 +04:00
|
|
|
mDragService->FireDragEventAtSource(NS_DRAGDROP_DRAG);
|
2010-06-02 17:02:05 +04:00
|
|
|
// Now process the native drag state and then dispatch the event
|
2011-09-01 17:48:48 +04:00
|
|
|
ProcessDrag(NS_DRAGDROP_OVER, grfKeyState, ptl, pdwEffect);
|
2007-11-17 07:31:32 +03:00
|
|
|
|
2007-09-29 02:45:14 +04:00
|
|
|
this->Release();
|
2007-04-12 08:37:39 +04:00
|
|
|
|
2005-03-15 03:07:46 +03:00
|
|
|
return S_OK;
|
1999-04-06 23:39:21 +04:00
|
|
|
}
|
|
|
|
|
2005-03-15 03:07:46 +03:00
|
|
|
STDMETHODIMP
|
|
|
|
nsNativeDragTarget::DragLeave()
|
|
|
|
{
|
2010-02-20 16:45:19 +03:00
|
|
|
if (!mDragService) {
|
|
|
|
return E_FAIL;
|
2005-03-15 03:07:46 +03:00
|
|
|
}
|
2000-10-07 04:11:28 +04:00
|
|
|
|
2007-11-17 07:31:32 +03:00
|
|
|
// Drag and drop image helper
|
2012-02-01 18:30:05 +04:00
|
|
|
if (GetDropTargetHelper()) {
|
|
|
|
GetDropTargetHelper()->DragLeave();
|
2007-11-17 07:31:32 +03:00
|
|
|
}
|
|
|
|
|
2005-03-15 03:07:46 +03:00
|
|
|
// dispatch the event into Gecko
|
|
|
|
DispatchDragDropEvent(NS_DRAGDROP_EXIT, gDragLastPoint);
|
|
|
|
|
2005-03-16 03:40:21 +03:00
|
|
|
nsCOMPtr<nsIDragSession> currentDragSession;
|
|
|
|
mDragService->GetCurrentSession(getter_AddRefs(currentDragSession));
|
|
|
|
|
|
|
|
if (currentDragSession) {
|
|
|
|
nsCOMPtr<nsIDOMNode> sourceNode;
|
|
|
|
currentDragSession->GetSourceNode(getter_AddRefs(sourceNode));
|
|
|
|
|
|
|
|
if (!sourceNode) {
|
|
|
|
// We're leaving a window while doing a drag that was
|
|
|
|
// initiated in a different app. End the drag session, since
|
|
|
|
// we're done with it for now (until the user drags back into
|
|
|
|
// mozilla).
|
2011-10-02 06:16:19 +04:00
|
|
|
mDragService->EndDragSession(false);
|
2005-03-16 03:40:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-03 01:06:40 +03:00
|
|
|
// release the ref that was taken in DragEnter
|
|
|
|
NS_ASSERTION(mTookOwnRef, "want to release own ref, but not taken!");
|
|
|
|
if (mTookOwnRef) {
|
|
|
|
this->Release();
|
2011-10-02 06:16:19 +04:00
|
|
|
mTookOwnRef = false;
|
2009-01-03 01:06:40 +03:00
|
|
|
}
|
|
|
|
|
2005-03-15 03:07:46 +03:00
|
|
|
return S_OK;
|
1999-04-06 23:39:21 +04:00
|
|
|
}
|
|
|
|
|
2010-06-02 17:02:05 +04:00
|
|
|
void
|
|
|
|
nsNativeDragTarget::DragCancel()
|
|
|
|
{
|
2010-08-14 03:58:19 +04:00
|
|
|
// Cancel the drag session if we did DragEnter.
|
2010-06-02 17:02:05 +04:00
|
|
|
if (mTookOwnRef) {
|
2012-02-01 18:30:05 +04:00
|
|
|
if (GetDropTargetHelper()) {
|
|
|
|
GetDropTargetHelper()->DragLeave();
|
2010-08-14 03:58:19 +04:00
|
|
|
}
|
|
|
|
if (mDragService) {
|
2011-10-02 06:16:19 +04:00
|
|
|
mDragService->EndDragSession(false);
|
2010-08-14 03:58:19 +04:00
|
|
|
}
|
|
|
|
this->Release(); // matching the AddRef in DragEnter
|
2011-10-02 06:16:19 +04:00
|
|
|
mTookOwnRef = false;
|
2010-06-02 17:02:05 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-15 03:07:46 +03:00
|
|
|
STDMETHODIMP
|
|
|
|
nsNativeDragTarget::Drop(LPDATAOBJECT pData,
|
|
|
|
DWORD grfKeyState,
|
|
|
|
POINTL aPT,
|
|
|
|
LPDWORD pdwEffect)
|
1999-04-06 23:39:21 +04:00
|
|
|
{
|
2010-02-20 16:45:19 +03:00
|
|
|
if (!mDragService) {
|
|
|
|
return E_FAIL;
|
2005-03-15 03:07:46 +03:00
|
|
|
}
|
2000-10-07 04:11:28 +04:00
|
|
|
|
2011-09-01 17:48:48 +04:00
|
|
|
mEffectsAllowed = *pdwEffect;
|
|
|
|
AddLinkSupportIfCanBeGenerated(pData);
|
|
|
|
|
2007-11-17 07:31:32 +03:00
|
|
|
// Drag and drop image helper
|
2012-02-01 18:30:05 +04:00
|
|
|
if (GetDropTargetHelper()) {
|
2007-11-17 07:31:32 +03:00
|
|
|
POINT pt = { aPT.x, aPT.y };
|
2012-02-01 18:30:05 +04:00
|
|
|
GetDropTargetHelper()->Drop(pData, &pt, *pdwEffect);
|
2007-11-17 07:31:32 +03:00
|
|
|
}
|
|
|
|
|
2005-03-15 03:07:46 +03:00
|
|
|
// Set the native data object into the drag service
|
|
|
|
//
|
|
|
|
// This cast is ok because in the constructor we created a
|
|
|
|
// the actual implementation we wanted, so we know this is
|
|
|
|
// a nsDragService (but it should still be a private interface)
|
2010-08-14 03:58:19 +04:00
|
|
|
nsDragService* winDragService = static_cast<nsDragService*>(mDragService);
|
2005-03-15 03:07:46 +03:00
|
|
|
winDragService->SetIDataObject(pData);
|
|
|
|
|
2010-08-14 03:58:19 +04:00
|
|
|
// NOTE: ProcessDrag spins the event loop which may destroy arbitrary objects.
|
|
|
|
// We use strong refs to prevent it from destroying these:
|
|
|
|
nsRefPtr<nsNativeDragTarget> kungFuDeathGrip = this;
|
2006-05-12 07:39:34 +04:00
|
|
|
nsCOMPtr<nsIDragService> serv = mDragService;
|
|
|
|
|
2005-03-15 03:07:46 +03:00
|
|
|
// Now process the native drag state and then dispatch the event
|
2011-09-01 17:48:48 +04:00
|
|
|
ProcessDrag(NS_DRAGDROP_DROP, grfKeyState, aPT, pdwEffect);
|
2005-03-15 03:07:46 +03:00
|
|
|
|
2010-08-14 03:58:19 +04:00
|
|
|
nsCOMPtr<nsIDragSession> currentDragSession;
|
|
|
|
serv->GetCurrentSession(getter_AddRefs(currentDragSession));
|
|
|
|
if (!currentDragSession) {
|
|
|
|
return S_OK; // DragCancel() was called.
|
|
|
|
}
|
|
|
|
|
2008-09-29 00:57:33 +04:00
|
|
|
// Let the win drag service know whether this session experienced
|
|
|
|
// a drop event within the application. Drop will not oocur if the
|
|
|
|
// drop landed outside the app. (used in tab tear off, bug 455884)
|
|
|
|
winDragService->SetDroppedLocal();
|
|
|
|
|
2005-03-15 03:07:46 +03:00
|
|
|
// tell the drag service we're done with the session
|
2009-08-11 01:29:41 +04:00
|
|
|
// Use GetMessagePos to get the position of the mouse at the last message
|
|
|
|
// seen by the event loop. (Bug 489729)
|
|
|
|
DWORD pos = ::GetMessagePos();
|
|
|
|
POINT cpos;
|
|
|
|
cpos.x = GET_X_LPARAM(pos);
|
|
|
|
cpos.y = GET_Y_LPARAM(pos);
|
|
|
|
winDragService->SetDragEndPoint(nsIntPoint(cpos.x, cpos.y));
|
2011-10-02 06:16:19 +04:00
|
|
|
serv->EndDragSession(true);
|
2009-01-03 01:06:40 +03:00
|
|
|
|
|
|
|
// release the ref that was taken in DragEnter
|
|
|
|
NS_ASSERTION(mTookOwnRef, "want to release own ref, but not taken!");
|
|
|
|
if (mTookOwnRef) {
|
|
|
|
this->Release();
|
2011-10-02 06:16:19 +04:00
|
|
|
mTookOwnRef = false;
|
2009-01-03 01:06:40 +03:00
|
|
|
}
|
|
|
|
|
2005-03-15 03:07:46 +03:00
|
|
|
return S_OK;
|
1999-04-06 23:39:21 +04:00
|
|
|
}
|
2012-02-01 18:30:05 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* By lazy loading mDropTargetHelper we save 50-70ms of startup time
|
|
|
|
* which is ~5% of startup time.
|
|
|
|
*/
|
|
|
|
IDropTargetHelper*
|
|
|
|
nsNativeDragTarget::GetDropTargetHelper()
|
|
|
|
{
|
|
|
|
if (!mDropTargetHelper) {
|
|
|
|
CoCreateInstance(CLSID_DragDropHelper, NULL, CLSCTX_INPROC_SERVER,
|
|
|
|
IID_IDropTargetHelper, (LPVOID*)&mDropTargetHelper);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mDropTargetHelper;
|
|
|
|
}
|