2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 12:12:37 +01: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"
|
2011-04-07 18:04:40 -07:00
|
|
|
#include "nsCOMPtr.h"
|
2014-04-16 01:41:40 +01:00
|
|
|
#include "nsRect.h"
|
2011-04-07 18:04:40 -07:00
|
|
|
#include "nsPoint.h"
|
2018-02-09 10:43:53 +09:00
|
|
|
#include "nsString.h"
|
2015-10-18 01:24:48 -04:00
|
|
|
#include "mozilla/RefPtr.h"
|
2015-04-08 21:48:11 +03:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
2014-04-17 17:30:45 +12:00
|
|
|
#include "mozilla/dom/HTMLCanvasElement.h"
|
2015-04-08 21:48:11 +03:00
|
|
|
#include "nsTArray.h"
|
2015-09-28 20:44:50 -04:00
|
|
|
#include "Units.h"
|
2007-03-20 12:14:52 +00:00
|
|
|
|
2007-03-25 20:27:53 -07:00
|
|
|
// translucency level for drag images
|
|
|
|
#define DRAG_TRANSLUCENCY 0.65
|
|
|
|
|
2013-03-21 20:05:20 -04:00
|
|
|
class nsIContent;
|
2000-08-16 01:46:34 +00:00
|
|
|
class nsIDOMNode;
|
2018-05-11 19:46:15 +02:00
|
|
|
class nsIDocument;
|
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 13:10:33 +13:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
class SourceSurface;
|
2015-07-13 08:25:42 -07:00
|
|
|
} // namespace gfx
|
2018-03-13 16:23:59 -04:00
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
class DataTransfer;
|
2018-03-27 00:35:22 -04:00
|
|
|
class Selection;
|
2018-03-13 16:23:59 -04:00
|
|
|
} // namespace dom
|
2015-07-13 08:25:42 -07:00
|
|
|
} // namespace mozilla
|
2014-01-29 13:10:33 +13: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 13:10:33 +13: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 13:33:13 -07:00
|
|
|
void SetDragEndPoint(nsIntPoint aEndDragPoint)
|
|
|
|
{
|
2015-11-09 18:22:25 -05:00
|
|
|
mEndDragPoint = mozilla::LayoutDeviceIntPoint::FromUnknownPoint(aEndDragPoint);
|
2015-10-26 13:33:13 -07:00
|
|
|
}
|
|
|
|
void SetDragEndPoint(mozilla::LayoutDeviceIntPoint aEndDragPoint)
|
|
|
|
{
|
|
|
|
mEndDragPoint = aEndDragPoint;
|
|
|
|
}
|
2009-04-13 09:00:29 -04:00
|
|
|
|
2012-08-22 11:56:38 -04:00
|
|
|
uint16_t GetInputSource() { return mInputSource; }
|
2010-04-06 15:59:24 +03:00
|
|
|
|
2015-06-05 08:33:29 -04:00
|
|
|
int32_t TakeChildProcessDragAction();
|
|
|
|
|
1999-04-16 21:03:22 +00:00
|
|
|
protected:
|
2014-06-24 12:36:44 -04:00
|
|
|
virtual ~nsBaseDragService();
|
1999-04-16 21:03:22 +00:00
|
|
|
|
2015-10-21 22:16:40 +13: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 11:56:20 -07:00
|
|
|
virtual nsresult InvokeDragSessionImpl(nsIArray* aTransferableArray,
|
2015-10-21 22:16:40 +13: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 15:01:39 -04: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 14:03:53 -08: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 15:01:39 -04:00
|
|
|
mozilla::CSSIntPoint aScreenPosition,
|
2016-10-19 15:01:39 -04:00
|
|
|
mozilla::LayoutDeviceIntRect* aScreenDragRect,
|
2015-10-18 01:24:48 -04:00
|
|
|
RefPtr<SourceSurface>* aSurface,
|
2008-01-08 14:03:53 -08:00
|
|
|
nsPresContext **aPresContext);
|
2007-03-20 12:14:52 +00:00
|
|
|
|
|
|
|
/**
|
2008-09-10 12:57:58 -04: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 15:01:40 -04:00
|
|
|
nsresult DrawDragForImage(nsPresContext *aPresContext,
|
|
|
|
nsIImageLoadingContent* aImageLoader,
|
2014-04-17 17:30:45 +12:00
|
|
|
mozilla::dom::HTMLCanvasElement* aCanvas,
|
2016-10-19 15:01:39 -04:00
|
|
|
mozilla::LayoutDeviceIntRect* aScreenDragRect,
|
2015-10-18 01:24:48 -04:00
|
|
|
RefPtr<SourceSurface>* aSurface);
|
2007-03-20 12:14:52 +00:00
|
|
|
|
2008-01-08 14:03:53 -08:00
|
|
|
/**
|
2016-10-19 15:01:39 -04:00
|
|
|
* Convert aScreenPosition from CSS pixels into unscaled device pixels.
|
2008-01-08 14:03:53 -08:00
|
|
|
*/
|
2016-10-19 15:01:39 -04:00
|
|
|
mozilla::LayoutDeviceIntPoint
|
2008-01-08 14:03:53 -08:00
|
|
|
ConvertToUnscaledDevPixels(nsPresContext* aPresContext,
|
2016-10-19 15:01:39 -04:00
|
|
|
mozilla::CSSIntPoint aScreenPosition);
|
2008-01-08 14:03:53 -08:00
|
|
|
|
2011-04-25 18:37:20 -07: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 21:48:11 +03: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-28 23:19:26 -07: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-28 23:19:26 -07:00
|
|
|
bool mHasImage;
|
2009-02-17 10:51:12 -05:00
|
|
|
// true if the user cancelled the drag operation
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mUserCancelled;
|
2007-03-20 12:14:52 +00:00
|
|
|
|
2015-04-08 21:48:11 +03:00
|
|
|
bool mDragEventDispatchedToChildProcess;
|
|
|
|
|
2012-08-22 11:56:38 -04:00
|
|
|
uint32_t mDragAction;
|
2015-06-05 08:33:29 -04: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;
|
2018-02-09 10:43:53 +09:00
|
|
|
nsCString mTriggeringPrincipalURISpec;
|
2018-05-11 19:46:15 +02:00
|
|
|
nsCOMPtr<nsIDocument> mSourceDocument; // the document at the drag source. will be null
|
2000-07-31 20:51:42 +00:00
|
|
|
// if it came from outside the app.
|
2015-08-10 12:56:47 -07:00
|
|
|
nsContentPolicyType mContentPolicyType; // the contentpolicy type passed to the channel
|
|
|
|
// when initiating the drag session
|
2018-03-13 16:23:59 -04:00
|
|
|
RefPtr<mozilla::dom::DataTransfer> 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-28 20:44:50 -04: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
|
2018-03-27 00:35:22 -04:00
|
|
|
RefPtr<mozilla::dom::Selection> mSelection;
|
2007-03-20 12:14:52 +00:00
|
|
|
|
2011-04-25 18:37:20 -07: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 14:19:50 +02:00
|
|
|
// the screen position where drag gesture occurred, used for positioning the
|
2016-10-19 15:01:39 -04:00
|
|
|
// drag image.
|
|
|
|
mozilla::CSSIntPoint mScreenPosition;
|
2008-03-18 17:06:22 -07:00
|
|
|
|
2009-04-13 09:00:29 -04:00
|
|
|
// the screen position where the drag ended
|
2015-10-26 13:33:13 -07:00
|
|
|
mozilla::LayoutDeviceIntPoint mEndDragPoint;
|
2009-04-13 09:00:29 -04:00
|
|
|
|
2012-08-22 11:56:38 -04:00
|
|
|
uint32_t mSuppressLevel;
|
2010-04-06 15:59:24 +03:00
|
|
|
|
2018-03-20 00:16:07 -04:00
|
|
|
// The input source of the drag event. Possible values are from MouseEvent.
|
2012-08-22 11:56:38 -04:00
|
|
|
uint16_t mInputSource;
|
2015-04-08 21:48:11 +03:00
|
|
|
|
2015-10-18 01:24:48 -04:00
|
|
|
nsTArray<RefPtr<mozilla::dom::ContentParent>> mChildProcesses;
|
1999-04-16 21:03:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsBaseDragService_h__
|