1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is the Mozilla Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 2008
19 * the Initial Developer. All Rights Reserved.
22 * Neil Deakin <enndeakin@gmail.com>
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef nsDOMDataTransfer_h__
39 #define nsDOMDataTransfer_h__
43 #include "nsIVariant.h"
44 #include "nsIPrincipal.h"
45 #include "nsIDOMDataTransfer.h"
46 #include "nsIDragService.h"
47 #include "nsIDOMElement.h"
48 #include "nsCycleCollectionParticipant.h"
50 class nsITransferable
;
53 * TransferItem is used to hold data for a particular format. Each piece of
54 * data has a principal set from the caller which added it. This allows a
55 * caller that wishes to retrieve the data to only be able to access the data
56 * it is allowed to, yet still allow a chrome caller to retrieve any of the
61 nsCOMPtr
<nsIPrincipal
> mPrincipal
;
62 nsCOMPtr
<nsIVariant
> mData
;
65 class nsDOMDataTransfer
: public nsIDOMDataTransfer
,
66 public nsIDOMNSDataTransfer
69 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
70 NS_DECL_NSIDOMDATATRANSFER
71 NS_DECL_NSIDOMNSDATATRANSFER
73 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsDOMDataTransfer
, nsIDOMDataTransfer
)
75 friend class nsDOMDragEvent
;
76 friend class nsEventStateManager
;
80 // the constructors are protected so only our friends can call them
82 // default constructor used for the dragstart/draggesture event and
86 // this constructor must only be used to create a dataTransfer for a drag
87 // that was started without using a data transfer, either an external drag,
88 // that is, a drag where the source is another application, or a drag
89 // started by calling the drag service directly.
90 nsDOMDataTransfer(PRUint32 aEventType
, PRUint32 aAction
);
92 // this constructor is used only by the Clone method to copy the fields as
93 // needed to a new data transfer.
94 nsDOMDataTransfer(PRUint32 aEventType
,
95 const PRUint32 aEffectAllowed
,
97 nsTArray
<nsTArray
<TransferItem
> >& aItems
,
98 nsIDOMElement
* aDragImage
,
100 PRUint32 aDragImageY
);
102 static const char sEffects
[8][9];
106 void GetDragTarget(nsIDOMElement
** aDragTarget
)
108 *aDragTarget
= mDragTarget
;
109 NS_IF_ADDREF(*aDragTarget
);
112 // a readonly dataTransfer cannot have new data added or existing data removed.
113 // Only the dropEffect and effectAllowed may be modified.
114 void SetReadOnly() { mReadOnly
= PR_TRUE
; }
116 // converts the data into an array of nsITransferable objects to be used for
117 // drag and drop or clipboard operations.
118 void GetTransferables(nsISupportsArray
** transferables
);
120 // converts the data in the variant to an nsISupportString if possible or
121 // an nsISupports or null otherwise.
122 PRBool
ConvertFromVariant(nsIVariant
* aVariant
,
123 nsISupports
** aSupports
,
126 // clears all of the data
129 // Similar to SetData except also specifies the principal to store.
130 // aData may be null when called from CacheExternalFormats.
131 nsresult
SetDataWithPrincipal(const nsAString
& aFormat
,
134 nsIPrincipal
* aPrincipal
);
138 // returns a weak reference to the drag image
139 nsIDOMElement
* GetDragImage(PRInt32
* aX
, PRInt32
* aY
)
146 // returns a weak reference to the current principal
147 nsIPrincipal
* GetCurrentPrincipal();
149 // converts some formats used for compatibility in aInFormat into aOutFormat.
150 // Text and text/unicode become text/plain, and URL becomes text/uri-list
151 void GetRealFormat(const nsAString
& aInFormat
, nsAString
& aOutFormat
);
153 // caches the formats that exist in the drag service that were added by an
155 void CacheExternalFormats();
157 // fills in the data field of aItem with the data from the drag service for
159 void FillInExternalDragData(TransferItem
& aItem
, PRUint32 aIndex
);
161 // the event type this data transfer is for. This will correspond to an
162 // event->message value.
165 // the drop effect and effect allowed
166 PRUint32 mDropEffect
;
167 PRUint32 mEffectAllowed
;
169 // readonly data transfers may not be modified except the drop effect and
171 PRPackedBool mReadOnly
;
173 // true for drags started without a data transfer, for example, those from
174 // another application.
175 PRPackedBool mIsExternal
;
177 // array of items, each containing an array of format->data pairs
178 nsTArray
<nsTArray
<TransferItem
> > mItems
;
180 // the target of the drag. The drag and dragend events will fire at this.
181 nsCOMPtr
<nsIDOMElement
> mDragTarget
;
183 // the custom drag image and coordinates within the image. If mDragImage is
184 // null, the default image is created from the drag target.
185 nsCOMPtr
<nsIDOMElement
> mDragImage
;
186 PRUint32 mDragImageX
;
187 PRUint32 mDragImageY
;
190 #endif // nsDOMDataTransfer_h__