Bug 1626988 [wpt PR 22658] - wake lock: Remove WakeLockPermissionDescriptor, use...
[gecko.git] / widget / nsBaseDragService.h
blobd91b71dfe7407fa5399a4155717408820571f5af
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 * Convert aScreenPosition from CSS pixels into unscaled device pixels.
127 mozilla::LayoutDeviceIntPoint ConvertToUnscaledDevPixels(
128 nsPresContext* aPresContext, mozilla::CSSIntPoint aScreenPosition);
131 * If the drag image is a popup, open the popup when the drag begins.
133 void OpenDragPopup();
136 * Free resources contained in DataTransferItems that aren't needed by JS.
138 void DiscardInternalTransferData();
140 // Returns true if a drag event was dispatched to a child process after
141 // the previous TakeDragEventDispatchedToChildProcess() call.
142 bool TakeDragEventDispatchedToChildProcess() {
143 bool retval = mDragEventDispatchedToChildProcess;
144 mDragEventDispatchedToChildProcess = false;
145 return retval;
148 bool mCanDrop;
149 bool mOnlyChromeDrop;
150 bool mDoingDrag;
151 bool mSessionIsSynthesizedForTests;
153 // true if in EndDragSession
154 bool mEndingSession;
155 // true if mImage should be used to set a drag image
156 bool mHasImage;
157 // true if the user cancelled the drag operation
158 bool mUserCancelled;
160 bool mDragEventDispatchedToChildProcess;
162 uint32_t mDragAction;
163 uint32_t mDragActionFromChildProcess;
165 // mEffectAllowedForTests stores allowed effects at invoking the drag
166 // for tests.
167 uint32_t mEffectAllowedForTests;
169 nsCOMPtr<nsINode> mSourceNode;
170 nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
171 nsCOMPtr<nsIContentSecurityPolicy> mCsp;
173 // the document at the drag source. will be null if it came from outside the
174 // app.
175 RefPtr<mozilla::dom::Document> mSourceDocument;
177 // the contentpolicy type passed to the channel when initiating the drag
178 // session
179 nsContentPolicyType mContentPolicyType;
181 RefPtr<mozilla::dom::DataTransfer> mDataTransfer;
183 // used to determine the image to appear on the cursor while dragging
184 nsCOMPtr<nsINode> mImage;
185 // offset of cursor within the image
186 mozilla::CSSIntPoint mImageOffset;
188 // set if a selection is being dragged
189 RefPtr<mozilla::dom::Selection> mSelection;
191 // remote drag data
192 RefPtr<mozilla::dom::RemoteDragStartData> mDragStartData;
194 // set if the image in mImage is a popup. If this case, the popup will be
195 // opened and moved instead of using a drag image.
196 nsCOMPtr<nsIContent> mDragPopup;
198 // the screen position where drag gesture occurred, used for positioning the
199 // drag image.
200 mozilla::CSSIntPoint mScreenPosition;
202 // the screen position where the drag ended
203 mozilla::LayoutDeviceIntPoint mEndDragPoint;
205 uint32_t mSuppressLevel;
207 // The input source of the drag event. Possible values are from MouseEvent.
208 uint16_t mInputSource;
210 nsTArray<RefPtr<mozilla::dom::ContentParent>> mChildProcesses;
212 // Sub-region for tree-selections.
213 mozilla::Maybe<mozilla::CSSIntRegion> mRegion;
216 #endif // nsBaseDragService_h__