1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/xpwidgets/nsBaseDragService.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,158 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef nsBaseDragService_h__ 1.10 +#define nsBaseDragService_h__ 1.11 + 1.12 +#include "nsIDragService.h" 1.13 +#include "nsIDragSession.h" 1.14 +#include "nsITransferable.h" 1.15 +#include "nsIDOMDocument.h" 1.16 +#include "nsIDOMDataTransfer.h" 1.17 +#include "nsCOMPtr.h" 1.18 +#include "nsRect.h" 1.19 +#include "nsPoint.h" 1.20 +#include "mozilla/RefPtr.h" 1.21 +#include "mozilla/dom/HTMLCanvasElement.h" 1.22 + 1.23 +// translucency level for drag images 1.24 +#define DRAG_TRANSLUCENCY 0.65 1.25 + 1.26 +class nsIContent; 1.27 +class nsIDOMNode; 1.28 +class nsIFrame; 1.29 +class nsPresContext; 1.30 +class nsIImageLoadingContent; 1.31 +class nsICanvasElementExternal; 1.32 + 1.33 +namespace mozilla { 1.34 +namespace gfx { 1.35 +class SourceSurface; 1.36 +} 1.37 +} 1.38 + 1.39 +/** 1.40 + * XP DragService wrapper base class 1.41 + */ 1.42 + 1.43 +class nsBaseDragService : public nsIDragService, 1.44 + public nsIDragSession 1.45 +{ 1.46 + 1.47 +public: 1.48 + typedef mozilla::gfx::SourceSurface SourceSurface; 1.49 + 1.50 + nsBaseDragService(); 1.51 + virtual ~nsBaseDragService(); 1.52 + 1.53 + //nsISupports 1.54 + NS_DECL_ISUPPORTS 1.55 + 1.56 + //nsIDragSession and nsIDragService 1.57 + NS_DECL_NSIDRAGSERVICE 1.58 + NS_DECL_NSIDRAGSESSION 1.59 + 1.60 + void SetDragEndPoint(nsIntPoint aEndDragPoint) { mEndDragPoint = aEndDragPoint; } 1.61 + 1.62 + uint16_t GetInputSource() { return mInputSource; } 1.63 + 1.64 +protected: 1.65 + 1.66 + /** 1.67 + * Draw the drag image, if any, to a surface and return it. The drag image 1.68 + * is constructed from mImage if specified, or aDOMNode if mImage is null. 1.69 + * 1.70 + * aRegion may be used to draw only a subset of the element. This region 1.71 + * should be supplied using x and y coordinates measured in css pixels 1.72 + * that are relative to the upper-left corner of the window. 1.73 + * 1.74 + * aScreenX and aScreenY should be the screen coordinates of the mouse click 1.75 + * for the drag. These are in global display pixels. 1.76 + * 1.77 + * On return, aScreenDragRect will contain the screen coordinates of the 1.78 + * area being dragged. This is used by the platform-specific part of the 1.79 + * drag service to determine the drag feedback. This rect will be in the 1.80 + * device pixels of the presContext. 1.81 + * 1.82 + * If there is no drag image, the returned surface will be null, but 1.83 + * aScreenDragRect will still be set to the drag area. 1.84 + * 1.85 + * aPresContext will be set to the nsPresContext used determined from 1.86 + * whichever of mImage or aDOMNode is used. 1.87 + */ 1.88 + nsresult DrawDrag(nsIDOMNode* aDOMNode, 1.89 + nsIScriptableRegion* aRegion, 1.90 + int32_t aScreenX, int32_t aScreenY, 1.91 + nsIntRect* aScreenDragRect, 1.92 + mozilla::RefPtr<SourceSurface>* aSurface, 1.93 + nsPresContext **aPresContext); 1.94 + 1.95 + /** 1.96 + * Draw a drag image for an image node specified by aImageLoader or aCanvas. 1.97 + * This is called by DrawDrag. 1.98 + */ 1.99 + nsresult DrawDragForImage(nsPresContext* aPresContext, 1.100 + nsIImageLoadingContent* aImageLoader, 1.101 + mozilla::dom::HTMLCanvasElement* aCanvas, 1.102 + int32_t aScreenX, int32_t aScreenY, 1.103 + nsIntRect* aScreenDragRect, 1.104 + mozilla::RefPtr<SourceSurface>* aSurface); 1.105 + 1.106 + /** 1.107 + * Convert aScreenX and aScreenY from CSS pixels into unscaled device pixels. 1.108 + */ 1.109 + void 1.110 + ConvertToUnscaledDevPixels(nsPresContext* aPresContext, 1.111 + int32_t* aScreenX, int32_t* aScreenY); 1.112 + 1.113 + /** 1.114 + * If the drag image is a popup, open the popup when the drag begins. 1.115 + */ 1.116 + void OpenDragPopup(); 1.117 + 1.118 + bool mCanDrop; 1.119 + bool mOnlyChromeDrop; 1.120 + bool mDoingDrag; 1.121 + // true if mImage should be used to set a drag image 1.122 + bool mHasImage; 1.123 + // true if the user cancelled the drag operation 1.124 + bool mUserCancelled; 1.125 + 1.126 + uint32_t mDragAction; 1.127 + nsSize mTargetSize; 1.128 + nsCOMPtr<nsIDOMNode> mSourceNode; 1.129 + nsCOMPtr<nsIDOMDocument> mSourceDocument; // the document at the drag source. will be null 1.130 + // if it came from outside the app. 1.131 + nsCOMPtr<nsIDOMDataTransfer> mDataTransfer; 1.132 + 1.133 + // used to determine the image to appear on the cursor while dragging 1.134 + nsCOMPtr<nsIDOMNode> mImage; 1.135 + // offset of cursor within the image 1.136 + int32_t mImageX; 1.137 + int32_t mImageY; 1.138 + 1.139 + // set if a selection is being dragged 1.140 + nsCOMPtr<nsISelection> mSelection; 1.141 + 1.142 + // set if the image in mImage is a popup. If this case, the popup will be opened 1.143 + // and moved instead of using a drag image. 1.144 + nsCOMPtr<nsIContent> mDragPopup; 1.145 + 1.146 + // the screen position where drag gesture occurred, used for positioning the 1.147 + // drag image when no image is specified. If a value is -1, no event was 1.148 + // supplied so the screen position is not known 1.149 + int32_t mScreenX; 1.150 + int32_t mScreenY; 1.151 + 1.152 + // the screen position where the drag ended 1.153 + nsIntPoint mEndDragPoint; 1.154 + 1.155 + uint32_t mSuppressLevel; 1.156 + 1.157 + // The input source of the drag event. Possible values are from nsIDOMMouseEvent. 1.158 + uint16_t mInputSource; 1.159 +}; 1.160 + 1.161 +#endif // nsBaseDragService_h__