Bug 1843831 [wpt PR 41060] - LoAF: Expose script start position instead of column...
[gecko.git] / widget / nsBaseDragService.h
blobaeba282bd91a6552c2dc33f94c591f38dad31810
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 "nsCOMPtr.h"
12 #include "nsRect.h"
13 #include "nsPoint.h"
14 #include "nsString.h"
15 #include "mozilla/RefPtr.h"
16 #include "mozilla/dom/ContentParent.h"
17 #include "mozilla/dom/HTMLCanvasElement.h"
18 #include "mozilla/dom/RemoteDragStartData.h"
19 #include "nsTArray.h"
20 #include "nsRegion.h"
21 #include "Units.h"
23 // translucency level for drag images
24 #define DRAG_TRANSLUCENCY 0.65
26 class nsIContent;
28 class nsINode;
29 class nsPresContext;
30 class nsIImageLoadingContent;
32 namespace mozilla {
33 namespace gfx {
34 class SourceSurface;
35 } // namespace gfx
37 namespace dom {
38 class DataTransfer;
39 class Selection;
40 } // namespace dom
41 } // namespace mozilla
43 /**
44 * XP DragService wrapper base class
47 class nsBaseDragService : public nsIDragService, public nsIDragSession {
48 public:
49 typedef mozilla::gfx::SourceSurface SourceSurface;
51 nsBaseDragService();
53 // nsISupports
54 NS_DECL_ISUPPORTS
56 // nsIDragSession and nsIDragService
57 NS_DECL_NSIDRAGSERVICE
58 NS_DECL_NSIDRAGSESSION
60 void SetDragEndPoint(nsIntPoint aEndDragPoint) {
61 mEndDragPoint =
62 mozilla::LayoutDeviceIntPoint::FromUnknownPoint(aEndDragPoint);
64 void SetDragEndPoint(mozilla::LayoutDeviceIntPoint aEndDragPoint) {
65 mEndDragPoint = aEndDragPoint;
68 uint16_t GetInputSource() { return mInputSource; }
70 int32_t TakeChildProcessDragAction();
72 protected:
73 virtual ~nsBaseDragService();
75 /**
76 * Called from nsBaseDragService to initiate a platform drag from a source
77 * in this process. This is expected to ensure that StartDragSession() and
78 * EndDragSession() get called if the platform drag is successfully invoked.
80 MOZ_CAN_RUN_SCRIPT virtual nsresult InvokeDragSessionImpl(
81 nsIArray* aTransferableArray,
82 const mozilla::Maybe<mozilla::CSSIntRegion>& aRegion,
83 uint32_t aActionType) = 0;
85 /**
86 * Draw the drag image, if any, to a surface and return it. The drag image
87 * is constructed from mImage if specified, or aDOMNode if mImage is null.
89 * aRegion may be used to draw only a subset of the element. This region
90 * should be supplied using x and y coordinates measured in css pixels
91 * that are relative to the upper-left corner of the window.
93 * aScreenPosition should be the screen coordinates of the mouse click
94 * for the drag. These are in CSS pixels.
96 * On return, aScreenDragRect will contain the screen coordinates of the
97 * area being dragged. This is used by the platform-specific part of the
98 * drag service to determine the drag feedback. This rect will be in the
99 * device pixels of the presContext.
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(nsINode* aDOMNode,
108 const mozilla::Maybe<mozilla::CSSIntRegion>& aRegion,
109 mozilla::CSSIntPoint aScreenPosition,
110 mozilla::LayoutDeviceIntRect* aScreenDragRect,
111 RefPtr<SourceSurface>* 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 mozilla::dom::HTMLCanvasElement* aCanvas,
121 mozilla::LayoutDeviceIntRect* aScreenDragRect,
122 RefPtr<SourceSurface>* aSurface);
125 * If the drag image is a popup, open the popup when the drag begins.
127 void OpenDragPopup();
130 * Free resources contained in DataTransferItems that aren't needed by JS.
132 void DiscardInternalTransferData();
134 // Returns true if a drag event was dispatched to a child process after
135 // the previous TakeDragEventDispatchedToChildProcess() call.
136 bool TakeDragEventDispatchedToChildProcess() {
137 bool retval = mDragEventDispatchedToChildProcess;
138 mDragEventDispatchedToChildProcess = false;
139 return retval;
142 bool mCanDrop;
143 bool mOnlyChromeDrop;
144 bool mDoingDrag;
145 bool mSessionIsSynthesizedForTests;
146 bool mIsDraggingTextInTextControl;
148 // true if in EndDragSession
149 bool mEndingSession;
150 // true if mImage should be used to set a drag image
151 bool mHasImage;
152 // true if the user cancelled the drag operation
153 bool mUserCancelled;
155 bool mDragEventDispatchedToChildProcess;
157 uint32_t mDragAction;
158 uint32_t mDragActionFromChildProcess;
160 // mEffectAllowedForTests stores allowed effects at invoking the drag
161 // for tests.
162 uint32_t mEffectAllowedForTests;
164 nsCOMPtr<nsINode> mSourceNode;
165 nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
166 nsCOMPtr<nsIContentSecurityPolicy> mCsp;
168 // the document at the drag source. will be null if it came from outside the
169 // app.
170 RefPtr<mozilla::dom::Document> mSourceDocument;
172 RefPtr<mozilla::dom::WindowContext> mSourceWindowContext;
173 RefPtr<mozilla::dom::WindowContext> mSourceTopWindowContext;
175 // the contentpolicy type passed to the channel when initiating the drag
176 // session
177 nsContentPolicyType mContentPolicyType;
179 RefPtr<mozilla::dom::DataTransfer> mDataTransfer;
181 // used to determine the image to appear on the cursor while dragging
182 nsCOMPtr<nsINode> mImage;
183 // offset of cursor within the image
184 mozilla::CSSIntPoint mImageOffset;
186 // set if a selection is being dragged
187 RefPtr<mozilla::dom::Selection> mSelection;
189 // remote drag data
190 RefPtr<mozilla::dom::RemoteDragStartData> mDragStartData;
192 // set if the image in mImage is a popup. If this case, the popup will be
193 // opened and moved instead of using a drag image.
194 nsCOMPtr<mozilla::dom::Element> mDragPopup;
196 // the screen position where drag gesture occurred, used for positioning the
197 // drag image.
198 mozilla::CSSIntPoint mScreenPosition;
200 // The position relative to the top level widget where the drag ended.
201 mozilla::LayoutDeviceIntPoint mEndDragPoint;
203 uint32_t mSuppressLevel;
205 // The input source of the drag event. Possible values are from MouseEvent.
206 uint16_t mInputSource;
208 nsTArray<RefPtr<mozilla::dom::ContentParent>> mChildProcesses;
210 // Sub-region for tree-selections.
211 mozilla::Maybe<mozilla::CSSIntRegion> mRegion;
214 #endif // nsBaseDragService_h__