2008-08-27 05:07:27 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2008-08-27 05:07:27 -07:00
|
|
|
|
|
|
|
#ifndef nsDOMDataTransfer_h__
|
|
|
|
#define nsDOMDataTransfer_h__
|
|
|
|
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsIVariant.h"
|
|
|
|
#include "nsIPrincipal.h"
|
|
|
|
#include "nsIDOMDataTransfer.h"
|
|
|
|
#include "nsIDragService.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
|
2009-07-30 14:02:08 -07:00
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsIFile.h"
|
|
|
|
#include "nsDOMFile.h"
|
|
|
|
|
2008-08-27 05:07:27 -07:00
|
|
|
class nsITransferable;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* TransferItem is used to hold data for a particular format. Each piece of
|
|
|
|
* data has a principal set from the caller which added it. This allows a
|
|
|
|
* caller that wishes to retrieve the data to only be able to access the data
|
|
|
|
* it is allowed to, yet still allow a chrome caller to retrieve any of the
|
|
|
|
* data.
|
|
|
|
*/
|
|
|
|
struct TransferItem {
|
|
|
|
nsString mFormat;
|
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
|
|
|
nsCOMPtr<nsIVariant> mData;
|
|
|
|
};
|
|
|
|
|
2012-02-07 10:02:32 -08:00
|
|
|
class nsDOMDataTransfer : public nsIDOMDataTransfer
|
2008-08-27 05:07:27 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_NSIDOMDATATRANSFER
|
|
|
|
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsDOMDataTransfer, nsIDOMDataTransfer)
|
|
|
|
|
|
|
|
friend class nsDOMDragEvent;
|
|
|
|
friend class nsEventStateManager;
|
2009-06-24 10:12:33 -07:00
|
|
|
friend class nsContentUtils;
|
2008-08-27 05:07:27 -07:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
// the constructors are protected so only our friends can call them
|
|
|
|
|
|
|
|
// default constructor used for the dragstart/draggesture event and
|
|
|
|
// synthetic events
|
|
|
|
nsDOMDataTransfer();
|
|
|
|
|
|
|
|
// this constructor must only be used to create a dataTransfer for a drag
|
|
|
|
// that was started without using a data transfer, either an external drag,
|
|
|
|
// that is, a drag where the source is another application, or a drag
|
|
|
|
// started by calling the drag service directly.
|
2010-11-24 10:31:24 -08:00
|
|
|
nsDOMDataTransfer(PRUint32 aEventType);
|
2008-08-27 05:07:27 -07:00
|
|
|
|
|
|
|
// this constructor is used only by the Clone method to copy the fields as
|
|
|
|
// needed to a new data transfer.
|
|
|
|
nsDOMDataTransfer(PRUint32 aEventType,
|
|
|
|
const PRUint32 aEffectAllowed,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aCursorState,
|
|
|
|
bool aIsExternal,
|
|
|
|
bool aUserCancelled,
|
2012-03-20 08:21:41 -07:00
|
|
|
bool aIsCrossDomainSubFrameDrop,
|
2008-08-27 05:07:27 -07:00
|
|
|
nsTArray<nsTArray<TransferItem> >& aItems,
|
|
|
|
nsIDOMElement* aDragImage,
|
|
|
|
PRUint32 aDragImageX,
|
|
|
|
PRUint32 aDragImageY);
|
|
|
|
|
2011-08-22 02:14:13 -07:00
|
|
|
~nsDOMDataTransfer()
|
|
|
|
{
|
|
|
|
if (mFiles) {
|
|
|
|
mFiles->Disconnect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-27 05:07:27 -07:00
|
|
|
static const char sEffects[8][9];
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
void GetDragTarget(nsIDOMElement** aDragTarget)
|
|
|
|
{
|
|
|
|
*aDragTarget = mDragTarget;
|
|
|
|
NS_IF_ADDREF(*aDragTarget);
|
|
|
|
}
|
|
|
|
|
|
|
|
// a readonly dataTransfer cannot have new data added or existing data removed.
|
|
|
|
// Only the dropEffect and effectAllowed may be modified.
|
2011-10-17 07:59:28 -07:00
|
|
|
void SetReadOnly() { mReadOnly = true; }
|
2008-08-27 05:07:27 -07:00
|
|
|
|
|
|
|
// converts the data into an array of nsITransferable objects to be used for
|
|
|
|
// drag and drop or clipboard operations.
|
|
|
|
void GetTransferables(nsISupportsArray** transferables);
|
|
|
|
|
|
|
|
// converts the data in the variant to an nsISupportString if possible or
|
|
|
|
// an nsISupports or null otherwise.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool ConvertFromVariant(nsIVariant* aVariant,
|
2008-08-27 05:07:27 -07:00
|
|
|
nsISupports** aSupports,
|
|
|
|
PRUint32* aLength);
|
|
|
|
|
|
|
|
// clears all of the data
|
|
|
|
void ClearAll();
|
|
|
|
|
|
|
|
// Similar to SetData except also specifies the principal to store.
|
|
|
|
// aData may be null when called from CacheExternalFormats.
|
|
|
|
nsresult SetDataWithPrincipal(const nsAString& aFormat,
|
|
|
|
nsIVariant* aData,
|
|
|
|
PRUint32 aIndex,
|
|
|
|
nsIPrincipal* aPrincipal);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
// returns a weak reference to the drag image
|
|
|
|
nsIDOMElement* GetDragImage(PRInt32* aX, PRInt32* aY)
|
|
|
|
{
|
|
|
|
*aX = mDragImageX;
|
|
|
|
*aY = mDragImageY;
|
|
|
|
return mDragImage;
|
|
|
|
}
|
|
|
|
|
|
|
|
// returns a weak reference to the current principal
|
2011-06-21 09:51:34 -07:00
|
|
|
nsIPrincipal* GetCurrentPrincipal(nsresult* rv);
|
2008-08-27 05:07:27 -07:00
|
|
|
|
|
|
|
// converts some formats used for compatibility in aInFormat into aOutFormat.
|
|
|
|
// Text and text/unicode become text/plain, and URL becomes text/uri-list
|
|
|
|
void GetRealFormat(const nsAString& aInFormat, nsAString& aOutFormat);
|
|
|
|
|
|
|
|
// caches the formats that exist in the drag service that were added by an
|
|
|
|
// external drag
|
|
|
|
void CacheExternalFormats();
|
|
|
|
|
|
|
|
// fills in the data field of aItem with the data from the drag service for
|
|
|
|
// a given index.
|
|
|
|
void FillInExternalDragData(TransferItem& aItem, PRUint32 aIndex);
|
|
|
|
|
|
|
|
// the event type this data transfer is for. This will correspond to an
|
|
|
|
// event->message value.
|
|
|
|
PRUint32 mEventType;
|
|
|
|
|
|
|
|
// the drop effect and effect allowed
|
|
|
|
PRUint32 mDropEffect;
|
|
|
|
PRUint32 mEffectAllowed;
|
|
|
|
|
2009-03-06 09:54:29 -08:00
|
|
|
// Indicates the behavior of the cursor during drag operations
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mCursorState;
|
2009-03-06 09:54:29 -08:00
|
|
|
|
2008-08-27 05:07:27 -07:00
|
|
|
// readonly data transfers may not be modified except the drop effect and
|
|
|
|
// effect allowed.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mReadOnly;
|
2008-08-27 05:07:27 -07:00
|
|
|
|
|
|
|
// true for drags started without a data transfer, for example, those from
|
|
|
|
// another application.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mIsExternal;
|
2008-08-27 05:07:27 -07:00
|
|
|
|
2009-02-17 07:51:12 -08:00
|
|
|
// true if the user cancelled the drag. Used only for the dragend event.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mUserCancelled;
|
2009-02-17 07:51:12 -08:00
|
|
|
|
2012-03-20 08:21:41 -07:00
|
|
|
// true if this is a cross-domain drop from a subframe where access to the
|
|
|
|
// data should be prevented
|
|
|
|
bool mIsCrossDomainSubFrameDrop;
|
|
|
|
|
2008-08-27 05:07:27 -07:00
|
|
|
// array of items, each containing an array of format->data pairs
|
|
|
|
nsTArray<nsTArray<TransferItem> > mItems;
|
|
|
|
|
2009-07-30 14:02:08 -07:00
|
|
|
// array of files, containing only the files present in the dataTransfer
|
|
|
|
nsRefPtr<nsDOMFileList> mFiles;
|
|
|
|
|
2008-08-27 05:07:27 -07:00
|
|
|
// the target of the drag. The drag and dragend events will fire at this.
|
|
|
|
nsCOMPtr<nsIDOMElement> mDragTarget;
|
|
|
|
|
|
|
|
// the custom drag image and coordinates within the image. If mDragImage is
|
|
|
|
// null, the default image is created from the drag target.
|
|
|
|
nsCOMPtr<nsIDOMElement> mDragImage;
|
|
|
|
PRUint32 mDragImageX;
|
|
|
|
PRUint32 mDragImageY;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsDOMDataTransfer_h__
|
|
|
|
|