1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef nsBaseDragService_h__
7 #define nsBaseDragService_h__
9 #include "nsIDragService.h"
10 #include "nsIDragSession.h"
11 #include "nsITransferable.h"
12 #include "nsIDOMDocument.h"
13 #include "nsIDOMDataTransfer.h"
17 #include "mozilla/RefPtr.h"
18 #include "mozilla/dom/HTMLCanvasElement.h"
20 // translucency level for drag images
21 #define DRAG_TRANSLUCENCY 0.65
27 class nsIImageLoadingContent
;
28 class nsICanvasElementExternal
;
37 * XP DragService wrapper base class
40 class nsBaseDragService
: public nsIDragService
,
45 typedef mozilla::gfx::SourceSurface SourceSurface
;
52 //nsIDragSession and nsIDragService
53 NS_DECL_NSIDRAGSERVICE
54 NS_DECL_NSIDRAGSESSION
56 void SetDragEndPoint(nsIntPoint aEndDragPoint
) { mEndDragPoint
= aEndDragPoint
; }
58 uint16_t GetInputSource() { return mInputSource
; }
61 virtual ~nsBaseDragService();
64 * Draw the drag image, if any, to a surface and return it. The drag image
65 * is constructed from mImage if specified, or aDOMNode if mImage is null.
67 * aRegion may be used to draw only a subset of the element. This region
68 * should be supplied using x and y coordinates measured in css pixels
69 * that are relative to the upper-left corner of the window.
71 * aScreenX and aScreenY should be the screen coordinates of the mouse click
72 * for the drag. These are in global display pixels.
74 * On return, aScreenDragRect will contain the screen coordinates of the
75 * area being dragged. This is used by the platform-specific part of the
76 * drag service to determine the drag feedback. This rect will be in the
77 * device pixels of the presContext.
79 * If there is no drag image, the returned surface will be null, but
80 * aScreenDragRect will still be set to the drag area.
82 * aPresContext will be set to the nsPresContext used determined from
83 * whichever of mImage or aDOMNode is used.
85 nsresult
DrawDrag(nsIDOMNode
* aDOMNode
,
86 nsIScriptableRegion
* aRegion
,
87 int32_t aScreenX
, int32_t aScreenY
,
88 nsIntRect
* aScreenDragRect
,
89 mozilla::RefPtr
<SourceSurface
>* aSurface
,
90 nsPresContext
**aPresContext
);
93 * Draw a drag image for an image node specified by aImageLoader or aCanvas.
94 * This is called by DrawDrag.
96 nsresult
DrawDragForImage(nsPresContext
* aPresContext
,
97 nsIImageLoadingContent
* aImageLoader
,
98 mozilla::dom::HTMLCanvasElement
* aCanvas
,
99 int32_t aScreenX
, int32_t aScreenY
,
100 nsIntRect
* aScreenDragRect
,
101 mozilla::RefPtr
<SourceSurface
>* aSurface
);
104 * Convert aScreenX and aScreenY from CSS pixels into unscaled device pixels.
107 ConvertToUnscaledDevPixels(nsPresContext
* aPresContext
,
108 int32_t* aScreenX
, int32_t* aScreenY
);
111 * If the drag image is a popup, open the popup when the drag begins.
113 void OpenDragPopup();
116 bool mOnlyChromeDrop
;
118 // true if mImage should be used to set a drag image
120 // true if the user cancelled the drag operation
123 uint32_t mDragAction
;
125 nsCOMPtr
<nsIDOMNode
> mSourceNode
;
126 nsCOMPtr
<nsIDOMDocument
> mSourceDocument
; // the document at the drag source. will be null
127 // if it came from outside the app.
128 nsCOMPtr
<nsIDOMDataTransfer
> mDataTransfer
;
130 // used to determine the image to appear on the cursor while dragging
131 nsCOMPtr
<nsIDOMNode
> mImage
;
132 // offset of cursor within the image
136 // set if a selection is being dragged
137 nsCOMPtr
<nsISelection
> mSelection
;
139 // set if the image in mImage is a popup. If this case, the popup will be opened
140 // and moved instead of using a drag image.
141 nsCOMPtr
<nsIContent
> mDragPopup
;
143 // the screen position where drag gesture occurred, used for positioning the
144 // drag image when no image is specified. If a value is -1, no event was
145 // supplied so the screen position is not known
149 // the screen position where the drag ended
150 nsIntPoint mEndDragPoint
;
152 uint32_t mSuppressLevel
;
154 // The input source of the drag event. Possible values are from nsIDOMMouseEvent.
155 uint16_t mInputSource
;
158 #endif // nsBaseDragService_h__