2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-04-16 21:03:22 +00:00
|
|
|
|
|
|
|
#ifndef nsBaseDragService_h__
|
|
|
|
#define nsBaseDragService_h__
|
|
|
|
|
|
|
|
#include "nsIDragService.h"
|
1999-05-07 19:51:50 +00:00
|
|
|
#include "nsIDragSession.h"
|
1999-04-16 21:03:22 +00:00
|
|
|
#include "nsITransferable.h"
|
2000-07-31 20:51:42 +00:00
|
|
|
#include "nsIDOMDocument.h"
|
2008-08-27 12:07:27 +00:00
|
|
|
#include "nsIDOMDataTransfer.h"
|
2011-04-08 01:04:40 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2014-04-16 00:41:40 +00:00
|
|
|
#include "nsRect.h"
|
2011-04-08 01:04:40 +00:00
|
|
|
#include "nsPoint.h"
|
2015-10-18 05:24:48 +00:00
|
|
|
#include "mozilla/RefPtr.h"
|
2015-04-08 18:48:11 +00:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
2014-04-17 05:30:45 +00:00
|
|
|
#include "mozilla/dom/HTMLCanvasElement.h"
|
2015-04-08 18:48:11 +00:00
|
|
|
#include "nsTArray.h"
|
2015-09-29 00:44:50 +00:00
|
|
|
#include "Units.h"
|
2007-03-20 12:14:52 +00:00
|
|
|
|
2007-03-26 03:27:53 +00:00
|
|
|
// translucency level for drag images
|
|
|
|
#define DRAG_TRANSLUCENCY 0.65
|
|
|
|
|
2013-03-22 00:05:20 +00:00
|
|
|
class nsIContent;
|
2000-08-16 01:46:34 +00:00
|
|
|
class nsIDOMNode;
|
2004-07-31 23:15:21 +00:00
|
|
|
class nsPresContext;
|
2007-03-20 12:14:52 +00:00
|
|
|
class nsIImageLoadingContent;
|
2000-08-16 01:46:34 +00:00
|
|
|
|
2014-01-29 00:10:33 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
class SourceSurface;
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
2014-01-29 00:10:33 +00:00
|
|
|
|
1999-04-16 21:03:22 +00:00
|
|
|
/**
|
|
|
|
* XP DragService wrapper base class
|
|
|
|
*/
|
|
|
|
|
2005-03-14 22:49:00 +00:00
|
|
|
class nsBaseDragService : public nsIDragService,
|
|
|
|
public nsIDragSession
|
1999-04-16 21:03:22 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
2014-01-29 00:10:33 +00:00
|
|
|
typedef mozilla::gfx::SourceSurface SourceSurface;
|
|
|
|
|
1999-04-16 21:03:22 +00:00
|
|
|
nsBaseDragService();
|
|
|
|
|
|
|
|
//nsISupports
|
|
|
|
NS_DECL_ISUPPORTS
|
2005-03-14 22:49:00 +00:00
|
|
|
|
1999-09-05 02:28:38 +00:00
|
|
|
//nsIDragSession and nsIDragService
|
|
|
|
NS_DECL_NSIDRAGSERVICE
|
|
|
|
NS_DECL_NSIDRAGSESSION
|
1999-04-16 21:03:22 +00:00
|
|
|
|
2015-10-26 20:33:13 +00:00
|
|
|
void SetDragEndPoint(nsIntPoint aEndDragPoint)
|
|
|
|
{
|
2015-11-09 23:22:25 +00:00
|
|
|
mEndDragPoint = mozilla::LayoutDeviceIntPoint::FromUnknownPoint(aEndDragPoint);
|
2015-10-26 20:33:13 +00:00
|
|
|
}
|
|
|
|
void SetDragEndPoint(mozilla::LayoutDeviceIntPoint aEndDragPoint)
|
|
|
|
{
|
|
|
|
mEndDragPoint = aEndDragPoint;
|
|
|
|
}
|
2009-04-13 13:00:29 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint16_t GetInputSource() { return mInputSource; }
|
2010-04-06 12:59:24 +00:00
|
|
|
|
2015-06-05 12:33:29 +00:00
|
|
|
int32_t TakeChildProcessDragAction();
|
|
|
|
|
1999-04-16 21:03:22 +00:00
|
|
|
protected:
|
2014-06-24 16:36:44 +00:00
|
|
|
virtual ~nsBaseDragService();
|
1999-04-16 21:03:22 +00:00
|
|
|
|
2015-10-21 09:16:40 +00:00
|
|
|
/**
|
|
|
|
* Called from nsBaseDragService to initiate a platform drag from a source
|
|
|
|
* in this process. This is expected to ensure that StartDragSession() and
|
|
|
|
* EndDragSession() get called if the platform drag is successfully invoked.
|
|
|
|
*/
|
2016-10-18 18:56:20 +00:00
|
|
|
virtual nsresult InvokeDragSessionImpl(nsIArray* aTransferableArray,
|
2015-10-21 09:16:40 +00:00
|
|
|
nsIScriptableRegion* aDragRgn,
|
|
|
|
uint32_t aActionType) = 0;
|
|
|
|
|
2007-03-20 12:14:52 +00:00
|
|
|
/**
|
|
|
|
* Draw the drag image, if any, to a surface and return it. The drag image
|
|
|
|
* is constructed from mImage if specified, or aDOMNode if mImage is null.
|
|
|
|
*
|
|
|
|
* aRegion may be used to draw only a subset of the element. This region
|
|
|
|
* should be supplied using x and y coordinates measured in css pixels
|
|
|
|
* that are relative to the upper-left corner of the window.
|
|
|
|
*
|
2016-10-19 19:01:39 +00:00
|
|
|
* aScreenPosition should be the screen coordinates of the mouse click
|
|
|
|
* for the drag. These are in CSS pixels.
|
2007-03-20 12:14:52 +00:00
|
|
|
*
|
|
|
|
* On return, aScreenDragRect will contain the screen coordinates of the
|
|
|
|
* area being dragged. This is used by the platform-specific part of the
|
2012-12-14 20:25:51 +00:00
|
|
|
* drag service to determine the drag feedback. This rect will be in the
|
|
|
|
* device pixels of the presContext.
|
2007-03-20 12:14:52 +00:00
|
|
|
*
|
|
|
|
* If there is no drag image, the returned surface will be null, but
|
|
|
|
* aScreenDragRect will still be set to the drag area.
|
2008-01-08 22:03:53 +00:00
|
|
|
*
|
|
|
|
* aPresContext will be set to the nsPresContext used determined from
|
|
|
|
* whichever of mImage or aDOMNode is used.
|
2007-03-20 12:14:52 +00:00
|
|
|
*/
|
|
|
|
nsresult DrawDrag(nsIDOMNode* aDOMNode,
|
|
|
|
nsIScriptableRegion* aRegion,
|
2016-10-19 19:01:39 +00:00
|
|
|
mozilla::CSSIntPoint aScreenPosition,
|
2016-10-19 19:01:39 +00:00
|
|
|
mozilla::LayoutDeviceIntRect* aScreenDragRect,
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<SourceSurface>* aSurface,
|
2008-01-08 22:03:53 +00:00
|
|
|
nsPresContext **aPresContext);
|
2007-03-20 12:14:52 +00:00
|
|
|
|
|
|
|
/**
|
2008-09-10 16:57:58 +00:00
|
|
|
* Draw a drag image for an image node specified by aImageLoader or aCanvas.
|
|
|
|
* This is called by DrawDrag.
|
2007-03-20 12:14:52 +00:00
|
|
|
*/
|
2016-10-19 19:01:40 +00:00
|
|
|
nsresult DrawDragForImage(nsPresContext *aPresContext,
|
|
|
|
nsIImageLoadingContent* aImageLoader,
|
2014-04-17 05:30:45 +00:00
|
|
|
mozilla::dom::HTMLCanvasElement* aCanvas,
|
2016-10-19 19:01:39 +00:00
|
|
|
mozilla::LayoutDeviceIntRect* aScreenDragRect,
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<SourceSurface>* aSurface);
|
2007-03-20 12:14:52 +00:00
|
|
|
|
2008-01-08 22:03:53 +00:00
|
|
|
/**
|
2016-10-19 19:01:39 +00:00
|
|
|
* Convert aScreenPosition from CSS pixels into unscaled device pixels.
|
2008-01-08 22:03:53 +00:00
|
|
|
*/
|
2016-10-19 19:01:39 +00:00
|
|
|
mozilla::LayoutDeviceIntPoint
|
2008-01-08 22:03:53 +00:00
|
|
|
ConvertToUnscaledDevPixels(nsPresContext* aPresContext,
|
2016-10-19 19:01:39 +00:00
|
|
|
mozilla::CSSIntPoint aScreenPosition);
|
2008-01-08 22:03:53 +00:00
|
|
|
|
2011-04-26 01:37:20 +00:00
|
|
|
/**
|
|
|
|
* If the drag image is a popup, open the popup when the drag begins.
|
|
|
|
*/
|
|
|
|
void OpenDragPopup();
|
|
|
|
|
2016-11-28 11:39:22 +00:00
|
|
|
/**
|
|
|
|
* Free resources contained in DataTransferItems that aren't needed by JS.
|
|
|
|
*/
|
|
|
|
void DiscardInternalTransferData();
|
|
|
|
|
2015-04-08 18:48:11 +00:00
|
|
|
// Returns true if a drag event was dispatched to a child process after
|
|
|
|
// the previous TakeDragEventDispatchedToChildProcess() call.
|
|
|
|
bool TakeDragEventDispatchedToChildProcess()
|
|
|
|
{
|
|
|
|
bool retval = mDragEventDispatchedToChildProcess;
|
|
|
|
mDragEventDispatchedToChildProcess = false;
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mCanDrop;
|
|
|
|
bool mOnlyChromeDrop;
|
|
|
|
bool mDoingDrag;
|
2007-03-20 12:14:52 +00:00
|
|
|
// true if mImage should be used to set a drag image
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mHasImage;
|
2009-02-17 15:51:12 +00:00
|
|
|
// true if the user cancelled the drag operation
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mUserCancelled;
|
2007-03-20 12:14:52 +00:00
|
|
|
|
2015-04-08 18:48:11 +00:00
|
|
|
bool mDragEventDispatchedToChildProcess;
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mDragAction;
|
2015-06-05 12:33:29 +00:00
|
|
|
uint32_t mDragActionFromChildProcess;
|
|
|
|
|
2005-03-14 22:49:00 +00:00
|
|
|
nsSize mTargetSize;
|
2001-05-20 05:58:25 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> mSourceNode;
|
2000-07-31 20:51:42 +00:00
|
|
|
nsCOMPtr<nsIDOMDocument> mSourceDocument; // the document at the drag source. will be null
|
|
|
|
// if it came from outside the app.
|
2015-08-10 19:56:47 +00:00
|
|
|
nsContentPolicyType mContentPolicyType; // the contentpolicy type passed to the channel
|
|
|
|
// when initiating the drag session
|
2008-08-27 12:07:27 +00:00
|
|
|
nsCOMPtr<nsIDOMDataTransfer> mDataTransfer;
|
2007-03-20 12:14:52 +00:00
|
|
|
|
|
|
|
// used to determine the image to appear on the cursor while dragging
|
|
|
|
nsCOMPtr<nsIDOMNode> mImage;
|
2015-09-29 00:44:50 +00:00
|
|
|
// offset of cursor within the image
|
|
|
|
mozilla::CSSIntPoint mImageOffset;
|
2007-03-20 12:14:52 +00:00
|
|
|
|
|
|
|
// set if a selection is being dragged
|
|
|
|
nsCOMPtr<nsISelection> mSelection;
|
|
|
|
|
2011-04-26 01:37:20 +00:00
|
|
|
// set if the image in mImage is a popup. If this case, the popup will be opened
|
|
|
|
// and moved instead of using a drag image.
|
|
|
|
nsCOMPtr<nsIContent> mDragPopup;
|
|
|
|
|
2010-05-13 12:19:50 +00:00
|
|
|
// the screen position where drag gesture occurred, used for positioning the
|
2016-10-19 19:01:39 +00:00
|
|
|
// drag image.
|
|
|
|
mozilla::CSSIntPoint mScreenPosition;
|
2008-03-19 00:06:22 +00:00
|
|
|
|
2009-04-13 13:00:29 +00:00
|
|
|
// the screen position where the drag ended
|
2015-10-26 20:33:13 +00:00
|
|
|
mozilla::LayoutDeviceIntPoint mEndDragPoint;
|
2009-04-13 13:00:29 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mSuppressLevel;
|
2010-04-06 12:59:24 +00:00
|
|
|
|
2011-08-26 07:43:56 +00:00
|
|
|
// The input source of the drag event. Possible values are from nsIDOMMouseEvent.
|
2012-08-22 15:56:38 +00:00
|
|
|
uint16_t mInputSource;
|
2015-04-08 18:48:11 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
nsTArray<RefPtr<mozilla::dom::ContentParent>> mChildProcesses;
|
1999-04-16 21:03:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsBaseDragService_h__
|