Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / widget / nsBaseDragService.h
blob7e76a236043b578c2902e443bb93d38e8b6a8892
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 "mozilla/Logging.h"
20 #include "nsTArray.h"
21 #include "nsRegion.h"
22 #include "Units.h"
24 extern mozilla::LazyLogModule sWidgetDragServiceLog;
25 #define MOZ_DRAGSERVICE_LOG(...) \
26 MOZ_LOG(sWidgetDragServiceLog, mozilla::LogLevel::Debug, (__VA_ARGS__))
27 #define MOZ_DRAGSERVICE_LOG_ENABLED() \
28 MOZ_LOG_TEST(sWidgetDragServiceLog, mozilla::LogLevel::Debug)
30 // translucency level for drag images
31 #define DRAG_TRANSLUCENCY 0.65
33 class nsIContent;
35 class nsINode;
36 class nsPresContext;
37 class nsIImageLoadingContent;
39 namespace mozilla {
40 namespace gfx {
41 class SourceSurface;
42 } // namespace gfx
44 namespace dom {
45 class DataTransfer;
46 class Selection;
47 } // namespace dom
48 } // namespace mozilla
50 /**
51 * XP DragService wrapper base class
54 class nsBaseDragService : public nsIDragService, public nsIDragSession {
55 public:
56 typedef mozilla::gfx::SourceSurface SourceSurface;
58 nsBaseDragService();
60 // nsISupports
61 NS_DECL_ISUPPORTS
63 // nsIDragSession and nsIDragService
64 NS_DECL_NSIDRAGSERVICE
65 NS_DECL_NSIDRAGSESSION
67 void SetDragEndPoint(nsIntPoint aEndDragPoint) {
68 mEndDragPoint =
69 mozilla::LayoutDeviceIntPoint::FromUnknownPoint(aEndDragPoint);
71 void SetDragEndPoint(mozilla::LayoutDeviceIntPoint aEndDragPoint) {
72 mEndDragPoint = aEndDragPoint;
75 uint16_t GetInputSource() { return mInputSource; }
77 int32_t TakeChildProcessDragAction();
79 protected:
80 virtual ~nsBaseDragService();
82 /**
83 * Called from nsBaseDragService to initiate a platform drag from a source
84 * in this process. This is expected to ensure that StartDragSession() and
85 * EndDragSession() get called if the platform drag is successfully invoked.
87 MOZ_CAN_RUN_SCRIPT virtual nsresult InvokeDragSessionImpl(
88 nsIArray* aTransferableArray,
89 const mozilla::Maybe<mozilla::CSSIntRegion>& aRegion,
90 uint32_t aActionType) = 0;
92 /**
93 * Draw the drag image, if any, to a surface and return it. The drag image
94 * is constructed from mImage if specified, or aDOMNode if mImage is null.
96 * aRegion may be used to draw only a subset of the element. This region
97 * should be supplied using x and y coordinates measured in css pixels
98 * that are relative to the upper-left corner of the window.
100 * aScreenPosition should be the screen coordinates of the mouse click
101 * for the drag. These are in CSS pixels.
103 * On return, aScreenDragRect will contain the screen coordinates of the
104 * area being dragged. This is used by the platform-specific part of the
105 * drag service to determine the drag feedback. This rect will be in the
106 * device pixels of the presContext.
108 * If there is no drag image, the returned surface will be null, but
109 * aScreenDragRect will still be set to the drag area.
111 * aPresContext will be set to the nsPresContext used determined from
112 * whichever of mImage or aDOMNode is used.
114 nsresult DrawDrag(nsINode* aDOMNode,
115 const mozilla::Maybe<mozilla::CSSIntRegion>& aRegion,
116 mozilla::CSSIntPoint aScreenPosition,
117 mozilla::LayoutDeviceIntRect* aScreenDragRect,
118 RefPtr<SourceSurface>* aSurface,
119 nsPresContext** aPresContext);
122 * Draw a drag image for an image node specified by aImageLoader or aCanvas.
123 * This is called by DrawDrag.
125 nsresult DrawDragForImage(nsPresContext* aPresContext,
126 nsIImageLoadingContent* aImageLoader,
127 mozilla::dom::HTMLCanvasElement* aCanvas,
128 mozilla::LayoutDeviceIntRect* aScreenDragRect,
129 RefPtr<SourceSurface>* aSurface);
132 * If the drag image is a popup, open the popup when the drag begins.
134 void OpenDragPopup();
137 * Free resources contained in DataTransferItems that aren't needed by JS.
139 void DiscardInternalTransferData();
141 // Returns true if a drag event was dispatched to a child process after
142 // the previous TakeDragEventDispatchedToChildProcess() call.
143 bool TakeDragEventDispatchedToChildProcess() {
144 bool retval = mDragEventDispatchedToChildProcess;
145 mDragEventDispatchedToChildProcess = false;
146 return retval;
149 bool mCanDrop;
150 bool mOnlyChromeDrop;
151 bool mDoingDrag;
152 bool mSessionIsSynthesizedForTests;
153 bool mIsDraggingTextInTextControl;
155 // true if in EndDragSession
156 bool mEndingSession;
157 // true if mImage should be used to set a drag image
158 bool mHasImage;
159 // true if the user cancelled the drag operation
160 bool mUserCancelled;
162 bool mDragEventDispatchedToChildProcess;
164 uint32_t mDragAction;
165 uint32_t mDragActionFromChildProcess;
167 // mEffectAllowedForTests stores allowed effects at invoking the drag
168 // for tests.
169 uint32_t mEffectAllowedForTests;
171 nsCOMPtr<nsINode> mSourceNode;
172 nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
173 nsCOMPtr<nsIContentSecurityPolicy> mCsp;
175 // the document at the drag source. will be null if it came from outside the
176 // app.
177 RefPtr<mozilla::dom::Document> mSourceDocument;
179 RefPtr<mozilla::dom::WindowContext> mSourceWindowContext;
180 RefPtr<mozilla::dom::WindowContext> mSourceTopWindowContext;
182 // the contentpolicy type passed to the channel when initiating the drag
183 // session
184 nsContentPolicyType mContentPolicyType;
186 RefPtr<mozilla::dom::DataTransfer> mDataTransfer;
188 // used to determine the image to appear on the cursor while dragging
189 nsCOMPtr<nsINode> mImage;
190 // offset of cursor within the image
191 mozilla::CSSIntPoint mImageOffset;
193 // set if a selection is being dragged
194 RefPtr<mozilla::dom::Selection> mSelection;
196 // remote drag data
197 RefPtr<mozilla::dom::RemoteDragStartData> mDragStartData;
199 // set if the image in mImage is a popup. If this case, the popup will be
200 // opened and moved instead of using a drag image.
201 nsCOMPtr<mozilla::dom::Element> mDragPopup;
203 // the screen position where drag gesture occurred, used for positioning the
204 // drag image.
205 mozilla::CSSIntPoint mScreenPosition;
207 // The position relative to the top level widget where the drag ended.
208 mozilla::LayoutDeviceIntPoint mEndDragPoint;
210 uint32_t mSuppressLevel;
212 // The input source of the drag event. Possible values are from MouseEvent.
213 uint16_t mInputSource;
215 nsTArray<RefPtr<mozilla::dom::ContentParent>> mChildProcesses;
217 // Sub-region for tree-selections.
218 mozilla::Maybe<mozilla::CSSIntRegion> mRegion;
221 #endif // nsBaseDragService_h__