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-03-23 18:37:34 +03:00
|
|
|
|
2004-07-16 11:28:10 +04:00
|
|
|
#include <ole2.h>
|
|
|
|
#include <oleidl.h>
|
|
|
|
#include <shlobj.h>
|
2006-08-15 11:16:10 +04:00
|
|
|
#include <shlwapi.h>
|
2004-07-16 11:28:10 +04:00
|
|
|
|
|
|
|
// shellapi.h is needed to build with WIN32_LEAN_AND_MEAN
|
|
|
|
#include <shellapi.h>
|
|
|
|
|
1999-03-23 18:37:34 +03:00
|
|
|
#include "nsDragService.h"
|
|
|
|
#include "nsITransferable.h"
|
|
|
|
#include "nsDataObj.h"
|
1999-04-07 00:25:09 +04:00
|
|
|
|
|
|
|
#include "nsWidgetsCID.h"
|
1999-04-17 17:49:39 +04:00
|
|
|
#include "nsNativeDragTarget.h"
|
|
|
|
#include "nsNativeDragSource.h"
|
1999-04-07 00:25:09 +04:00
|
|
|
#include "nsClipboard.h"
|
1999-05-07 23:55:00 +04:00
|
|
|
#include "nsISupportsArray.h"
|
2004-12-07 17:13:54 +03:00
|
|
|
#include "nsIDocument.h"
|
1999-05-27 01:08:21 +04:00
|
|
|
#include "nsDataObjCollection.h"
|
1999-03-23 18:37:34 +03:00
|
|
|
|
2003-06-18 23:12:54 +04:00
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
|
2006-02-20 23:48:35 +03:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsEscape.h"
|
|
|
|
#include "nsISupportsPrimitives.h"
|
|
|
|
#include "nsIURL.h"
|
|
|
|
#include "nsCWebBrowserPersist.h"
|
|
|
|
#include "nsToolkit.h"
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsDirectoryServiceDefs.h"
|
|
|
|
#include "nsUnicharUtils.h"
|
2007-11-17 07:31:32 +03:00
|
|
|
#include "gfxContext.h"
|
2011-04-08 05:04:40 +04:00
|
|
|
#include "nsRect.h"
|
2007-11-17 07:31:32 +03:00
|
|
|
#include "nsMathUtils.h"
|
2013-04-01 13:10:09 +04:00
|
|
|
#include "gfxWindowsPlatform.h"
|
2014-01-29 04:10:33 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2014-03-07 22:15:51 +04:00
|
|
|
#include "mozilla/gfx/DataSurfaceHelpers.h"
|
|
|
|
#include "mozilla/gfx/Tools.h"
|
2014-01-29 04:10:33 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::gfx;
|
2006-02-20 23:48:35 +03:00
|
|
|
|
1999-03-23 18:37:34 +03:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// DragService constructor
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
nsDragService::nsDragService()
|
2012-07-30 18:20:58 +04:00
|
|
|
: mDataObject(nullptr), mSentLocalDropEvent(false)
|
1999-03-23 18:37:34 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// DragService destructor
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
nsDragService::~nsDragService()
|
|
|
|
{
|
1999-04-17 17:49:39 +04:00
|
|
|
NS_IF_RELEASE(mDataObject);
|
1999-03-23 18:37:34 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2007-11-17 07:31:32 +03:00
|
|
|
nsDragService::CreateDragImage(nsIDOMNode *aDOMNode,
|
|
|
|
nsIScriptableRegion *aRegion,
|
|
|
|
SHDRAGIMAGE *psdi)
|
|
|
|
{
|
|
|
|
if (!psdi)
|
2011-10-02 06:16:19 +04:00
|
|
|
return false;
|
2007-11-17 07:31:32 +03:00
|
|
|
|
|
|
|
memset(psdi, 0, sizeof(SHDRAGIMAGE));
|
|
|
|
if (!aDOMNode)
|
2011-10-02 06:16:19 +04:00
|
|
|
return false;
|
2007-11-17 07:31:32 +03:00
|
|
|
|
|
|
|
// Prepare the drag image
|
2009-01-15 06:27:09 +03:00
|
|
|
nsIntRect dragRect;
|
2015-10-18 07:40:10 +03:00
|
|
|
nsRefPtr<SourceSurface> surface;
|
2008-01-09 01:03:53 +03:00
|
|
|
nsPresContext* pc;
|
2007-11-17 07:31:32 +03:00
|
|
|
DrawDrag(aDOMNode, aRegion,
|
|
|
|
mScreenX, mScreenY,
|
2014-01-29 04:10:33 +04:00
|
|
|
&dragRect, &surface, &pc);
|
2007-11-17 07:31:32 +03:00
|
|
|
if (!surface)
|
2011-10-02 06:16:19 +04:00
|
|
|
return false;
|
2007-11-17 07:31:32 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t bmWidth = dragRect.width, bmHeight = dragRect.height;
|
2007-11-17 07:31:32 +03:00
|
|
|
|
|
|
|
if (bmWidth == 0 || bmHeight == 0)
|
2011-10-02 06:16:19 +04:00
|
|
|
return false;
|
2007-11-17 07:31:32 +03:00
|
|
|
|
|
|
|
psdi->crColorKey = CLR_NONE;
|
|
|
|
|
2015-10-18 07:40:10 +03:00
|
|
|
nsRefPtr<DataSourceSurface> dataSurface =
|
2014-03-07 22:15:51 +04:00
|
|
|
Factory::CreateDataSourceSurface(IntSize(bmWidth, bmHeight),
|
|
|
|
SurfaceFormat::B8G8R8A8);
|
|
|
|
NS_ENSURE_TRUE(dataSurface, false);
|
|
|
|
|
2014-01-29 04:10:33 +04:00
|
|
|
DataSourceSurface::MappedSurface map;
|
2014-03-07 22:15:51 +04:00
|
|
|
if (!dataSurface->Map(DataSourceSurface::MapType::READ_WRITE, &map)) {
|
2014-01-29 04:10:33 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-18 07:40:10 +03:00
|
|
|
nsRefPtr<DrawTarget> dt =
|
2014-03-07 22:15:51 +04:00
|
|
|
Factory::CreateDrawTargetForData(BackendType::CAIRO,
|
|
|
|
map.mData,
|
|
|
|
dataSurface->GetSize(),
|
|
|
|
map.mStride,
|
|
|
|
dataSurface->GetFormat());
|
|
|
|
if (!dt) {
|
|
|
|
dataSurface->Unmap();
|
2011-10-02 06:16:19 +04:00
|
|
|
return false;
|
2014-03-07 22:15:51 +04:00
|
|
|
}
|
2007-11-17 07:31:32 +03:00
|
|
|
|
2014-03-07 22:15:51 +04:00
|
|
|
dt->DrawSurface(surface,
|
|
|
|
Rect(0, 0, dataSurface->GetSize().width, dataSurface->GetSize().height),
|
|
|
|
Rect(0, 0, surface->GetSize().width, surface->GetSize().height),
|
|
|
|
DrawSurfaceOptions(),
|
|
|
|
DrawOptions(1.0f, CompositionOp::OP_SOURCE));
|
|
|
|
dt->Flush();
|
2007-11-17 07:31:32 +03:00
|
|
|
|
|
|
|
BITMAPV5HEADER bmih;
|
|
|
|
memset((void*)&bmih, 0, sizeof(BITMAPV5HEADER));
|
|
|
|
bmih.bV5Size = sizeof(BITMAPV5HEADER);
|
|
|
|
bmih.bV5Width = bmWidth;
|
2012-08-22 19:56:38 +04:00
|
|
|
bmih.bV5Height = -(int32_t)bmHeight; // flip vertical
|
2007-11-17 07:31:32 +03:00
|
|
|
bmih.bV5Planes = 1;
|
|
|
|
bmih.bV5BitCount = 32;
|
|
|
|
bmih.bV5Compression = BI_BITFIELDS;
|
|
|
|
bmih.bV5RedMask = 0x00FF0000;
|
|
|
|
bmih.bV5GreenMask = 0x0000FF00;
|
|
|
|
bmih.bV5BlueMask = 0x000000FF;
|
|
|
|
bmih.bV5AlphaMask = 0xFF000000;
|
|
|
|
|
2013-10-08 22:48:02 +04:00
|
|
|
HDC hdcSrc = CreateCompatibleDC(nullptr);
|
|
|
|
void *lpBits = nullptr;
|
2007-11-17 07:31:32 +03:00
|
|
|
if (hdcSrc) {
|
|
|
|
psdi->hbmpDragImage =
|
|
|
|
::CreateDIBSection(hdcSrc, (BITMAPINFO*)&bmih, DIB_RGB_COLORS,
|
2013-10-08 22:48:02 +04:00
|
|
|
(void**)&lpBits, nullptr, 0);
|
2007-11-17 07:31:32 +03:00
|
|
|
if (psdi->hbmpDragImage && lpBits) {
|
2014-03-07 22:15:51 +04:00
|
|
|
CopySurfaceDataToPackedArray(map.mData, static_cast<uint8_t*>(lpBits),
|
|
|
|
dataSurface->GetSize(), map.mStride,
|
|
|
|
BytesPerPixel(dataSurface->GetFormat()));
|
2007-11-17 07:31:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
psdi->sizeDragImage.cx = bmWidth;
|
|
|
|
psdi->sizeDragImage.cy = bmHeight;
|
|
|
|
|
|
|
|
// Mouse position in center
|
|
|
|
if (mScreenX == -1 || mScreenY == -1) {
|
2012-08-22 19:56:38 +04:00
|
|
|
psdi->ptOffset.x = (uint32_t)((float)bmWidth/2.0f);
|
|
|
|
psdi->ptOffset.y = (uint32_t)((float)bmHeight/2.0f);
|
2007-11-17 07:31:32 +03:00
|
|
|
} else {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t sx = mScreenX, sy = mScreenY;
|
2008-01-09 01:03:53 +03:00
|
|
|
ConvertToUnscaledDevPixels(pc, &sx, &sy);
|
|
|
|
psdi->ptOffset.x = sx - dragRect.x;
|
|
|
|
psdi->ptOffset.y = sy - dragRect.y;
|
2007-11-17 07:31:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
DeleteDC(hdcSrc);
|
|
|
|
}
|
|
|
|
|
2014-03-07 22:15:51 +04:00
|
|
|
dataSurface->Unmap();
|
2014-01-29 04:10:33 +04:00
|
|
|
|
2013-10-08 22:48:02 +04:00
|
|
|
return psdi->hbmpDragImage != nullptr;
|
2007-11-17 07:31:32 +03:00
|
|
|
}
|
1999-08-25 12:35:06 +04:00
|
|
|
|
1999-05-07 23:55:00 +04:00
|
|
|
//-------------------------------------------------------------------------
|
2005-03-15 03:26:15 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDragService::InvokeDragSession(nsIDOMNode *aDOMNode,
|
|
|
|
nsISupportsArray *anArrayTransferables,
|
|
|
|
nsIScriptableRegion *aRegion,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aActionType)
|
1999-05-07 23:55:00 +04:00
|
|
|
{
|
2008-03-19 23:18:41 +03:00
|
|
|
nsresult rv = nsBaseDragService::InvokeDragSession(aDOMNode,
|
|
|
|
anArrayTransferables,
|
|
|
|
aRegion,
|
|
|
|
aActionType);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2004-12-07 17:13:54 +03:00
|
|
|
|
|
|
|
// Try and get source URI of the items that are being dragged
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIURI *uri = nullptr;
|
2004-12-07 17:13:54 +03:00
|
|
|
|
2005-01-28 23:01:46 +03:00
|
|
|
nsCOMPtr<nsIDocument> doc(do_QueryInterface(mSourceDocument));
|
|
|
|
if (doc) {
|
|
|
|
uri = doc->GetDocumentURI();
|
2004-12-07 17:13:54 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t numItemsToDrag = 0;
|
2000-06-05 04:34:11 +04:00
|
|
|
rv = anArrayTransferables->Count(&numItemsToDrag);
|
2005-03-15 03:26:15 +03:00
|
|
|
if (!numItemsToDrag)
|
1999-05-07 23:55:00 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2005-03-15 03:26:15 +03:00
|
|
|
// The clipboard class contains some static utility methods that we
|
|
|
|
// can use to create an IDataObject from the transferable
|
1999-05-07 23:55:00 +04:00
|
|
|
|
2005-03-15 03:26:15 +03:00
|
|
|
// if we're dragging more than one item, we need to create a
|
|
|
|
// "collection" object to fake out the OS. This collection contains
|
2011-09-09 05:04:12 +04:00
|
|
|
// one |IDataObject| for each transferable. If there is just the one
|
2005-03-15 03:26:15 +03:00
|
|
|
// (most cases), only pass around the native |IDataObject|.
|
2003-06-18 23:12:54 +04:00
|
|
|
nsRefPtr<IDataObject> itemToDrag;
|
2005-03-15 03:26:15 +03:00
|
|
|
if (numItemsToDrag > 1) {
|
2000-06-05 04:34:11 +04:00
|
|
|
nsDataObjCollection * dataObjCollection = new nsDataObjCollection();
|
2003-06-18 23:12:54 +04:00
|
|
|
if (!dataObjCollection)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
itemToDrag = dataObjCollection;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i=0; i<numItemsToDrag; ++i) {
|
2000-06-05 04:34:11 +04:00
|
|
|
nsCOMPtr<nsISupports> supports;
|
|
|
|
anArrayTransferables->GetElementAt(i, getter_AddRefs(supports));
|
|
|
|
nsCOMPtr<nsITransferable> trans(do_QueryInterface(supports));
|
2005-03-15 03:26:15 +03:00
|
|
|
if (trans) {
|
2014-09-21 20:41:56 +04:00
|
|
|
// set the requestingNode on the transferable
|
|
|
|
trans->SetRequestingNode(aDOMNode);
|
2003-06-18 23:12:54 +04:00
|
|
|
nsRefPtr<IDataObject> dataObj;
|
2005-03-15 03:26:15 +03:00
|
|
|
rv = nsClipboard::CreateNativeDataObject(trans,
|
|
|
|
getter_AddRefs(dataObj), uri);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-02-20 16:44:02 +03:00
|
|
|
// Add the flavors to the collection object too
|
|
|
|
rv = nsClipboard::SetupNativeDataObject(trans, dataObjCollection);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2005-03-15 03:26:15 +03:00
|
|
|
|
|
|
|
dataObjCollection->AddDataObject(dataObj);
|
2000-06-05 04:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} // if dragging multiple items
|
|
|
|
else {
|
1999-08-25 12:35:06 +04:00
|
|
|
nsCOMPtr<nsISupports> supports;
|
2000-06-05 04:34:11 +04:00
|
|
|
anArrayTransferables->GetElementAt(0, getter_AddRefs(supports));
|
1999-05-07 23:55:00 +04:00
|
|
|
nsCOMPtr<nsITransferable> trans(do_QueryInterface(supports));
|
2005-03-15 03:26:15 +03:00
|
|
|
if (trans) {
|
2014-09-21 20:41:56 +04:00
|
|
|
// set the requestingNode on the transferable
|
|
|
|
trans->SetRequestingNode(aDOMNode);
|
2005-03-15 03:26:15 +03:00
|
|
|
rv = nsClipboard::CreateNativeDataObject(trans,
|
|
|
|
getter_AddRefs(itemToDrag),
|
|
|
|
uri);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1999-08-25 12:35:06 +04:00
|
|
|
}
|
2000-06-05 04:34:11 +04:00
|
|
|
} // else dragging a single object
|
2005-03-15 03:26:15 +03:00
|
|
|
|
2007-11-17 07:31:32 +03:00
|
|
|
// Create a drag image if support is available
|
|
|
|
IDragSourceHelper *pdsh;
|
2013-10-08 22:48:02 +04:00
|
|
|
if (SUCCEEDED(CoCreateInstance(CLSID_DragDropHelper, nullptr,
|
|
|
|
CLSCTX_INPROC_SERVER,
|
2007-11-17 07:31:32 +03:00
|
|
|
IID_IDragSourceHelper, (void**)&pdsh))) {
|
|
|
|
SHDRAGIMAGE sdi;
|
|
|
|
if (CreateDragImage(aDOMNode, aRegion, &sdi)) {
|
|
|
|
if (FAILED(pdsh->InitializeFromBitmap(&sdi, itemToDrag)))
|
|
|
|
DeleteObject(sdi.hbmpDragImage);
|
|
|
|
}
|
|
|
|
pdsh->Release();
|
|
|
|
}
|
|
|
|
|
2006-02-20 23:48:35 +03:00
|
|
|
// Kick off the native drag session
|
2006-08-15 11:16:10 +04:00
|
|
|
return StartInvokingDragSession(itemToDrag, aActionType);
|
1999-05-07 23:55:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
2005-03-15 03:26:15 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDragService::StartInvokingDragSession(IDataObject * aDataObj,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aActionType)
|
1999-05-07 23:55:00 +04:00
|
|
|
{
|
2005-03-15 03:26:15 +03:00
|
|
|
// To do the drag we need to create an object that
|
1999-04-23 18:35:26 +04:00
|
|
|
// implements the IDataObject interface (for OLE)
|
2012-05-11 22:32:08 +04:00
|
|
|
nsRefPtr<nsNativeDragSource> nativeDragSrc =
|
|
|
|
new nsNativeDragSource(mDataTransfer);
|
1999-04-17 17:49:39 +04:00
|
|
|
|
1999-04-23 18:35:26 +04:00
|
|
|
// Now figure out what the native drag effect should be
|
2008-09-29 00:57:33 +04:00
|
|
|
DWORD winDropRes;
|
1999-04-17 17:49:39 +04:00
|
|
|
DWORD effects = DROPEFFECT_SCROLL;
|
|
|
|
if (aActionType & DRAGDROP_ACTION_COPY) {
|
|
|
|
effects |= DROPEFFECT_COPY;
|
|
|
|
}
|
|
|
|
if (aActionType & DRAGDROP_ACTION_MOVE) {
|
|
|
|
effects |= DROPEFFECT_MOVE;
|
|
|
|
}
|
|
|
|
if (aActionType & DRAGDROP_ACTION_LINK) {
|
|
|
|
effects |= DROPEFFECT_LINK;
|
|
|
|
}
|
|
|
|
|
2005-03-15 03:26:15 +03:00
|
|
|
// XXX not sure why we bother to cache this, it can change during
|
|
|
|
// the drag
|
|
|
|
mDragAction = aActionType;
|
2011-10-02 06:16:19 +04:00
|
|
|
mSentLocalDropEvent = false;
|
1999-04-23 18:35:26 +04:00
|
|
|
|
2005-03-16 03:40:21 +03:00
|
|
|
// Start dragging
|
|
|
|
StartDragSession();
|
2011-04-26 05:37:20 +04:00
|
|
|
OpenDragPopup();
|
2005-03-16 03:40:21 +03:00
|
|
|
|
2010-10-20 01:21:10 +04:00
|
|
|
nsRefPtr<IAsyncOperation> pAsyncOp;
|
|
|
|
// Offer to do an async drag
|
|
|
|
if (SUCCEEDED(aDataObj->QueryInterface(IID_IAsyncOperation,
|
|
|
|
getter_AddRefs(pAsyncOp)))) {
|
|
|
|
pAsyncOp->SetAsyncMode(VARIANT_TRUE);
|
|
|
|
} else {
|
|
|
|
NS_NOTREACHED("When did our data object stop being async");
|
2006-08-15 11:16:10 +04:00
|
|
|
}
|
|
|
|
|
1999-04-23 18:35:26 +04:00
|
|
|
// Call the native D&D method
|
2012-05-11 22:32:08 +04:00
|
|
|
HRESULT res = ::DoDragDrop(aDataObj, nativeDragSrc, effects, &winDropRes);
|
1999-05-07 23:55:00 +04:00
|
|
|
|
2008-09-29 00:57:33 +04:00
|
|
|
// In cases where the drop operation completed outside the application, update
|
2012-02-07 22:02:32 +04:00
|
|
|
// the source node's nsIDOMDataTransfer dropEffect value so it is up to date.
|
2008-09-29 00:57:33 +04:00
|
|
|
if (!mSentLocalDropEvent) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t dropResult;
|
2008-09-29 00:57:33 +04:00
|
|
|
// Order is important, since multiple flags can be returned.
|
|
|
|
if (winDropRes & DROPEFFECT_COPY)
|
|
|
|
dropResult = DRAGDROP_ACTION_COPY;
|
|
|
|
else if (winDropRes & DROPEFFECT_LINK)
|
|
|
|
dropResult = DRAGDROP_ACTION_LINK;
|
|
|
|
else if (winDropRes & DROPEFFECT_MOVE)
|
|
|
|
dropResult = DRAGDROP_ACTION_MOVE;
|
|
|
|
else
|
|
|
|
dropResult = DRAGDROP_ACTION_NONE;
|
|
|
|
|
2012-02-07 22:02:32 +04:00
|
|
|
if (mDataTransfer) {
|
2008-09-29 00:57:33 +04:00
|
|
|
if (res == DRAGDROP_S_DROP) // Success
|
2012-02-07 22:02:32 +04:00
|
|
|
mDataTransfer->SetDropEffectInt(dropResult);
|
2008-09-29 00:57:33 +04:00
|
|
|
else
|
2012-02-07 22:02:32 +04:00
|
|
|
mDataTransfer->SetDropEffectInt(DRAGDROP_ACTION_NONE);
|
2008-09-29 00:57:33 +04:00
|
|
|
}
|
|
|
|
}
|
2009-02-17 18:51:12 +03:00
|
|
|
|
2012-05-11 22:32:08 +04:00
|
|
|
mUserCancelled = nativeDragSrc->UserCancelled();
|
2009-02-17 18:51:12 +03:00
|
|
|
|
2009-04-13 17:00:29 +04:00
|
|
|
// We're done dragging, get the cursor position and end the drag
|
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)
|
2013-04-01 13:10:09 +04:00
|
|
|
// Note that we must convert this from device pixels back to Windows logical
|
|
|
|
// pixels (bug 818927).
|
2009-08-11 01:29:41 +04:00
|
|
|
DWORD pos = ::GetMessagePos();
|
2013-04-01 13:10:28 +04:00
|
|
|
FLOAT dpiScale = gfxWindowsPlatform::GetPlatform()->GetDPIScale();
|
|
|
|
nsIntPoint logPos(NSToIntRound(GET_X_LPARAM(pos) / dpiScale),
|
|
|
|
NSToIntRound(GET_Y_LPARAM(pos) / dpiScale));
|
2013-04-01 13:10:09 +04:00
|
|
|
SetDragEndPoint(logPos);
|
2011-10-02 06:16:19 +04:00
|
|
|
EndDragSession(true);
|
2005-03-16 03:40:21 +03:00
|
|
|
|
2011-10-02 06:16:19 +04:00
|
|
|
mDoingDrag = false;
|
1999-04-17 17:49:39 +04:00
|
|
|
|
2005-03-15 03:26:15 +03:00
|
|
|
return DRAGDROP_S_DROP == res ? NS_OK : NS_ERROR_FAILURE;
|
1999-04-17 17:49:39 +04:00
|
|
|
}
|
|
|
|
|
2002-06-14 15:28:13 +04:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
// Make Sure we have the right kind of object
|
2005-03-15 03:26:15 +03:00
|
|
|
nsDataObjCollection*
|
|
|
|
nsDragService::GetDataObjCollection(IDataObject* aDataObj)
|
2002-06-14 15:28:13 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
nsDataObjCollection * dataObjCol = nullptr;
|
2002-06-14 15:28:13 +04:00
|
|
|
if (aDataObj) {
|
|
|
|
nsIDataObjCollection* dataObj;
|
2005-03-15 03:26:15 +03:00
|
|
|
if (aDataObj->QueryInterface(IID_IDataObjCollection,
|
|
|
|
(void**)&dataObj) == S_OK) {
|
2007-07-08 11:08:04 +04:00
|
|
|
dataObjCol = static_cast<nsDataObjCollection*>(aDataObj);
|
2002-06-14 15:28:13 +04:00
|
|
|
dataObj->Release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return dataObjCol;
|
|
|
|
}
|
|
|
|
|
1999-04-17 17:49:39 +04:00
|
|
|
//-------------------------------------------------------------------------
|
2005-03-15 03:26:15 +03:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsDragService::GetNumDropItems(uint32_t * aNumItems)
|
1999-05-27 01:08:21 +04:00
|
|
|
{
|
2005-03-15 03:26:15 +03:00
|
|
|
if (!mDataObject) {
|
2002-03-21 05:50:59 +03:00
|
|
|
*aNumItems = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-03-15 03:26:15 +03:00
|
|
|
if (IsCollectionObject(mDataObject)) {
|
2002-06-14 15:28:13 +04:00
|
|
|
nsDataObjCollection * dataObjCol = GetDataObjCollection(mDataObject);
|
2011-09-09 05:04:12 +04:00
|
|
|
if (dataObjCol) {
|
2000-04-26 05:04:13 +04:00
|
|
|
*aNumItems = dataObjCol->GetNumDataObjects();
|
2011-09-09 05:04:12 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// If the count cannot be determined just return 0.
|
|
|
|
// This can happen if we have collection data of type
|
|
|
|
// MULTI_MIME ("Mozilla/IDataObjectCollectionFormat") on the clipboard
|
|
|
|
// from another process but we can't obtain an IID_IDataObjCollection
|
|
|
|
// from this process.
|
|
|
|
*aNumItems = 0;
|
|
|
|
}
|
2000-04-26 05:04:13 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Next check if we have a file drop. Return the number of files in
|
|
|
|
// the file drop as the number of items we have, pretending like we
|
|
|
|
// actually have > 1 drag item.
|
|
|
|
FORMATETC fe2;
|
|
|
|
SET_FORMATETC(fe2, CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL);
|
2005-03-15 03:26:15 +03:00
|
|
|
if (mDataObject->QueryGetData(&fe2) == S_OK) {
|
2000-04-26 05:04:13 +04:00
|
|
|
STGMEDIUM stm;
|
2005-03-15 03:26:15 +03:00
|
|
|
if (mDataObject->GetData(&fe2, &stm) == S_OK) {
|
|
|
|
HDROP hdrop = (HDROP)GlobalLock(stm.hGlobal);
|
2013-10-08 22:48:02 +04:00
|
|
|
*aNumItems = ::DragQueryFileW(hdrop, 0xFFFFFFFF, nullptr, 0);
|
2000-04-26 05:04:13 +04:00
|
|
|
::GlobalUnlock(stm.hGlobal);
|
|
|
|
::ReleaseStgMedium(&stm);
|
2012-07-09 01:12:42 +04:00
|
|
|
// Data may be provided later, so assume we have 1 item
|
|
|
|
if (*aNumItems == 0)
|
|
|
|
*aNumItems = 1;
|
2000-04-26 05:04:13 +04:00
|
|
|
}
|
2009-09-30 00:39:16 +04:00
|
|
|
else
|
|
|
|
*aNumItems = 1;
|
2000-04-26 05:04:13 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
*aNumItems = 1;
|
1999-05-27 01:08:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
2005-03-15 03:26:15 +03:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsDragService::GetData(nsITransferable * aTransferable, uint32_t anItem)
|
1999-03-23 18:37:34 +03:00
|
|
|
{
|
1999-04-23 18:35:26 +04:00
|
|
|
// This typcially happens on a drop, the target would be asking
|
|
|
|
// for it's transferable to be filled in
|
1999-05-27 01:08:21 +04:00
|
|
|
// Use a static clipboard utility method for this
|
2005-03-15 03:26:15 +03:00
|
|
|
if (!mDataObject)
|
1999-05-27 01:08:21 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2001-01-06 02:47:09 +03:00
|
|
|
nsresult dataFound = NS_ERROR_FAILURE;
|
|
|
|
|
2005-03-15 03:26:15 +03:00
|
|
|
if (IsCollectionObject(mDataObject)) {
|
2000-06-05 04:34:11 +04:00
|
|
|
// multiple items, use |anItem| as an index into our collection
|
2002-06-14 15:28:13 +04:00
|
|
|
nsDataObjCollection * dataObjCol = GetDataObjCollection(mDataObject);
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t cnt = dataObjCol->GetNumDataObjects();
|
2014-09-02 13:07:25 +04:00
|
|
|
if (anItem < cnt) {
|
2000-02-02 01:26:21 +03:00
|
|
|
IDataObject * dataObj = dataObjCol->GetDataObjectAt(anItem);
|
2012-07-30 18:20:58 +04:00
|
|
|
dataFound = nsClipboard::GetDataFromDataObject(dataObj, 0, nullptr,
|
2005-03-15 03:26:15 +03:00
|
|
|
aTransferable);
|
2000-02-02 01:26:21 +03:00
|
|
|
}
|
2001-01-06 02:47:09 +03:00
|
|
|
else
|
2005-03-15 03:26:15 +03:00
|
|
|
NS_WARNING("Index out of range!");
|
1999-05-27 01:08:21 +04:00
|
|
|
}
|
2000-06-05 04:34:11 +04:00
|
|
|
else {
|
2001-01-06 02:47:09 +03:00
|
|
|
// If they are asking for item "0", we can just get it...
|
2005-03-15 03:26:15 +03:00
|
|
|
if (anItem == 0) {
|
|
|
|
dataFound = nsClipboard::GetDataFromDataObject(mDataObject, anItem,
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr, aTransferable);
|
2005-03-15 03:26:15 +03:00
|
|
|
} else {
|
2001-01-06 02:47:09 +03:00
|
|
|
// It better be a file drop, or else non-zero indexes are invalid!
|
|
|
|
FORMATETC fe2;
|
|
|
|
SET_FORMATETC(fe2, CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL);
|
2005-03-15 03:26:15 +03:00
|
|
|
if (mDataObject->QueryGetData(&fe2) == S_OK)
|
|
|
|
dataFound = nsClipboard::GetDataFromDataObject(mDataObject, anItem,
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr, aTransferable);
|
2001-01-06 02:47:09 +03:00
|
|
|
else
|
2005-03-15 03:26:15 +03:00
|
|
|
NS_WARNING("Reqesting non-zero index, but clipboard data is not a collection!");
|
2001-01-06 02:47:09 +03:00
|
|
|
}
|
2000-06-05 04:34:11 +04:00
|
|
|
}
|
2001-01-06 02:47:09 +03:00
|
|
|
return dataFound;
|
1999-03-23 18:37:34 +03:00
|
|
|
}
|
|
|
|
|
1999-04-17 17:49:39 +04:00
|
|
|
//---------------------------------------------------------
|
2005-03-15 03:26:15 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDragService::SetIDataObject(IDataObject * aDataObj)
|
1999-04-17 17:49:39 +04:00
|
|
|
{
|
2005-03-15 03:26:15 +03:00
|
|
|
// When the native drag starts the DragService gets
|
1999-05-27 01:08:21 +04:00
|
|
|
// the IDataObject that is being dragged
|
1999-04-17 17:49:39 +04:00
|
|
|
NS_IF_RELEASE(mDataObject);
|
|
|
|
mDataObject = aDataObj;
|
2000-10-07 04:11:28 +04:00
|
|
|
NS_IF_ADDREF(mDataObject);
|
1999-04-23 18:35:26 +04:00
|
|
|
|
1999-04-17 17:49:39 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-05-07 23:55:00 +04:00
|
|
|
|
2008-09-29 00:57:33 +04:00
|
|
|
//---------------------------------------------------------
|
|
|
|
void
|
|
|
|
nsDragService::SetDroppedLocal()
|
|
|
|
{
|
|
|
|
// Sent from the native drag handler, letting us know
|
2010-05-13 16:19:50 +04:00
|
|
|
// a drop occurred within the application vs. outside of it.
|
2011-10-02 06:16:19 +04:00
|
|
|
mSentLocalDropEvent = true;
|
2008-09-29 00:57:33 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-05-07 23:55:00 +04:00
|
|
|
//-------------------------------------------------------------------------
|
2005-03-15 03:26:15 +03:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsDragService::IsDataFlavorSupported(const char *aDataFlavor, bool *_retval)
|
1999-05-07 23:55:00 +04:00
|
|
|
{
|
2005-03-15 03:26:15 +03:00
|
|
|
if (!aDataFlavor || !mDataObject || !_retval)
|
1999-05-07 23:55:00 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2012-06-25 23:59:42 +04:00
|
|
|
#ifdef DEBUG
|
2005-03-15 03:26:15 +03:00
|
|
|
if (strcmp(aDataFlavor, kTextMime) == 0)
|
|
|
|
NS_WARNING("DO NOT USE THE text/plain DATA FLAVOR ANY MORE. USE text/unicode INSTEAD");
|
2000-02-02 01:26:21 +03:00
|
|
|
#endif
|
|
|
|
|
2011-10-02 06:16:19 +04:00
|
|
|
*_retval = false;
|
2000-02-02 01:26:21 +03:00
|
|
|
|
1999-05-27 01:08:21 +04:00
|
|
|
FORMATETC fe;
|
2000-06-05 04:34:11 +04:00
|
|
|
UINT format = 0;
|
2005-03-15 03:26:15 +03:00
|
|
|
|
|
|
|
if (IsCollectionObject(mDataObject)) {
|
2000-02-02 01:26:21 +03:00
|
|
|
// We know we have one of our special collection objects.
|
1999-08-25 12:35:06 +04:00
|
|
|
format = nsClipboard::GetFormat(aDataFlavor);
|
2005-03-15 03:26:15 +03:00
|
|
|
SET_FORMATETC(fe, format, 0, DVASPECT_CONTENT, -1,
|
|
|
|
TYMED_HGLOBAL | TYMED_FILE | TYMED_GDI);
|
1999-05-07 23:55:00 +04:00
|
|
|
|
2005-03-15 03:26:15 +03:00
|
|
|
// See if any one of the IDataObjects in the collection supports
|
|
|
|
// this data type
|
2002-06-14 15:28:13 +04:00
|
|
|
nsDataObjCollection* dataObjCol = GetDataObjCollection(mDataObject);
|
2005-03-15 03:26:15 +03:00
|
|
|
if (dataObjCol) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t cnt = dataObjCol->GetNumDataObjects();
|
|
|
|
for (uint32_t i=0;i<cnt;++i) {
|
2000-02-02 01:26:21 +03:00
|
|
|
IDataObject * dataObj = dataObjCol->GetDataObjectAt(i);
|
|
|
|
if (S_OK == dataObj->QueryGetData(&fe))
|
2011-10-02 06:16:19 +04:00
|
|
|
*_retval = true; // found it!
|
2000-02-02 01:26:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} // if special collection object
|
|
|
|
else {
|
2005-03-15 03:26:15 +03:00
|
|
|
// Ok, so we have a single object. Check to see if has the correct
|
|
|
|
// data type. Since this can come from an outside app, we also
|
|
|
|
// need to see if we need to perform text->unicode conversion if
|
|
|
|
// the client asked for unicode and it wasn't available.
|
2000-02-02 01:26:21 +03:00
|
|
|
format = nsClipboard::GetFormat(aDataFlavor);
|
2005-03-15 03:26:15 +03:00
|
|
|
SET_FORMATETC(fe, format, 0, DVASPECT_CONTENT, -1,
|
|
|
|
TYMED_HGLOBAL | TYMED_FILE | TYMED_GDI);
|
2014-04-24 22:48:14 +04:00
|
|
|
if (mDataObject->QueryGetData(&fe) == S_OK)
|
2011-10-02 06:16:19 +04:00
|
|
|
*_retval = true; // found it!
|
2000-02-02 01:26:21 +03:00
|
|
|
else {
|
2005-03-15 03:26:15 +03:00
|
|
|
// We haven't found the exact flavor the client asked for, but
|
|
|
|
// maybe we can still find it from something else that's on the
|
|
|
|
// clipboard
|
|
|
|
if (strcmp(aDataFlavor, kUnicodeMime) == 0) {
|
|
|
|
// client asked for unicode and it wasn't present, check if we
|
|
|
|
// have CF_TEXT. We'll handle the actual data substitution in
|
|
|
|
// the data object.
|
2000-08-03 04:47:36 +04:00
|
|
|
format = nsClipboard::GetFormat(kTextMime);
|
2005-03-15 03:26:15 +03:00
|
|
|
SET_FORMATETC(fe, format, 0, DVASPECT_CONTENT, -1,
|
|
|
|
TYMED_HGLOBAL | TYMED_FILE | TYMED_GDI);
|
2014-04-24 22:48:14 +04:00
|
|
|
if (mDataObject->QueryGetData(&fe) == S_OK)
|
2011-10-02 06:16:19 +04:00
|
|
|
*_retval = true; // found it!
|
2000-08-03 04:47:36 +04:00
|
|
|
}
|
2005-03-15 03:26:15 +03:00
|
|
|
else if (strcmp(aDataFlavor, kURLMime) == 0) {
|
|
|
|
// client asked for a url and it wasn't present, but if we
|
|
|
|
// have a file, then we have a URL to give them (the path, or
|
|
|
|
// the internal URL if an InternetShortcut).
|
2000-08-03 04:47:36 +04:00
|
|
|
format = nsClipboard::GetFormat(kFileMime);
|
2005-03-15 03:26:15 +03:00
|
|
|
SET_FORMATETC(fe, format, 0, DVASPECT_CONTENT, -1,
|
|
|
|
TYMED_HGLOBAL | TYMED_FILE | TYMED_GDI);
|
2014-04-24 22:48:14 +04:00
|
|
|
if (mDataObject->QueryGetData(&fe) == S_OK)
|
2011-10-02 06:16:19 +04:00
|
|
|
*_retval = true; // found it!
|
2000-08-03 04:47:36 +04:00
|
|
|
}
|
2000-02-02 01:26:21 +03:00
|
|
|
} // else try again
|
1999-05-07 23:55:00 +04:00
|
|
|
}
|
|
|
|
|
1999-08-26 02:04:02 +04:00
|
|
|
return NS_OK;
|
1999-05-07 23:55:00 +04:00
|
|
|
}
|
|
|
|
|
2000-06-05 04:34:11 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// IsCollectionObject
|
|
|
|
//
|
2005-03-15 03:26:15 +03:00
|
|
|
// Determine if this is a single |IDataObject| or one of our private
|
|
|
|
// collection objects. We know the difference because our collection
|
|
|
|
// object will respond to supporting the private |MULTI_MIME| format.
|
2000-06-05 04:34:11 +04:00
|
|
|
//
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2005-03-15 03:26:15 +03:00
|
|
|
nsDragService::IsCollectionObject(IDataObject* inDataObj)
|
2000-06-05 04:34:11 +04:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isCollection = false;
|
2005-03-15 03:26:15 +03:00
|
|
|
|
|
|
|
// setup the format object to ask for the MULTI_MIME format. We only
|
|
|
|
// need to do this once
|
2000-06-05 04:34:11 +04:00
|
|
|
static UINT sFormat = 0;
|
|
|
|
static FORMATETC sFE;
|
2005-03-15 03:26:15 +03:00
|
|
|
if (!sFormat) {
|
2000-06-05 04:34:11 +04:00
|
|
|
sFormat = nsClipboard::GetFormat(MULTI_MIME);
|
|
|
|
SET_FORMATETC(sFE, sFormat, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL);
|
|
|
|
}
|
2005-03-15 03:26:15 +03:00
|
|
|
|
|
|
|
// ask the object if it supports it. If yes, we have a collection
|
|
|
|
// object
|
|
|
|
if (inDataObj->QueryGetData(&sFE) == S_OK)
|
2011-10-02 06:16:19 +04:00
|
|
|
isCollection = true;
|
2000-06-05 04:34:11 +04:00
|
|
|
|
|
|
|
return isCollection;
|
|
|
|
|
2000-06-16 04:32:17 +04:00
|
|
|
} // IsCollectionObject
|
2000-10-07 04:11:28 +04:00
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// EndDragSession
|
|
|
|
//
|
2005-03-15 03:26:15 +03:00
|
|
|
// Override the default to make sure that we release the data object
|
|
|
|
// when the drag ends. It seems that OLE doesn't like to let apps quit
|
|
|
|
// w/out crashing when we're still holding onto their data
|
2000-10-07 04:11:28 +04:00
|
|
|
//
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsDragService::EndDragSession(bool aDoneDrag)
|
2000-10-07 04:11:28 +04:00
|
|
|
{
|
2014-04-23 20:35:00 +04:00
|
|
|
// Bug 100180: If we've got mouse events captured, make sure we release it -
|
|
|
|
// that way, if we happen to call EndDragSession before diving into a nested
|
|
|
|
// event loop, we can still respond to mouse events.
|
|
|
|
if (::GetCapture()) {
|
|
|
|
::ReleaseCapture();
|
|
|
|
}
|
|
|
|
|
2007-04-12 08:37:39 +04:00
|
|
|
nsBaseDragService::EndDragSession(aDoneDrag);
|
2000-10-07 04:11:28 +04:00
|
|
|
NS_IF_RELEASE(mDataObject);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|