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
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * 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 nsBaseDragService_h__
39 #define nsBaseDragService_h__
41 #include "nsIDragService.h"
42 #include "nsIDragSession.h"
43 #include "nsITransferable.h"
44 #include "nsISupportsArray.h"
45 #include "nsIDOMDocument.h"
47 #include "nsIRenderingContext.h"
48 #include "nsIDOMDataTransfer.h"
50 #include "gfxImageSurface.h"
52 // translucency level for drag images
53 #define DRAG_TRANSLUCENCY 0.65
58 class nsIImageLoadingContent
;
59 class nsICanvasElementExternal
;
62 * XP DragService wrapper base class
65 class nsBaseDragService
: public nsIDragService
,
71 virtual ~nsBaseDragService();
76 //nsIDragSession and nsIDragService
77 NS_DECL_NSIDRAGSERVICE
78 NS_DECL_NSIDRAGSESSION
80 void SetDragEndPoint(nsIntPoint aEndDragPoint
) { mEndDragPoint
= aEndDragPoint
; }
82 PRUint16
GetInputSource() { return mInputSource
; }
87 * Draw the drag image, if any, to a surface and return it. The drag image
88 * is constructed from mImage if specified, or aDOMNode if mImage is null.
90 * aRegion may be used to draw only a subset of the element. This region
91 * should be supplied using x and y coordinates measured in css pixels
92 * that are relative to the upper-left corner of the window.
94 * aScreenX and aScreenY should be the screen coordinates of the mouse click
97 * On return, aScreenDragRect will contain the screen coordinates of the
98 * area being dragged. This is used by the platform-specific part of the
99 * drag service to determine the drag feedback.
101 * If there is no drag image, the returned surface will be null, but
102 * aScreenDragRect will still be set to the drag area.
104 * aPresContext will be set to the nsPresContext used determined from
105 * whichever of mImage or aDOMNode is used.
107 nsresult
DrawDrag(nsIDOMNode
* aDOMNode
,
108 nsIScriptableRegion
* aRegion
,
109 PRInt32 aScreenX
, PRInt32 aScreenY
,
110 nsIntRect
* aScreenDragRect
,
111 gfxASurface
** aSurface
,
112 nsPresContext
**aPresContext
);
115 * Draw a drag image for an image node specified by aImageLoader or aCanvas.
116 * This is called by DrawDrag.
118 nsresult
DrawDragForImage(nsPresContext
* aPresContext
,
119 nsIImageLoadingContent
* aImageLoader
,
120 nsICanvasElementExternal
* aCanvas
,
121 PRInt32 aScreenX
, PRInt32 aScreenY
,
122 nsIntRect
* aScreenDragRect
,
123 gfxASurface
** aSurface
);
126 * Convert aScreenX and aScreenY from CSS pixels into unscaled device pixels.
129 ConvertToUnscaledDevPixels(nsPresContext
* aPresContext
,
130 PRInt32
* aScreenX
, PRInt32
* aScreenY
);
132 PRPackedBool mCanDrop
;
133 PRPackedBool mOnlyChromeDrop
;
134 PRPackedBool mDoingDrag
;
135 // true if mImage should be used to set a drag image
136 PRPackedBool mHasImage
;
137 // true if the user cancelled the drag operation
138 PRPackedBool mUserCancelled
;
140 PRUint32 mDragAction
;
142 nsCOMPtr
<nsIDOMNode
> mSourceNode
;
143 nsCOMPtr
<nsIDOMDocument
> mSourceDocument
; // the document at the drag source. will be null
144 // if it came from outside the app.
145 nsCOMPtr
<nsIDOMDataTransfer
> mDataTransfer
;
147 // used to determine the image to appear on the cursor while dragging
148 nsCOMPtr
<nsIDOMNode
> mImage
;
149 // offset of cursor within the image
153 // set if a selection is being dragged
154 nsCOMPtr
<nsISelection
> mSelection
;
156 // the screen position where drag gesture occurred, used for positioning the
157 // drag image when no image is specified. If a value is -1, no event was
158 // supplied so the screen position is not known
162 // the screen position where the drag ended
163 nsIntPoint mEndDragPoint
;
165 PRUint32 mSuppressLevel
;
167 // The input source of the drag event. Possible values are from nsIDOMNSMouseEvent.
168 PRUint16 mInputSource
;
171 #endif // nsBaseDragService_h__