Line data Source code
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/. */
5 :
6 : #ifndef nsBaseDragService_h__
7 : #define nsBaseDragService_h__
8 :
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"
22 :
23 : // translucency level for drag images
24 : #define DRAG_TRANSLUCENCY 0.65
25 :
26 : class nsIContent;
27 : class nsIDOMNode;
28 : class nsPresContext;
29 : class nsIImageLoadingContent;
30 :
31 : namespace mozilla {
32 : namespace gfx {
33 : class SourceSurface;
34 : } // namespace gfx
35 : } // namespace mozilla
36 :
37 : /**
38 : * XP DragService wrapper base class
39 : */
40 :
41 0 : class nsBaseDragService : public nsIDragService,
42 : public nsIDragSession
43 : {
44 :
45 : public:
46 : typedef mozilla::gfx::SourceSurface SourceSurface;
47 :
48 : nsBaseDragService();
49 :
50 : //nsISupports
51 : NS_DECL_ISUPPORTS
52 :
53 : //nsIDragSession and nsIDragService
54 : NS_DECL_NSIDRAGSERVICE
55 : NS_DECL_NSIDRAGSESSION
56 :
57 : void SetDragEndPoint(nsIntPoint aEndDragPoint)
58 : {
59 : mEndDragPoint = mozilla::LayoutDeviceIntPoint::FromUnknownPoint(aEndDragPoint);
60 : }
61 0 : void SetDragEndPoint(mozilla::LayoutDeviceIntPoint aEndDragPoint)
62 : {
63 0 : mEndDragPoint = aEndDragPoint;
64 0 : }
65 :
66 : uint16_t GetInputSource() { return mInputSource; }
67 :
68 : int32_t TakeChildProcessDragAction();
69 :
70 : protected:
71 : virtual ~nsBaseDragService();
72 :
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.
77 : */
78 : virtual nsresult InvokeDragSessionImpl(nsIArray* aTransferableArray,
79 : nsIScriptableRegion* aDragRgn,
80 : uint32_t aActionType) = 0;
81 :
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.
85 : *
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.
89 : *
90 : * aScreenPosition should be the screen coordinates of the mouse click
91 : * for the drag. These are in CSS pixels.
92 : *
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.
97 : *
98 : * If there is no drag image, the returned surface will be null, but
99 : * aScreenDragRect will still be set to the drag area.
100 : *
101 : * aPresContext will be set to the nsPresContext used determined from
102 : * whichever of mImage or aDOMNode is used.
103 : */
104 : nsresult DrawDrag(nsIDOMNode* aDOMNode,
105 : nsIScriptableRegion* aRegion,
106 : mozilla::CSSIntPoint aScreenPosition,
107 : mozilla::LayoutDeviceIntRect* aScreenDragRect,
108 : RefPtr<SourceSurface>* aSurface,
109 : nsPresContext **aPresContext);
110 :
111 : /**
112 : * Draw a drag image for an image node specified by aImageLoader or aCanvas.
113 : * This is called by DrawDrag.
114 : */
115 : nsresult DrawDragForImage(nsPresContext *aPresContext,
116 : nsIImageLoadingContent* aImageLoader,
117 : mozilla::dom::HTMLCanvasElement* aCanvas,
118 : mozilla::LayoutDeviceIntRect* aScreenDragRect,
119 : RefPtr<SourceSurface>* aSurface);
120 :
121 : /**
122 : * Convert aScreenPosition from CSS pixels into unscaled device pixels.
123 : */
124 : mozilla::LayoutDeviceIntPoint
125 : ConvertToUnscaledDevPixels(nsPresContext* aPresContext,
126 : mozilla::CSSIntPoint aScreenPosition);
127 :
128 : /**
129 : * If the drag image is a popup, open the popup when the drag begins.
130 : */
131 : void OpenDragPopup();
132 :
133 : /**
134 : * Free resources contained in DataTransferItems that aren't needed by JS.
135 : */
136 : void DiscardInternalTransferData();
137 :
138 : // Returns true if a drag event was dispatched to a child process after
139 : // the previous TakeDragEventDispatchedToChildProcess() call.
140 0 : bool TakeDragEventDispatchedToChildProcess()
141 : {
142 0 : bool retval = mDragEventDispatchedToChildProcess;
143 0 : mDragEventDispatchedToChildProcess = false;
144 0 : return retval;
145 : }
146 :
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;
154 :
155 : bool mDragEventDispatchedToChildProcess;
156 :
157 : uint32_t mDragAction;
158 : uint32_t mDragActionFromChildProcess;
159 :
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;
167 :
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;
172 :
173 : // set if a selection is being dragged
174 : nsCOMPtr<nsISelection> mSelection;
175 :
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;
179 :
180 : // the screen position where drag gesture occurred, used for positioning the
181 : // drag image.
182 : mozilla::CSSIntPoint mScreenPosition;
183 :
184 : // the screen position where the drag ended
185 : mozilla::LayoutDeviceIntPoint mEndDragPoint;
186 :
187 : uint32_t mSuppressLevel;
188 :
189 : // The input source of the drag event. Possible values are from nsIDOMMouseEvent.
190 : uint16_t mInputSource;
191 :
192 : nsTArray<RefPtr<mozilla::dom::ContentParent>> mChildProcesses;
193 : };
194 :
195 : #endif // nsBaseDragService_h__
|