Bug 1376625 - Updating meta data for newly added tests r=ato
[gecko.git] / widget / nsBaseDragService.h
blob300ea693a1d05e048959790cb29af64acd9b6c4c
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"
14 #include "nsCOMPtr.h"
15 #include "nsRect.h"
16 #include "nsPoint.h"
17 #include "mozilla/RefPtr.h"
18 #include "mozilla/dom/ContentParent.h"
19 #include "mozilla/dom/HTMLCanvasElement.h"
20 #include "nsTArray.h"
21 #include "Units.h"
23 // translucency level for drag images
24 #define DRAG_TRANSLUCENCY 0.65
26 class nsIContent;
27 class nsIDOMNode;
28 class nsPresContext;
29 class nsIImageLoadingContent;
31 namespace mozilla {
32 namespace gfx {
33 class SourceSurface;
34 } // namespace gfx
35 } // namespace mozilla
37 /**
38 * XP DragService wrapper base class
41 class nsBaseDragService : public nsIDragService,
42 public nsIDragSession
45 public:
46 typedef mozilla::gfx::SourceSurface SourceSurface;
48 nsBaseDragService();
50 //nsISupports
51 NS_DECL_ISUPPORTS
53 //nsIDragSession and nsIDragService
54 NS_DECL_NSIDRAGSERVICE
55 NS_DECL_NSIDRAGSESSION
57 void SetDragEndPoint(nsIntPoint aEndDragPoint)
59 mEndDragPoint = mozilla::LayoutDeviceIntPoint::FromUnknownPoint(aEndDragPoint);
61 void SetDragEndPoint(mozilla::LayoutDeviceIntPoint aEndDragPoint)
63 mEndDragPoint = aEndDragPoint;
66 uint16_t GetInputSource() { return mInputSource; }
68 int32_t TakeChildProcessDragAction();
70 protected:
71 virtual ~nsBaseDragService();
73 /**
74 * Called from nsBaseDragService to initiate a platform drag from a source
75 * in this process. This is expected to ensure that StartDragSession() and
76 * EndDragSession() get called if the platform drag is successfully invoked.
78 virtual nsresult InvokeDragSessionImpl(nsIArray* aTransferableArray,
79 nsIScriptableRegion* aDragRgn,
80 uint32_t aActionType) = 0;
82 /**
83 * Draw the drag image, if any, to a surface and return it. The drag image
84 * is constructed from mImage if specified, or aDOMNode if mImage is null.
86 * aRegion may be used to draw only a subset of the element. This region
87 * should be supplied using x and y coordinates measured in css pixels
88 * that are relative to the upper-left corner of the window.
90 * aScreenPosition should be the screen coordinates of the mouse click
91 * for the drag. These are in CSS pixels.
93 * On return, aScreenDragRect will contain the screen coordinates of the
94 * area being dragged. This is used by the platform-specific part of the
95 * drag service to determine the drag feedback. This rect will be in the
96 * device pixels of the presContext.
98 * If there is no drag image, the returned surface will be null, but
99 * aScreenDragRect will still be set to the drag area.
101 * aPresContext will be set to the nsPresContext used determined from
102 * whichever of mImage or aDOMNode is used.
104 nsresult DrawDrag(nsIDOMNode* aDOMNode,
105 nsIScriptableRegion* aRegion,
106 mozilla::CSSIntPoint aScreenPosition,
107 mozilla::LayoutDeviceIntRect* aScreenDragRect,
108 RefPtr<SourceSurface>* aSurface,
109 nsPresContext **aPresContext);
112 * Draw a drag image for an image node specified by aImageLoader or aCanvas.
113 * This is called by DrawDrag.
115 nsresult DrawDragForImage(nsPresContext *aPresContext,
116 nsIImageLoadingContent* aImageLoader,
117 mozilla::dom::HTMLCanvasElement* aCanvas,
118 mozilla::LayoutDeviceIntRect* aScreenDragRect,
119 RefPtr<SourceSurface>* aSurface);
122 * Convert aScreenPosition from CSS pixels into unscaled device pixels.
124 mozilla::LayoutDeviceIntPoint
125 ConvertToUnscaledDevPixels(nsPresContext* aPresContext,
126 mozilla::CSSIntPoint aScreenPosition);
129 * If the drag image is a popup, open the popup when the drag begins.
131 void OpenDragPopup();
134 * Free resources contained in DataTransferItems that aren't needed by JS.
136 void DiscardInternalTransferData();
138 // Returns true if a drag event was dispatched to a child process after
139 // the previous TakeDragEventDispatchedToChildProcess() call.
140 bool TakeDragEventDispatchedToChildProcess()
142 bool retval = mDragEventDispatchedToChildProcess;
143 mDragEventDispatchedToChildProcess = false;
144 return retval;
147 bool mCanDrop;
148 bool mOnlyChromeDrop;
149 bool mDoingDrag;
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 nsSize mTargetSize;
161 nsCOMPtr<nsIDOMNode> mSourceNode;
162 nsCOMPtr<nsIDOMDocument> mSourceDocument; // the document at the drag source. will be null
163 // if it came from outside the app.
164 nsContentPolicyType mContentPolicyType; // the contentpolicy type passed to the channel
165 // when initiating the drag session
166 nsCOMPtr<nsIDOMDataTransfer> mDataTransfer;
168 // used to determine the image to appear on the cursor while dragging
169 nsCOMPtr<nsIDOMNode> mImage;
170 // offset of cursor within the image
171 mozilla::CSSIntPoint mImageOffset;
173 // set if a selection is being dragged
174 nsCOMPtr<nsISelection> mSelection;
176 // set if the image in mImage is a popup. If this case, the popup will be opened
177 // and moved instead of using a drag image.
178 nsCOMPtr<nsIContent> mDragPopup;
180 // the screen position where drag gesture occurred, used for positioning the
181 // drag image.
182 mozilla::CSSIntPoint mScreenPosition;
184 // the screen position where the drag ended
185 mozilla::LayoutDeviceIntPoint mEndDragPoint;
187 uint32_t mSuppressLevel;
189 // The input source of the drag event. Possible values are from nsIDOMMouseEvent.
190 uint16_t mInputSource;
192 nsTArray<RefPtr<mozilla::dom::ContentParent>> mChildProcesses;
195 #endif // nsBaseDragService_h__