michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsBaseDragService_h__ michael@0: #define nsBaseDragService_h__ michael@0: michael@0: #include "nsIDragService.h" michael@0: #include "nsIDragSession.h" michael@0: #include "nsITransferable.h" michael@0: #include "nsIDOMDocument.h" michael@0: #include "nsIDOMDataTransfer.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsRect.h" michael@0: #include "nsPoint.h" michael@0: #include "mozilla/RefPtr.h" michael@0: #include "mozilla/dom/HTMLCanvasElement.h" michael@0: michael@0: // translucency level for drag images michael@0: #define DRAG_TRANSLUCENCY 0.65 michael@0: michael@0: class nsIContent; michael@0: class nsIDOMNode; michael@0: class nsIFrame; michael@0: class nsPresContext; michael@0: class nsIImageLoadingContent; michael@0: class nsICanvasElementExternal; michael@0: michael@0: namespace mozilla { michael@0: namespace gfx { michael@0: class SourceSurface; michael@0: } michael@0: } michael@0: michael@0: /** michael@0: * XP DragService wrapper base class michael@0: */ michael@0: michael@0: class nsBaseDragService : public nsIDragService, michael@0: public nsIDragSession michael@0: { michael@0: michael@0: public: michael@0: typedef mozilla::gfx::SourceSurface SourceSurface; michael@0: michael@0: nsBaseDragService(); michael@0: virtual ~nsBaseDragService(); michael@0: michael@0: //nsISupports michael@0: NS_DECL_ISUPPORTS michael@0: michael@0: //nsIDragSession and nsIDragService michael@0: NS_DECL_NSIDRAGSERVICE michael@0: NS_DECL_NSIDRAGSESSION michael@0: michael@0: void SetDragEndPoint(nsIntPoint aEndDragPoint) { mEndDragPoint = aEndDragPoint; } michael@0: michael@0: uint16_t GetInputSource() { return mInputSource; } michael@0: michael@0: protected: michael@0: michael@0: /** michael@0: * Draw the drag image, if any, to a surface and return it. The drag image michael@0: * is constructed from mImage if specified, or aDOMNode if mImage is null. michael@0: * michael@0: * aRegion may be used to draw only a subset of the element. This region michael@0: * should be supplied using x and y coordinates measured in css pixels michael@0: * that are relative to the upper-left corner of the window. michael@0: * michael@0: * aScreenX and aScreenY should be the screen coordinates of the mouse click michael@0: * for the drag. These are in global display pixels. michael@0: * michael@0: * On return, aScreenDragRect will contain the screen coordinates of the michael@0: * area being dragged. This is used by the platform-specific part of the michael@0: * drag service to determine the drag feedback. This rect will be in the michael@0: * device pixels of the presContext. michael@0: * michael@0: * If there is no drag image, the returned surface will be null, but michael@0: * aScreenDragRect will still be set to the drag area. michael@0: * michael@0: * aPresContext will be set to the nsPresContext used determined from michael@0: * whichever of mImage or aDOMNode is used. michael@0: */ michael@0: nsresult DrawDrag(nsIDOMNode* aDOMNode, michael@0: nsIScriptableRegion* aRegion, michael@0: int32_t aScreenX, int32_t aScreenY, michael@0: nsIntRect* aScreenDragRect, michael@0: mozilla::RefPtr* aSurface, michael@0: nsPresContext **aPresContext); michael@0: michael@0: /** michael@0: * Draw a drag image for an image node specified by aImageLoader or aCanvas. michael@0: * This is called by DrawDrag. michael@0: */ michael@0: nsresult DrawDragForImage(nsPresContext* aPresContext, michael@0: nsIImageLoadingContent* aImageLoader, michael@0: mozilla::dom::HTMLCanvasElement* aCanvas, michael@0: int32_t aScreenX, int32_t aScreenY, michael@0: nsIntRect* aScreenDragRect, michael@0: mozilla::RefPtr* aSurface); michael@0: michael@0: /** michael@0: * Convert aScreenX and aScreenY from CSS pixels into unscaled device pixels. michael@0: */ michael@0: void michael@0: ConvertToUnscaledDevPixels(nsPresContext* aPresContext, michael@0: int32_t* aScreenX, int32_t* aScreenY); michael@0: michael@0: /** michael@0: * If the drag image is a popup, open the popup when the drag begins. michael@0: */ michael@0: void OpenDragPopup(); michael@0: michael@0: bool mCanDrop; michael@0: bool mOnlyChromeDrop; michael@0: bool mDoingDrag; michael@0: // true if mImage should be used to set a drag image michael@0: bool mHasImage; michael@0: // true if the user cancelled the drag operation michael@0: bool mUserCancelled; michael@0: michael@0: uint32_t mDragAction; michael@0: nsSize mTargetSize; michael@0: nsCOMPtr mSourceNode; michael@0: nsCOMPtr mSourceDocument; // the document at the drag source. will be null michael@0: // if it came from outside the app. michael@0: nsCOMPtr mDataTransfer; michael@0: michael@0: // used to determine the image to appear on the cursor while dragging michael@0: nsCOMPtr mImage; michael@0: // offset of cursor within the image michael@0: int32_t mImageX; michael@0: int32_t mImageY; michael@0: michael@0: // set if a selection is being dragged michael@0: nsCOMPtr mSelection; michael@0: michael@0: // set if the image in mImage is a popup. If this case, the popup will be opened michael@0: // and moved instead of using a drag image. michael@0: nsCOMPtr mDragPopup; michael@0: michael@0: // the screen position where drag gesture occurred, used for positioning the michael@0: // drag image when no image is specified. If a value is -1, no event was michael@0: // supplied so the screen position is not known michael@0: int32_t mScreenX; michael@0: int32_t mScreenY; michael@0: michael@0: // the screen position where the drag ended michael@0: nsIntPoint mEndDragPoint; michael@0: michael@0: uint32_t mSuppressLevel; michael@0: michael@0: // The input source of the drag event. Possible values are from nsIDOMMouseEvent. michael@0: uint16_t mInputSource; michael@0: }; michael@0: michael@0: #endif // nsBaseDragService_h__