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"
17 #include "mozilla/RefPtr.h"
18 #include "mozilla/dom/ContentParent.h"
19 #include "mozilla/dom/HTMLCanvasElement.h"
23 // translucency level for drag images
24 #define DRAG_TRANSLUCENCY 0.65
29 class nsIImageLoadingContent
;
40 } // namespace mozilla
43 * XP DragService wrapper base class
46 class nsBaseDragService
: public nsIDragService
,
51 typedef mozilla::gfx::SourceSurface SourceSurface
;
58 //nsIDragSession and nsIDragService
59 NS_DECL_NSIDRAGSERVICE
60 NS_DECL_NSIDRAGSESSION
62 void SetDragEndPoint(nsIntPoint aEndDragPoint
)
64 mEndDragPoint
= mozilla::LayoutDeviceIntPoint::FromUnknownPoint(aEndDragPoint
);
66 void SetDragEndPoint(mozilla::LayoutDeviceIntPoint aEndDragPoint
)
68 mEndDragPoint
= aEndDragPoint
;
71 uint16_t GetInputSource() { return mInputSource
; }
73 int32_t TakeChildProcessDragAction();
76 virtual ~nsBaseDragService();
79 * Called from nsBaseDragService to initiate a platform drag from a source
80 * in this process. This is expected to ensure that StartDragSession() and
81 * EndDragSession() get called if the platform drag is successfully invoked.
83 virtual nsresult
InvokeDragSessionImpl(nsIArray
* aTransferableArray
,
84 nsIScriptableRegion
* aDragRgn
,
85 uint32_t aActionType
) = 0;
88 * Draw the drag image, if any, to a surface and return it. The drag image
89 * is constructed from mImage if specified, or aDOMNode if mImage is null.
91 * aRegion may be used to draw only a subset of the element. This region
92 * should be supplied using x and y coordinates measured in css pixels
93 * that are relative to the upper-left corner of the window.
95 * aScreenPosition should be the screen coordinates of the mouse click
96 * for the drag. These are in CSS pixels.
98 * On return, aScreenDragRect will contain the screen coordinates of the
99 * area being dragged. This is used by the platform-specific part of the
100 * drag service to determine the drag feedback. This rect will be in the
101 * device pixels of the presContext.
103 * If there is no drag image, the returned surface will be null, but
104 * aScreenDragRect will still be set to the drag area.
106 * aPresContext will be set to the nsPresContext used determined from
107 * whichever of mImage or aDOMNode is used.
109 nsresult
DrawDrag(nsIDOMNode
* aDOMNode
,
110 nsIScriptableRegion
* aRegion
,
111 mozilla::CSSIntPoint aScreenPosition
,
112 mozilla::LayoutDeviceIntRect
* aScreenDragRect
,
113 RefPtr
<SourceSurface
>* aSurface
,
114 nsPresContext
**aPresContext
);
117 * Draw a drag image for an image node specified by aImageLoader or aCanvas.
118 * This is called by DrawDrag.
120 nsresult
DrawDragForImage(nsPresContext
*aPresContext
,
121 nsIImageLoadingContent
* aImageLoader
,
122 mozilla::dom::HTMLCanvasElement
* aCanvas
,
123 mozilla::LayoutDeviceIntRect
* aScreenDragRect
,
124 RefPtr
<SourceSurface
>* aSurface
);
127 * Convert aScreenPosition from CSS pixels into unscaled device pixels.
129 mozilla::LayoutDeviceIntPoint
130 ConvertToUnscaledDevPixels(nsPresContext
* aPresContext
,
131 mozilla::CSSIntPoint aScreenPosition
);
134 * If the drag image is a popup, open the popup when the drag begins.
136 void OpenDragPopup();
139 * Free resources contained in DataTransferItems that aren't needed by JS.
141 void DiscardInternalTransferData();
143 // Returns true if a drag event was dispatched to a child process after
144 // the previous TakeDragEventDispatchedToChildProcess() call.
145 bool TakeDragEventDispatchedToChildProcess()
147 bool retval
= mDragEventDispatchedToChildProcess
;
148 mDragEventDispatchedToChildProcess
= false;
153 bool mOnlyChromeDrop
;
155 // true if mImage should be used to set a drag image
157 // true if the user cancelled the drag operation
160 bool mDragEventDispatchedToChildProcess
;
162 uint32_t mDragAction
;
163 uint32_t mDragActionFromChildProcess
;
166 nsCOMPtr
<nsIDOMNode
> mSourceNode
;
167 nsCString mTriggeringPrincipalURISpec
;
168 nsCOMPtr
<nsIDOMDocument
> mSourceDocument
; // the document at the drag source. will be null
169 // if it came from outside the app.
170 nsContentPolicyType mContentPolicyType
; // the contentpolicy type passed to the channel
171 // when initiating the drag session
172 RefPtr
<mozilla::dom::DataTransfer
> mDataTransfer
;
174 // used to determine the image to appear on the cursor while dragging
175 nsCOMPtr
<nsIDOMNode
> mImage
;
176 // offset of cursor within the image
177 mozilla::CSSIntPoint mImageOffset
;
179 // set if a selection is being dragged
180 RefPtr
<mozilla::dom::Selection
> mSelection
;
182 // set if the image in mImage is a popup. If this case, the popup will be opened
183 // and moved instead of using a drag image.
184 nsCOMPtr
<nsIContent
> mDragPopup
;
186 // the screen position where drag gesture occurred, used for positioning the
188 mozilla::CSSIntPoint mScreenPosition
;
190 // the screen position where the drag ended
191 mozilla::LayoutDeviceIntPoint mEndDragPoint
;
193 uint32_t mSuppressLevel
;
195 // The input source of the drag event. Possible values are from MouseEvent.
196 uint16_t mInputSource
;
198 nsTArray
<RefPtr
<mozilla::dom::ContentParent
>> mChildProcesses
;
201 #endif // nsBaseDragService_h__