2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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-17 01:03:22 +04:00
|
|
|
|
|
|
|
#ifndef nsBaseDragService_h__
|
|
|
|
#define nsBaseDragService_h__
|
|
|
|
|
|
|
|
#include "nsIDragService.h"
|
1999-05-07 23:51:50 +04:00
|
|
|
#include "nsIDragSession.h"
|
1999-04-17 01:03:22 +04:00
|
|
|
#include "nsITransferable.h"
|
2000-08-01 00:51:42 +04:00
|
|
|
#include "nsIDOMDocument.h"
|
2008-08-27 16:07:27 +04:00
|
|
|
#include "nsIDOMDataTransfer.h"
|
2011-04-08 05:04:40 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2014-04-16 04:41:40 +04:00
|
|
|
#include "nsRect.h"
|
2011-04-08 05:04:40 +04:00
|
|
|
#include "nsPoint.h"
|
2015-10-18 08:24:48 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2015-04-08 21:48:11 +03:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
2014-04-17 09:30:45 +04:00
|
|
|
#include "mozilla/dom/HTMLCanvasElement.h"
|
2015-04-08 21:48:11 +03:00
|
|
|
#include "nsTArray.h"
|
2015-09-29 03:44:50 +03:00
|
|
|
#include "Units.h"
|
2007-03-20 15:14:52 +03:00
|
|
|
|
2007-03-26 07:27:53 +04:00
|
|
|
// translucency level for drag images
|
|
|
|
#define DRAG_TRANSLUCENCY 0.65
|
|
|
|
|
2013-03-22 04:05:20 +04:00
|
|
|
class nsIContent;
|
2000-08-16 05:46:34 +04:00
|
|
|
class nsIDOMNode;
|
2004-08-01 03:15:21 +04:00
|
|
|
class nsPresContext;
|
2007-03-20 15:14:52 +03:00
|
|
|
class nsIImageLoadingContent;
|
2000-08-16 05:46:34 +04:00
|
|
|
|
2014-01-29 04:10:33 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
class SourceSurface;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
2014-01-29 04:10:33 +04:00
|
|
|
|
1999-04-17 01:03:22 +04:00
|
|
|
/**
|
|
|
|
* XP DragService wrapper base class
|
|
|
|
*/
|
|
|
|
|
2005-03-15 01:49:00 +03:00
|
|
|
class nsBaseDragService : public nsIDragService,
|
|
|
|
public nsIDragSession
|
1999-04-17 01:03:22 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
2014-01-29 04:10:33 +04:00
|
|
|
typedef mozilla::gfx::SourceSurface SourceSurface;
|
|
|
|
|
1999-04-17 01:03:22 +04:00
|
|
|
nsBaseDragService();
|
|
|
|
|
|
|
|
//nsISupports
|
|
|
|
NS_DECL_ISUPPORTS
|
2005-03-15 01:49:00 +03:00
|
|
|
|
1999-09-05 06:28:38 +04:00
|
|
|
//nsIDragSession and nsIDragService
|
|
|
|
NS_DECL_NSIDRAGSERVICE
|
|
|
|
NS_DECL_NSIDRAGSESSION
|
1999-04-17 01:03:22 +04:00
|
|
|
|
2015-10-26 23:33:13 +03:00
|
|
|
void SetDragEndPoint(nsIntPoint aEndDragPoint)
|
|
|
|
{
|
2015-11-10 02:22:25 +03:00
|
|
|
mEndDragPoint = mozilla::LayoutDeviceIntPoint::FromUnknownPoint(aEndDragPoint);
|
2015-10-26 23:33:13 +03:00
|
|
|
}
|
|
|
|
void SetDragEndPoint(mozilla::LayoutDeviceIntPoint aEndDragPoint)
|
|
|
|
{
|
|
|
|
mEndDragPoint = aEndDragPoint;
|
|
|
|
}
|
2009-04-13 17:00:29 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t GetInputSource() { return mInputSource; }
|
2010-04-06 16:59:24 +04:00
|
|
|
|
2015-06-05 15:33:29 +03:00
|
|
|
int32_t TakeChildProcessDragAction();
|
|
|
|
|
1999-04-17 01:03:22 +04:00
|
|
|
protected:
|
2014-06-24 20:36:44 +04:00
|
|
|
virtual ~nsBaseDragService();
|
1999-04-17 01:03:22 +04:00
|
|
|
|
2015-10-21 12:16:40 +03: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 21:56:20 +03:00
|
|
|
virtual nsresult InvokeDragSessionImpl(nsIArray* aTransferableArray,
|
2015-10-21 12:16:40 +03:00
|
|
|
nsIScriptableRegion* aDragRgn,
|
|
|
|
uint32_t aActionType) = 0;
|
|
|
|
|
2007-03-20 15:14:52 +03: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 22:01:39 +03:00
|
|
|
* aScreenPosition should be the screen coordinates of the mouse click
|
|
|
|
* for the drag. These are in CSS pixels.
|
2007-03-20 15:14:52 +03: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-15 00:25:51 +04:00
|
|
|
* drag service to determine the drag feedback. This rect will be in the
|
|
|
|
* device pixels of the presContext.
|
2007-03-20 15:14:52 +03: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-09 01:03:53 +03:00
|
|
|
*
|
|
|
|
* aPresContext will be set to the nsPresContext used determined from
|
|
|
|
* whichever of mImage or aDOMNode is used.
|
2007-03-20 15:14:52 +03:00
|
|
|
*/
|
|
|
|
nsresult DrawDrag(nsIDOMNode* aDOMNode,
|
|
|
|
nsIScriptableRegion* aRegion,
|
2016-10-19 22:01:39 +03:00
|
|
|
mozilla::CSSIntPoint aScreenPosition,
|
2016-10-19 22:01:39 +03:00
|
|
|
mozilla::LayoutDeviceIntRect* aScreenDragRect,
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SourceSurface>* aSurface,
|
2008-01-09 01:03:53 +03:00
|
|
|
nsPresContext **aPresContext);
|
2007-03-20 15:14:52 +03:00
|
|
|
|
|
|
|
/**
|
2008-09-10 20: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 15:14:52 +03:00
|
|
|
*/
|
2016-10-19 22:01:40 +03:00
|
|
|
nsresult DrawDragForImage(nsPresContext *aPresContext,
|
|
|
|
nsIImageLoadingContent* aImageLoader,
|
2014-04-17 09:30:45 +04:00
|
|
|
mozilla::dom::HTMLCanvasElement* aCanvas,
|
2016-10-19 22:01:39 +03:00
|
|
|
mozilla::LayoutDeviceIntRect* aScreenDragRect,
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SourceSurface>* aSurface);
|
2007-03-20 15:14:52 +03:00
|
|
|
|
2008-01-09 01:03:53 +03:00
|
|
|
/**
|
2016-10-19 22:01:39 +03:00
|
|
|
* Convert aScreenPosition from CSS pixels into unscaled device pixels.
|
2008-01-09 01:03:53 +03:00
|
|
|
*/
|
2016-10-19 22:01:39 +03:00
|
|
|
mozilla::LayoutDeviceIntPoint
|
2008-01-09 01:03:53 +03:00
|
|
|
ConvertToUnscaledDevPixels(nsPresContext* aPresContext,
|
2016-10-19 22:01:39 +03:00
|
|
|
mozilla::CSSIntPoint aScreenPosition);
|
2008-01-09 01:03:53 +03:00
|
|
|
|
2011-04-26 05:37:20 +04:00
|
|
|
/**
|
|
|
|
* If the drag image is a popup, open the popup when the drag begins.
|
|
|
|
*/
|
|
|
|
void OpenDragPopup();
|
|
|
|
|
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-29 10:19:26 +04:00
|
|
|
bool mCanDrop;
|
|
|
|
bool mOnlyChromeDrop;
|
|
|
|
bool mDoingDrag;
|
2007-03-20 15:14:52 +03:00
|
|
|
// true if mImage should be used to set a drag image
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mHasImage;
|
2009-02-17 18:51:12 +03:00
|
|
|
// true if the user cancelled the drag operation
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mUserCancelled;
|
2007-03-20 15:14:52 +03:00
|
|
|
|
2015-04-08 21:48:11 +03:00
|
|
|
bool mDragEventDispatchedToChildProcess;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mDragAction;
|
2015-06-05 15:33:29 +03:00
|
|
|
uint32_t mDragActionFromChildProcess;
|
|
|
|
|
2005-03-15 01:49:00 +03:00
|
|
|
nsSize mTargetSize;
|
2001-05-20 09:58:25 +04:00
|
|
|
nsCOMPtr<nsIDOMNode> mSourceNode;
|
2000-08-01 00:51:42 +04:00
|
|
|
nsCOMPtr<nsIDOMDocument> mSourceDocument; // the document at the drag source. will be null
|
|
|
|
// if it came from outside the app.
|
2015-08-10 22:56:47 +03:00
|
|
|
nsContentPolicyType mContentPolicyType; // the contentpolicy type passed to the channel
|
|
|
|
// when initiating the drag session
|
2008-08-27 16:07:27 +04:00
|
|
|
nsCOMPtr<nsIDOMDataTransfer> mDataTransfer;
|
2007-03-20 15:14:52 +03:00
|
|
|
|
|
|
|
// used to determine the image to appear on the cursor while dragging
|
|
|
|
nsCOMPtr<nsIDOMNode> mImage;
|
2015-09-29 03:44:50 +03:00
|
|
|
// offset of cursor within the image
|
|
|
|
mozilla::CSSIntPoint mImageOffset;
|
2007-03-20 15:14:52 +03:00
|
|
|
|
|
|
|
// set if a selection is being dragged
|
|
|
|
nsCOMPtr<nsISelection> mSelection;
|
|
|
|
|
2011-04-26 05:37:20 +04: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 16:19:50 +04:00
|
|
|
// the screen position where drag gesture occurred, used for positioning the
|
2016-10-19 22:01:39 +03:00
|
|
|
// drag image.
|
|
|
|
mozilla::CSSIntPoint mScreenPosition;
|
2008-03-19 03:06:22 +03:00
|
|
|
|
2009-04-13 17:00:29 +04:00
|
|
|
// the screen position where the drag ended
|
2015-10-26 23:33:13 +03:00
|
|
|
mozilla::LayoutDeviceIntPoint mEndDragPoint;
|
2009-04-13 17:00:29 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mSuppressLevel;
|
2010-04-06 16:59:24 +04:00
|
|
|
|
2011-08-26 11:43:56 +04:00
|
|
|
// The input source of the drag event. Possible values are from nsIDOMMouseEvent.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t mInputSource;
|
2015-04-08 21:48:11 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<mozilla::dom::ContentParent>> mChildProcesses;
|
1999-04-17 01:03:22 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsBaseDragService_h__
|