2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
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"
|
2012-06-15 13:52:50 +04:00
|
|
|
#include "KeyboardLayout.h"
|
|
|
|
|
2013-09-25 15:21:18 +04:00
|
|
|
#include "mozilla/MouseEvents.h"
|
|
|
|
|
2013-10-01 11:23:02 +04:00
|
|
|
using namespace mozilla;
|
2012-06-15 13:52:50 +04:00
|
|
|
using namespace mozilla::widget;
|
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
|
|
|
|
*/
|
2012-07-25 19:09:16 +04:00
|
|
|
nsNativeDragTarget::nsNativeDragTarget(nsIWidget * aWidget)
|
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),
|
2012-07-30 18:20:58 +04:00
|
|
|
mTookOwnRef(false), mWidget(aWidget), mDropTargetHelper(nullptr)
|
1999-04-06 23:39:21 +04:00
|
|
|
{
|
2013-12-16 04:00:54 +04:00
|
|
|
static NS_DEFINE_IID(kCDragServiceCID, NS_DRAGSERVICE_CID);
|
|
|
|
|
2012-07-25 19:09:16 +04:00
|
|
|
mHWnd = (HWND)mWidget->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();
|
2012-07-30 18:20:58 +04:00
|
|
|
mDropTargetHelper = nullptr;
|
2007-11-17 07:31:32 +03:00
|
|
|
}
|
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
|
|
|
{
|
2013-10-08 22:48:20 +04:00
|
|
|
*ppv=nullptr;
|
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
|
|
|
|
2013-10-08 22:48:20 +04:00
|
|
|
if (nullptr!=*ppv) {
|
2005-03-15 03:07:46 +03:00
|
|
|
((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,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t * 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.
|
2012-07-25 19:09:16 +04:00
|
|
|
if (!mWidget->IsEnabled()) {
|
2011-09-01 17:48:48 +04:00
|
|
|
*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
|
2015-08-26 15:56:59 +03:00
|
|
|
nsNativeDragTarget::DispatchDragDropEvent(EventMessage aEventMessage,
|
|
|
|
const POINTL& aPT)
|
1999-04-06 23:39:21 +04:00
|
|
|
{
|
|
|
|
nsEventStatus status;
|
2015-08-26 15:56:59 +03:00
|
|
|
WidgetDragEvent event(true, aEventMessage, mWidget);
|
1999-04-17 17:49:39 +04:00
|
|
|
|
2012-07-25 19:09:16 +04:00
|
|
|
nsWindow * win = static_cast<nsWindow *>(mWidget);
|
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;
|
|
|
|
|
2013-10-08 22:48:20 +04:00
|
|
|
if (mHWnd != nullptr) {
|
1999-04-17 17:49:39 +04:00
|
|
|
::ScreenToClient(mHWnd, &cpos);
|
2016-04-18 17:09:02 +03:00
|
|
|
event.mRefPoint = LayoutDeviceIntPoint(cpos.x, cpos.y);
|
1999-04-17 17:49:39 +04:00
|
|
|
} else {
|
2016-04-18 17:09:02 +03:00
|
|
|
event.mRefPoint = LayoutDeviceIntPoint(0, 0);
|
1999-04-17 17:49:39 +04:00
|
|
|
}
|
|
|
|
|
2012-06-15 13:52:50 +04:00
|
|
|
ModifierKeyState modifierKeyState;
|
2012-04-25 07:00:01 +04:00
|
|
|
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
|
|
|
|
2012-07-25 19:09:16 +04:00
|
|
|
mWidget->DispatchEvent(&event, status);
|
1999-04-06 23:39:21 +04:00
|
|
|
}
|
|
|
|
|
2005-03-15 03:07:46 +03:00
|
|
|
void
|
2015-08-26 15:56:59 +03:00
|
|
|
nsNativeDragTarget::ProcessDrag(EventMessage aEventMessage,
|
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
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t 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
|
2015-08-26 15:56:59 +03:00
|
|
|
DispatchDragDropEvent(aEventMessage, ptl);
|
1999-04-23 18:10:39 +04:00
|
|
|
|
2015-06-05 15:33:29 +03:00
|
|
|
// If TakeChildProcessDragAction returns something other than
|
|
|
|
// DRAGDROP_ACTION_UNINITIALIZED, it means that the last event was sent
|
|
|
|
// to the child process and this event is also being sent to the child
|
|
|
|
// process. In this case, use the last event's action instead.
|
|
|
|
nsDragService* dragService = static_cast<nsDragService *>(mDragService);
|
|
|
|
currSession->GetDragAction(&geckoAction);
|
|
|
|
|
|
|
|
int32_t childDragAction = dragService->TakeChildProcessDragAction();
|
|
|
|
if (childDragAction != nsIDragService::DRAGDROP_ACTION_UNINITIALIZED) {
|
|
|
|
geckoAction = childDragAction;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsIDragService::DRAGDROP_ACTION_LINK & geckoAction) {
|
|
|
|
*pdwEffect = DROPEFFECT_LINK;
|
|
|
|
}
|
|
|
|
else if (nsIDragService::DRAGDROP_ACTION_COPY & geckoAction) {
|
|
|
|
*pdwEffect = DROPEFFECT_COPY;
|
|
|
|
}
|
|
|
|
else if (nsIDragService::DRAGDROP_ACTION_MOVE & geckoAction) {
|
|
|
|
*pdwEffect = DROPEFFECT_MOVE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*pdwEffect = DROPEFFECT_NONE;
|
|
|
|
}
|
|
|
|
|
2015-09-02 09:08:01 +03:00
|
|
|
if (aEventMessage != eDrop) {
|
2011-09-01 17:48:48 +04:00
|
|
|
// Get the cached drag effect from the drag service, the data member should
|
2013-10-02 07:46:03 +04:00
|
|
|
// have been set by whoever handled the WidgetGUIEvent 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
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
void* tempOutData = nullptr;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t tempDataLen = 0;
|
2008-09-10 12:15:54 +04:00
|
|
|
nsresult loadResult = nsClipboard::GetNativeDataOffClipboard(
|
2012-07-30 18:20:58 +04:00
|
|
|
pIDataSource, 0, ::RegisterClipboardFormat(CFSTR_PREFERREDDROPEFFECT), nullptr, &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);
|
2015-03-27 03:01:12 +03:00
|
|
|
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
|
2015-09-02 09:08:02 +03:00
|
|
|
ProcessDrag(eDragEnter, 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
|
|
|
}
|
|
|
|
|
2015-09-02 09:08:02 +03:00
|
|
|
mDragService->FireDragEventAtSource(eDrag);
|
2010-06-02 17:02:05 +04:00
|
|
|
// Now process the native drag state and then dispatch the event
|
2015-09-02 09:08:02 +03:00
|
|
|
ProcessDrag(eDragOver, 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
|
2015-09-02 09:08:02 +03:00
|
|
|
DispatchDragDropEvent(eDragExit, gDragLastPoint);
|
2005-03-15 03:07:46 +03:00
|
|
|
|
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:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<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
|
2015-09-02 09:08:01 +03:00
|
|
|
ProcessDrag(eDrop, 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) {
|
2013-10-08 22:48:20 +04:00
|
|
|
CoCreateInstance(CLSID_DragDropHelper, nullptr, CLSCTX_INPROC_SERVER,
|
2012-02-01 18:30:05 +04:00
|
|
|
IID_IDropTargetHelper, (LPVOID*)&mDropTargetHelper);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mDropTargetHelper;
|
|
|
|
}
|