|
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/HTMLCanvasElement.h" |
|
19 |
|
20 // translucency level for drag images |
|
21 #define DRAG_TRANSLUCENCY 0.65 |
|
22 |
|
23 class nsIContent; |
|
24 class nsIDOMNode; |
|
25 class nsIFrame; |
|
26 class nsPresContext; |
|
27 class nsIImageLoadingContent; |
|
28 class nsICanvasElementExternal; |
|
29 |
|
30 namespace mozilla { |
|
31 namespace gfx { |
|
32 class SourceSurface; |
|
33 } |
|
34 } |
|
35 |
|
36 /** |
|
37 * XP DragService wrapper base class |
|
38 */ |
|
39 |
|
40 class nsBaseDragService : public nsIDragService, |
|
41 public nsIDragSession |
|
42 { |
|
43 |
|
44 public: |
|
45 typedef mozilla::gfx::SourceSurface SourceSurface; |
|
46 |
|
47 nsBaseDragService(); |
|
48 virtual ~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) { mEndDragPoint = aEndDragPoint; } |
|
58 |
|
59 uint16_t GetInputSource() { return mInputSource; } |
|
60 |
|
61 protected: |
|
62 |
|
63 /** |
|
64 * Draw the drag image, if any, to a surface and return it. The drag image |
|
65 * is constructed from mImage if specified, or aDOMNode if mImage is null. |
|
66 * |
|
67 * aRegion may be used to draw only a subset of the element. This region |
|
68 * should be supplied using x and y coordinates measured in css pixels |
|
69 * that are relative to the upper-left corner of the window. |
|
70 * |
|
71 * aScreenX and aScreenY should be the screen coordinates of the mouse click |
|
72 * for the drag. These are in global display pixels. |
|
73 * |
|
74 * On return, aScreenDragRect will contain the screen coordinates of the |
|
75 * area being dragged. This is used by the platform-specific part of the |
|
76 * drag service to determine the drag feedback. This rect will be in the |
|
77 * device pixels of the presContext. |
|
78 * |
|
79 * If there is no drag image, the returned surface will be null, but |
|
80 * aScreenDragRect will still be set to the drag area. |
|
81 * |
|
82 * aPresContext will be set to the nsPresContext used determined from |
|
83 * whichever of mImage or aDOMNode is used. |
|
84 */ |
|
85 nsresult DrawDrag(nsIDOMNode* aDOMNode, |
|
86 nsIScriptableRegion* aRegion, |
|
87 int32_t aScreenX, int32_t aScreenY, |
|
88 nsIntRect* aScreenDragRect, |
|
89 mozilla::RefPtr<SourceSurface>* aSurface, |
|
90 nsPresContext **aPresContext); |
|
91 |
|
92 /** |
|
93 * Draw a drag image for an image node specified by aImageLoader or aCanvas. |
|
94 * This is called by DrawDrag. |
|
95 */ |
|
96 nsresult DrawDragForImage(nsPresContext* aPresContext, |
|
97 nsIImageLoadingContent* aImageLoader, |
|
98 mozilla::dom::HTMLCanvasElement* aCanvas, |
|
99 int32_t aScreenX, int32_t aScreenY, |
|
100 nsIntRect* aScreenDragRect, |
|
101 mozilla::RefPtr<SourceSurface>* aSurface); |
|
102 |
|
103 /** |
|
104 * Convert aScreenX and aScreenY from CSS pixels into unscaled device pixels. |
|
105 */ |
|
106 void |
|
107 ConvertToUnscaledDevPixels(nsPresContext* aPresContext, |
|
108 int32_t* aScreenX, int32_t* aScreenY); |
|
109 |
|
110 /** |
|
111 * If the drag image is a popup, open the popup when the drag begins. |
|
112 */ |
|
113 void OpenDragPopup(); |
|
114 |
|
115 bool mCanDrop; |
|
116 bool mOnlyChromeDrop; |
|
117 bool mDoingDrag; |
|
118 // true if mImage should be used to set a drag image |
|
119 bool mHasImage; |
|
120 // true if the user cancelled the drag operation |
|
121 bool mUserCancelled; |
|
122 |
|
123 uint32_t mDragAction; |
|
124 nsSize mTargetSize; |
|
125 nsCOMPtr<nsIDOMNode> mSourceNode; |
|
126 nsCOMPtr<nsIDOMDocument> mSourceDocument; // the document at the drag source. will be null |
|
127 // if it came from outside the app. |
|
128 nsCOMPtr<nsIDOMDataTransfer> mDataTransfer; |
|
129 |
|
130 // used to determine the image to appear on the cursor while dragging |
|
131 nsCOMPtr<nsIDOMNode> mImage; |
|
132 // offset of cursor within the image |
|
133 int32_t mImageX; |
|
134 int32_t mImageY; |
|
135 |
|
136 // set if a selection is being dragged |
|
137 nsCOMPtr<nsISelection> mSelection; |
|
138 |
|
139 // set if the image in mImage is a popup. If this case, the popup will be opened |
|
140 // and moved instead of using a drag image. |
|
141 nsCOMPtr<nsIContent> mDragPopup; |
|
142 |
|
143 // the screen position where drag gesture occurred, used for positioning the |
|
144 // drag image when no image is specified. If a value is -1, no event was |
|
145 // supplied so the screen position is not known |
|
146 int32_t mScreenX; |
|
147 int32_t mScreenY; |
|
148 |
|
149 // the screen position where the drag ended |
|
150 nsIntPoint mEndDragPoint; |
|
151 |
|
152 uint32_t mSuppressLevel; |
|
153 |
|
154 // The input source of the drag event. Possible values are from nsIDOMMouseEvent. |
|
155 uint16_t mInputSource; |
|
156 }; |
|
157 |
|
158 #endif // nsBaseDragService_h__ |