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