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:32 +04:00
|
|
|
|
|
|
|
#include "nsBaseDragService.h"
|
|
|
|
#include "nsITransferable.h"
|
|
|
|
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsITransferable.h"
|
|
|
|
#include "nsSize.h"
|
2002-09-04 03:36:13 +04:00
|
|
|
#include "nsXPCOM.h"
|
1999-08-25 12:35:06 +04:00
|
|
|
#include "nsISupportsPrimitives.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2007-03-20 15:14:52 +03:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2000-08-16 05:46:34 +04:00
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIPresShell.h"
|
2013-01-05 07:12:24 +04:00
|
|
|
#include "nsViewManager.h"
|
2000-08-16 05:46:34 +04:00
|
|
|
#include "nsIDOMNode.h"
|
2008-08-27 16:07:27 +04:00
|
|
|
#include "nsIDOMDragEvent.h"
|
2007-03-20 15:14:52 +03:00
|
|
|
#include "nsISelection.h"
|
|
|
|
#include "nsISelectionPrivate.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2008-08-27 16:07:27 +04:00
|
|
|
#include "nsIDOMDataTransfer.h"
|
2007-03-20 15:14:52 +03:00
|
|
|
#include "nsIImageLoadingContent.h"
|
|
|
|
#include "imgIContainer.h"
|
|
|
|
#include "imgIRequest.h"
|
2014-08-23 00:12:38 +04:00
|
|
|
#include "ImageRegion.h"
|
2007-03-20 15:14:52 +03:00
|
|
|
#include "nsRegion.h"
|
2011-04-26 05:37:20 +04:00
|
|
|
#include "nsXULPopupManager.h"
|
|
|
|
#include "nsMenuPopupFrame.h"
|
2014-08-23 00:12:38 +04:00
|
|
|
#include "SVGImageContext.h"
|
2013-09-25 15:21:18 +04:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2011-05-23 18:54:03 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2014-01-29 04:10:33 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2016-08-23 07:09:32 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2015-04-08 21:48:11 +03:00
|
|
|
#include "nsFrameLoader.h"
|
|
|
|
#include "TabParent.h"
|
2007-03-20 15:14:52 +03:00
|
|
|
|
|
|
|
#include "gfxContext.h"
|
2009-04-22 16:55:51 +04:00
|
|
|
#include "gfxPlatform.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2007-03-20 15:14:52 +03:00
|
|
|
|
2011-05-23 18:54:03 +04:00
|
|
|
using namespace mozilla;
|
2014-04-17 09:30:45 +04:00
|
|
|
using namespace mozilla::dom;
|
2014-08-23 00:12:38 +04:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
using namespace mozilla::image;
|
2011-05-23 18:54:03 +04:00
|
|
|
|
2007-05-16 22:05:23 +04:00
|
|
|
#define DRAGIMAGES_PREF "nglayout.enable_drag_images"
|
|
|
|
|
2005-03-15 01:49:00 +03:00
|
|
|
nsBaseDragService::nsBaseDragService()
|
2011-10-17 18:59:28 +04:00
|
|
|
: mCanDrop(false), mOnlyChromeDrop(false), mDoingDrag(false),
|
|
|
|
mHasImage(false), mUserCancelled(false),
|
2015-04-08 21:48:11 +03:00
|
|
|
mDragEventDispatchedToChildProcess(false),
|
2015-06-05 15:33:29 +03:00
|
|
|
mDragAction(DRAGDROP_ACTION_NONE),
|
|
|
|
mDragActionFromChildProcess(DRAGDROP_ACTION_UNINITIALIZED), mTargetSize(0,0),
|
2015-08-10 22:56:47 +03:00
|
|
|
mContentPolicyType(nsIContentPolicy::TYPE_OTHER),
|
2016-10-19 22:01:39 +03:00
|
|
|
mSuppressLevel(0), mInputSource(nsIDOMMouseEvent::MOZ_SOURCE_MOUSE)
|
1999-04-17 01:03:32 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsBaseDragService::~nsBaseDragService()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsBaseDragService, nsIDragService, nsIDragSession)
|
1999-04-17 01:03:32 +04:00
|
|
|
|
|
|
|
//---------------------------------------------------------
|
2005-03-15 01:49:00 +03:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsBaseDragService::SetCanDrop(bool aCanDrop)
|
1999-04-17 01:03:32 +04:00
|
|
|
{
|
2005-03-15 01:49:00 +03:00
|
|
|
mCanDrop = aCanDrop;
|
|
|
|
return NS_OK;
|
1999-04-17 01:03:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
2005-03-15 01:49:00 +03:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsBaseDragService::GetCanDrop(bool * aCanDrop)
|
1999-04-17 01:03:32 +04:00
|
|
|
{
|
|
|
|
*aCanDrop = mCanDrop;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-10-29 14:11:02 +03:00
|
|
|
//---------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsBaseDragService::SetOnlyChromeDrop(bool aOnlyChrome)
|
2009-10-29 14:11:02 +03:00
|
|
|
{
|
|
|
|
mOnlyChromeDrop = aOnlyChrome;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsBaseDragService::GetOnlyChromeDrop(bool* aOnlyChrome)
|
2009-10-29 14:11:02 +03:00
|
|
|
{
|
|
|
|
*aOnlyChrome = mOnlyChromeDrop;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-04-17 01:03:32 +04:00
|
|
|
|
1999-04-23 18:13:06 +04:00
|
|
|
//---------------------------------------------------------
|
2005-03-15 01:49:00 +03:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsBaseDragService::SetDragAction(uint32_t anAction)
|
1999-04-23 18:13:06 +04:00
|
|
|
{
|
2005-03-16 03:40:21 +03:00
|
|
|
mDragAction = anAction;
|
|
|
|
return NS_OK;
|
1999-04-23 18:13:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
2005-03-15 01:49:00 +03:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsBaseDragService::GetDragAction(uint32_t * anAction)
|
1999-04-23 18:13:06 +04:00
|
|
|
{
|
|
|
|
*anAction = mDragAction;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-04-17 01:03:32 +04:00
|
|
|
//---------------------------------------------------------
|
2005-03-15 01:49:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseDragService::SetTargetSize(nsSize aDragTargetSize)
|
1999-04-17 01:03:32 +04:00
|
|
|
{
|
2005-03-15 01:49:00 +03:00
|
|
|
mTargetSize = aDragTargetSize;
|
|
|
|
return NS_OK;
|
1999-04-17 01:03:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
2005-03-15 01:49:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseDragService::GetTargetSize(nsSize * aDragTargetSize)
|
1999-04-17 01:03:32 +04:00
|
|
|
{
|
|
|
|
*aDragTargetSize = mTargetSize;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-05-27 01:08:14 +04:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
2005-03-15 01:49:00 +03:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsBaseDragService::GetNumDropItems(uint32_t * aNumItems)
|
1999-05-27 01:08:14 +04:00
|
|
|
{
|
|
|
|
*aNumItems = 0;
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-01 00:51:42 +04:00
|
|
|
//
|
|
|
|
// GetSourceDocument
|
|
|
|
//
|
|
|
|
// Returns the DOM document where the drag was initiated. This will be
|
2012-07-30 18:20:58 +04:00
|
|
|
// nullptr if the drag began outside of our application.
|
2000-08-01 00:51:42 +04:00
|
|
|
//
|
|
|
|
NS_IMETHODIMP
|
2005-03-15 01:49:00 +03:00
|
|
|
nsBaseDragService::GetSourceDocument(nsIDOMDocument** aSourceDocument)
|
2000-08-01 00:51:42 +04:00
|
|
|
{
|
|
|
|
*aSourceDocument = mSourceDocument.get();
|
2005-03-15 01:49:00 +03:00
|
|
|
NS_IF_ADDREF(*aSourceDocument);
|
|
|
|
|
2000-08-01 00:51:42 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-05-20 09:58:25 +04:00
|
|
|
//
|
|
|
|
// GetSourceNode
|
|
|
|
//
|
|
|
|
// Returns the DOM node where the drag was initiated. This will be
|
2012-07-30 18:20:58 +04:00
|
|
|
// nullptr if the drag began outside of our application.
|
2001-05-20 09:58:25 +04:00
|
|
|
//
|
|
|
|
NS_IMETHODIMP
|
2005-03-15 01:49:00 +03:00
|
|
|
nsBaseDragService::GetSourceNode(nsIDOMNode** aSourceNode)
|
2001-05-20 09:58:25 +04:00
|
|
|
{
|
|
|
|
*aSourceNode = mSourceNode.get();
|
2005-03-15 01:49:00 +03:00
|
|
|
NS_IF_ADDREF(*aSourceNode);
|
|
|
|
|
2001-05-20 09:58:25 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-04-17 01:03:32 +04:00
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
1999-05-27 01:08:14 +04:00
|
|
|
|
2005-03-15 01:49:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseDragService::GetData(nsITransferable * aTransferable,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aItemIndex)
|
1999-05-07 23:51:50 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
2005-03-15 01:49:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseDragService::IsDataFlavorSupported(const char *aDataFlavor,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool *_retval)
|
1999-05-07 23:51:50 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1999-04-17 01:03:32 +04:00
|
|
|
|
2008-08-27 16:07:27 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseDragService::GetDataTransfer(nsIDOMDataTransfer** aDataTransfer)
|
|
|
|
{
|
|
|
|
*aDataTransfer = mDataTransfer;
|
|
|
|
NS_IF_ADDREF(*aDataTransfer);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseDragService::SetDataTransfer(nsIDOMDataTransfer* aDataTransfer)
|
|
|
|
{
|
|
|
|
mDataTransfer = aDataTransfer;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-05-07 23:51:50 +04:00
|
|
|
//-------------------------------------------------------------------------
|
2005-03-15 01:49:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseDragService::InvokeDragSession(nsIDOMNode *aDOMNode,
|
2016-10-18 21:56:20 +03:00
|
|
|
nsIArray* aTransferableArray,
|
2007-03-20 15:14:52 +03:00
|
|
|
nsIScriptableRegion* aDragRgn,
|
2015-08-10 22:56:47 +03:00
|
|
|
uint32_t aActionType,
|
|
|
|
nsContentPolicyType aContentPolicyType =
|
|
|
|
nsIContentPolicy::TYPE_OTHER)
|
1999-04-17 01:03:32 +04:00
|
|
|
{
|
2016-01-15 13:38:03 +03:00
|
|
|
PROFILER_LABEL_FUNC(js::ProfileEntry::Category::OTHER);
|
|
|
|
|
2005-03-16 03:40:21 +03:00
|
|
|
NS_ENSURE_TRUE(aDOMNode, NS_ERROR_INVALID_ARG);
|
2008-03-19 03:06:22 +03:00
|
|
|
NS_ENSURE_TRUE(mSuppressLevel == 0, NS_ERROR_FAILURE);
|
2005-03-16 03:40:21 +03:00
|
|
|
|
|
|
|
// stash the document of the dom node
|
|
|
|
aDOMNode->GetOwnerDocument(getter_AddRefs(mSourceDocument));
|
|
|
|
mSourceNode = aDOMNode;
|
2015-08-10 22:56:47 +03:00
|
|
|
mContentPolicyType = aContentPolicyType;
|
2015-10-26 23:33:13 +03:00
|
|
|
mEndDragPoint = LayoutDeviceIntPoint(0, 0);
|
2005-03-16 03:40:21 +03:00
|
|
|
|
|
|
|
// When the mouse goes down, the selection code starts a mouse
|
|
|
|
// capture. However, this gets in the way of determining drag
|
|
|
|
// feedback for things like trees because the event coordinates
|
2009-09-13 17:13:16 +04:00
|
|
|
// are in the wrong coord system, so turn off mouse capture.
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIPresShell::ClearMouseCapture(nullptr);
|
2005-03-16 03:40:21 +03:00
|
|
|
|
2015-10-21 12:16:40 +03:00
|
|
|
nsresult rv = InvokeDragSessionImpl(aTransferableArray,
|
|
|
|
aDragRgn, aActionType);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mSourceNode = nullptr;
|
|
|
|
mSourceDocument = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
1999-04-17 01:03:32 +04:00
|
|
|
}
|
|
|
|
|
2007-03-20 15:14:52 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseDragService::InvokeDragSessionWithImage(nsIDOMNode* aDOMNode,
|
2016-10-18 21:56:20 +03:00
|
|
|
nsIArray* aTransferableArray,
|
2007-03-20 15:14:52 +03:00
|
|
|
nsIScriptableRegion* aRegion,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aActionType,
|
2007-03-20 15:14:52 +03:00
|
|
|
nsIDOMNode* aImage,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aImageX, int32_t aImageY,
|
2008-08-27 16:07:27 +04:00
|
|
|
nsIDOMDragEvent* aDragEvent,
|
|
|
|
nsIDOMDataTransfer* aDataTransfer)
|
2007-03-20 15:14:52 +03:00
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(aDragEvent, NS_ERROR_NULL_POINTER);
|
2008-08-27 16:07:27 +04:00
|
|
|
NS_ENSURE_TRUE(aDataTransfer, NS_ERROR_NULL_POINTER);
|
2008-03-19 03:06:22 +03:00
|
|
|
NS_ENSURE_TRUE(mSuppressLevel == 0, NS_ERROR_FAILURE);
|
2007-03-20 15:14:52 +03:00
|
|
|
|
2008-08-27 16:07:27 +04:00
|
|
|
mDataTransfer = aDataTransfer;
|
2012-07-30 18:20:58 +04:00
|
|
|
mSelection = nullptr;
|
2011-10-17 18:59:28 +04:00
|
|
|
mHasImage = true;
|
2012-07-30 18:20:58 +04:00
|
|
|
mDragPopup = nullptr;
|
2007-03-20 15:14:52 +03:00
|
|
|
mImage = aImage;
|
2015-09-29 03:44:50 +03:00
|
|
|
mImageOffset = CSSIntPoint(aImageX, aImageY);
|
2007-03-20 15:14:52 +03:00
|
|
|
|
2016-10-19 22:01:39 +03:00
|
|
|
aDragEvent->GetScreenX(&mScreenPosition.x);
|
|
|
|
aDragEvent->GetScreenY(&mScreenPosition.y);
|
2011-08-26 11:43:56 +04:00
|
|
|
aDragEvent->GetMozInputSource(&mInputSource);
|
2010-04-06 16:59:24 +04:00
|
|
|
|
2015-10-21 10:12:42 +03:00
|
|
|
nsresult rv = InvokeDragSession(aDOMNode, aTransferableArray,
|
2015-08-10 22:56:47 +03:00
|
|
|
aRegion, aActionType,
|
|
|
|
nsIContentPolicy::TYPE_INTERNAL_IMAGE);
|
2015-10-21 10:12:42 +03:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mImage = nullptr;
|
|
|
|
mHasImage = false;
|
|
|
|
mDataTransfer = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
2007-03-20 15:14:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseDragService::InvokeDragSessionWithSelection(nsISelection* aSelection,
|
2016-10-18 21:56:20 +03:00
|
|
|
nsIArray* aTransferableArray,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aActionType,
|
2008-08-27 16:07:27 +04:00
|
|
|
nsIDOMDragEvent* aDragEvent,
|
|
|
|
nsIDOMDataTransfer* aDataTransfer)
|
2007-03-20 15:14:52 +03:00
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(aSelection, NS_ERROR_NULL_POINTER);
|
|
|
|
NS_ENSURE_TRUE(aDragEvent, NS_ERROR_NULL_POINTER);
|
2008-03-19 03:06:22 +03:00
|
|
|
NS_ENSURE_TRUE(mSuppressLevel == 0, NS_ERROR_FAILURE);
|
2007-03-20 15:14:52 +03:00
|
|
|
|
2008-08-27 16:07:27 +04:00
|
|
|
mDataTransfer = aDataTransfer;
|
2007-03-20 15:14:52 +03:00
|
|
|
mSelection = aSelection;
|
2011-10-17 18:59:28 +04:00
|
|
|
mHasImage = true;
|
2012-07-30 18:20:58 +04:00
|
|
|
mDragPopup = nullptr;
|
|
|
|
mImage = nullptr;
|
2015-09-29 03:44:50 +03:00
|
|
|
mImageOffset = CSSIntPoint();
|
2007-03-20 15:14:52 +03:00
|
|
|
|
2016-10-19 22:01:39 +03:00
|
|
|
aDragEvent->GetScreenX(&mScreenPosition.x);
|
|
|
|
aDragEvent->GetScreenY(&mScreenPosition.y);
|
2011-08-26 11:43:56 +04:00
|
|
|
aDragEvent->GetMozInputSource(&mInputSource);
|
2010-04-06 16:59:24 +04:00
|
|
|
|
2007-03-20 15:14:52 +03:00
|
|
|
// just get the focused node from the selection
|
2008-08-27 16:07:27 +04:00
|
|
|
// XXXndeakin this should actually be the deepest node that contains both
|
|
|
|
// endpoints of the selection
|
2007-03-20 15:14:52 +03:00
|
|
|
nsCOMPtr<nsIDOMNode> node;
|
|
|
|
aSelection->GetFocusNode(getter_AddRefs(node));
|
|
|
|
|
2015-10-21 10:12:42 +03:00
|
|
|
nsresult rv = InvokeDragSession(node, aTransferableArray,
|
2015-08-10 22:56:47 +03:00
|
|
|
nullptr, aActionType,
|
|
|
|
nsIContentPolicy::TYPE_OTHER);
|
2015-10-21 10:12:42 +03:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mHasImage = false;
|
|
|
|
mSelection = nullptr;
|
|
|
|
mDataTransfer = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
2007-03-20 15:14:52 +03:00
|
|
|
}
|
1999-05-07 23:51:50 +04:00
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
2005-03-15 01:49:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseDragService::GetCurrentSession(nsIDragSession ** aSession)
|
1999-05-07 23:51:50 +04:00
|
|
|
{
|
2005-03-15 01:49:00 +03:00
|
|
|
if (!aSession)
|
1999-05-07 23:51:50 +04:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
2005-03-15 01:49:00 +03:00
|
|
|
|
|
|
|
// "this" also implements a drag session, so say we are one but only
|
|
|
|
// if there is currently a drag going on.
|
2008-03-19 03:06:22 +03:00
|
|
|
if (!mSuppressLevel && mDoingDrag) {
|
1999-05-07 23:51:50 +04:00
|
|
|
*aSession = this;
|
1999-08-25 12:35:06 +04:00
|
|
|
NS_ADDREF(*aSession); // addRef because we're a "getter"
|
1999-05-07 23:51:50 +04:00
|
|
|
}
|
|
|
|
else
|
2012-07-30 18:20:58 +04:00
|
|
|
*aSession = nullptr;
|
2005-03-15 01:49:00 +03:00
|
|
|
|
1999-05-07 23:51:50 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
2005-03-15 01:49:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseDragService::StartDragSession()
|
1999-05-07 23:51:50 +04:00
|
|
|
{
|
|
|
|
if (mDoingDrag) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
mDoingDrag = true;
|
2009-10-29 14:11:02 +03:00
|
|
|
// By default dispatch drop also to content.
|
2011-10-17 18:59:28 +04:00
|
|
|
mOnlyChromeDrop = false;
|
2011-04-26 05:37:20 +04:00
|
|
|
|
1999-05-07 23:51:50 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-04-26 05:37:20 +04:00
|
|
|
void
|
|
|
|
nsBaseDragService::OpenDragPopup()
|
|
|
|
{
|
|
|
|
if (mDragPopup) {
|
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm) {
|
2016-10-19 22:01:39 +03:00
|
|
|
pm->ShowPopupAtScreen(mDragPopup, mScreenPosition.x - mImageOffset.x,
|
|
|
|
mScreenPosition.y - mImageOffset.y, false, nullptr);
|
2011-04-26 05:37:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-05 15:33:29 +03:00
|
|
|
int32_t
|
|
|
|
nsBaseDragService::TakeChildProcessDragAction()
|
|
|
|
{
|
|
|
|
// If the last event was dispatched to the child process, use the drag action
|
|
|
|
// assigned from it instead and return it. DRAGDROP_ACTION_UNINITIALIZED is
|
|
|
|
// returned otherwise.
|
|
|
|
int32_t retval = DRAGDROP_ACTION_UNINITIALIZED;
|
|
|
|
if (TakeDragEventDispatchedToChildProcess() &&
|
|
|
|
mDragActionFromChildProcess != DRAGDROP_ACTION_UNINITIALIZED) {
|
|
|
|
retval = mDragActionFromChildProcess;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
1999-05-07 23:51:50 +04:00
|
|
|
//-------------------------------------------------------------------------
|
2005-03-15 01:49:00 +03:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsBaseDragService::EndDragSession(bool aDoneDrag)
|
1999-05-07 23:51:50 +04:00
|
|
|
{
|
|
|
|
if (!mDoingDrag) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2005-03-16 03:40:21 +03:00
|
|
|
|
2015-09-02 09:08:02 +03:00
|
|
|
if (aDoneDrag && !mSuppressLevel) {
|
|
|
|
FireDragEventAtSource(eDragEnd);
|
|
|
|
}
|
2007-04-12 08:37:39 +04:00
|
|
|
|
2011-04-26 05:37:20 +04:00
|
|
|
if (mDragPopup) {
|
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm) {
|
2014-04-08 16:45:52 +04:00
|
|
|
pm->HidePopup(mDragPopup, false, true, false, false);
|
2011-04-26 05:37:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-08 21:48:11 +03:00
|
|
|
for (uint32_t i = 0; i < mChildProcesses.Length(); ++i) {
|
2015-11-02 08:53:26 +03:00
|
|
|
mozilla::Unused << mChildProcesses[i]->SendEndDragSession(aDoneDrag,
|
2016-05-19 00:17:34 +03:00
|
|
|
mUserCancelled,
|
|
|
|
mEndDragPoint);
|
2015-04-08 21:48:11 +03:00
|
|
|
}
|
|
|
|
mChildProcesses.Clear();
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mDoingDrag = false;
|
2015-04-08 21:48:11 +03:00
|
|
|
mCanDrop = false;
|
2005-03-16 03:40:21 +03:00
|
|
|
|
|
|
|
// release the source we've been holding on to.
|
2012-07-30 18:20:58 +04:00
|
|
|
mSourceDocument = nullptr;
|
|
|
|
mSourceNode = nullptr;
|
|
|
|
mSelection = nullptr;
|
|
|
|
mDataTransfer = nullptr;
|
2011-10-17 18:59:28 +04:00
|
|
|
mHasImage = false;
|
|
|
|
mUserCancelled = false;
|
2012-07-30 18:20:58 +04:00
|
|
|
mDragPopup = nullptr;
|
|
|
|
mImage = nullptr;
|
2015-09-29 03:44:50 +03:00
|
|
|
mImageOffset = CSSIntPoint();
|
2016-10-19 22:01:39 +03:00
|
|
|
mScreenPosition = CSSIntPoint();
|
2015-10-26 23:33:13 +03:00
|
|
|
mEndDragPoint = LayoutDeviceIntPoint(0, 0);
|
2011-08-26 11:43:56 +04:00
|
|
|
mInputSource = nsIDOMMouseEvent::MOZ_SOURCE_MOUSE;
|
2007-03-20 15:14:52 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-04-12 08:37:39 +04:00
|
|
|
NS_IMETHODIMP
|
2015-09-14 18:18:29 +03:00
|
|
|
nsBaseDragService::FireDragEventAtSource(EventMessage aEventMessage)
|
2007-04-12 08:37:39 +04:00
|
|
|
{
|
2008-03-19 03:06:22 +03:00
|
|
|
if (mSourceNode && !mSuppressLevel) {
|
2007-04-12 08:37:39 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(mSourceDocument);
|
|
|
|
if (doc) {
|
2010-06-25 17:59:57 +04:00
|
|
|
nsCOMPtr<nsIPresShell> presShell = doc->GetShell();
|
2007-04-12 08:37:39 +04:00
|
|
|
if (presShell) {
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2015-09-14 18:18:29 +03:00
|
|
|
WidgetDragEvent event(true, aEventMessage, nullptr);
|
2010-04-06 16:59:24 +04:00
|
|
|
event.inputSource = mInputSource;
|
2015-09-14 18:18:29 +03:00
|
|
|
if (aEventMessage == eDragEnd) {
|
2016-04-18 17:09:02 +03:00
|
|
|
event.mRefPoint = mEndDragPoint;
|
2016-03-31 13:06:05 +03:00
|
|
|
event.mUserCancelled = mUserCancelled;
|
2009-04-13 17:00:29 +04:00
|
|
|
}
|
2007-04-12 08:37:39 +04:00
|
|
|
|
2016-04-18 21:24:28 +03:00
|
|
|
// Send the drag event to APZ, which needs to know about them to be
|
|
|
|
// able to accurately detect the end of a drag gesture.
|
|
|
|
if (nsPresContext* presContext = presShell->GetPresContext()) {
|
|
|
|
if (nsCOMPtr<nsIWidget> widget = presContext->GetRootWidget()) {
|
|
|
|
widget->DispatchEventToAPZOnly(&event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-12 08:37:39 +04:00
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(mSourceNode);
|
|
|
|
return presShell->HandleDOMEventWithTarget(content, &event, &status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-04-26 05:37:20 +04:00
|
|
|
/* This is used by Windows and Mac to update the position of a popup being
|
|
|
|
* used as a drag image during the drag. This isn't used on GTK as it manages
|
|
|
|
* the drag popup itself.
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsBaseDragService::DragMoved(int32_t aX, int32_t aY)
|
2011-04-26 05:37:20 +04:00
|
|
|
{
|
|
|
|
if (mDragPopup) {
|
|
|
|
nsIFrame* frame = mDragPopup->GetPrimaryFrame();
|
|
|
|
if (frame && frame->GetType() == nsGkAtoms::menuPopupFrame) {
|
2015-09-29 03:17:34 +03:00
|
|
|
CSSIntPoint cssPos = RoundedToInt(LayoutDeviceIntPoint(aX, aY) /
|
|
|
|
frame->PresContext()->CSSToDevPixelScale()) - mImageOffset;
|
|
|
|
(static_cast<nsMenuPopupFrame *>(frame))->MoveTo(cssPos, true);
|
2011-04-26 05:37:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-20 15:14:52 +03:00
|
|
|
static nsIPresShell*
|
|
|
|
GetPresShellForContent(nsIDOMNode* aDOMNode)
|
|
|
|
{
|
2007-03-29 01:18:11 +04:00
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(aDOMNode);
|
2010-02-28 14:18:19 +03:00
|
|
|
if (!content)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-02-28 14:18:19 +03:00
|
|
|
|
2016-03-31 14:46:32 +03:00
|
|
|
nsCOMPtr<nsIDocument> document = content->GetUncomposedDoc();
|
2007-03-20 15:14:52 +03:00
|
|
|
if (document) {
|
|
|
|
document->FlushPendingNotifications(Flush_Display);
|
|
|
|
|
2010-06-25 17:59:57 +04:00
|
|
|
return document->GetShell();
|
2007-03-20 15:14:52 +03:00
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2007-03-20 15:14:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsBaseDragService::DrawDrag(nsIDOMNode* aDOMNode,
|
|
|
|
nsIScriptableRegion* aRegion,
|
2016-10-19 22:01:39 +03:00
|
|
|
CSSIntPoint aScreenPosition,
|
2016-10-19 22:01:39 +03:00
|
|
|
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
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aSurface = nullptr;
|
|
|
|
*aPresContext = nullptr;
|
2007-03-20 15:14:52 +03:00
|
|
|
|
|
|
|
// use a default size, in case of an error.
|
2016-10-19 22:01:39 +03:00
|
|
|
aScreenDragRect->MoveTo(aScreenPosition.x - mImageOffset.x,
|
|
|
|
aScreenPosition.y - mImageOffset.y);
|
|
|
|
aScreenDragRect->SizeTo(1, 1);
|
2007-03-20 15:14:52 +03:00
|
|
|
|
|
|
|
// if a drag image was specified, use that, otherwise, use the source node
|
|
|
|
nsCOMPtr<nsIDOMNode> dragNode = mImage ? mImage.get() : aDOMNode;
|
|
|
|
|
|
|
|
// get the presshell for the node being dragged. If the drag image is not in
|
|
|
|
// a document or has no frame, get the presshell from the source drag node
|
|
|
|
nsIPresShell* presShell = GetPresShellForContent(dragNode);
|
|
|
|
if (!presShell && mImage)
|
|
|
|
presShell = GetPresShellForContent(aDOMNode);
|
|
|
|
if (!presShell)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2008-01-09 01:03:53 +03:00
|
|
|
*aPresContext = presShell->GetPresContext();
|
|
|
|
|
2015-04-08 21:48:11 +03:00
|
|
|
nsCOMPtr<nsIFrameLoaderOwner> flo = do_QueryInterface(dragNode);
|
|
|
|
if (flo) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsFrameLoader> fl = flo->GetFrameLoader();
|
2015-04-08 21:48:11 +03:00
|
|
|
if (fl) {
|
|
|
|
mozilla::dom::TabParent* tp =
|
|
|
|
static_cast<mozilla::dom::TabParent*>(fl->GetRemoteBrowser());
|
2016-10-19 22:01:39 +03:00
|
|
|
if (tp && tp->TakeDragVisualization(*aSurface, aScreenDragRect)) {
|
|
|
|
if (mImage) {
|
|
|
|
// Just clear the surface if chrome has overridden it with an image.
|
|
|
|
*aSurface = nullptr;
|
2015-04-08 21:48:11 +03:00
|
|
|
}
|
2016-10-19 22:01:39 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2015-04-08 21:48:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-15 00:25:51 +04:00
|
|
|
// convert mouse position to dev pixels of the prescontext
|
2016-10-19 22:01:39 +03:00
|
|
|
CSSIntPoint screenPosition(aScreenPosition);
|
|
|
|
screenPosition.x -= mImageOffset.x;
|
|
|
|
screenPosition.y -= mImageOffset.y;
|
|
|
|
LayoutDeviceIntPoint screenPoint = ConvertToUnscaledDevPixels(*aPresContext, screenPosition);
|
|
|
|
aScreenDragRect->x = screenPoint.x;
|
|
|
|
aScreenDragRect->y = screenPoint.y;
|
2012-12-15 00:25:51 +04:00
|
|
|
|
2007-05-16 22:05:23 +04:00
|
|
|
// check if drag images are disabled
|
2011-09-29 10:19:26 +04:00
|
|
|
bool enableDragImages = Preferences::GetBool(DRAGIMAGES_PREF, true);
|
2007-05-16 22:05:23 +04:00
|
|
|
|
2007-03-20 15:14:52 +03:00
|
|
|
// didn't want an image, so just set the screen rectangle to the frame size
|
2007-05-16 22:05:23 +04:00
|
|
|
if (!enableDragImages || !mHasImage) {
|
2007-03-20 15:14:52 +03:00
|
|
|
// if a region was specified, set the screen rectangle to the area that
|
|
|
|
// the region occupies
|
2016-10-19 22:01:39 +03:00
|
|
|
nsIntRect dragRect;
|
2007-03-20 15:14:52 +03:00
|
|
|
if (aRegion) {
|
|
|
|
// the region's coordinates are relative to the root frame
|
2016-10-19 22:01:39 +03:00
|
|
|
aRegion->GetBoundingBox(&dragRect.x, &dragRect.y, &dragRect.width, &dragRect.height);
|
|
|
|
|
2007-03-20 15:14:52 +03:00
|
|
|
nsIFrame* rootFrame = presShell->GetRootFrame();
|
2016-10-19 22:01:39 +03:00
|
|
|
nsIntRect screenRect = rootFrame->GetScreenRect();
|
|
|
|
dragRect.MoveBy(screenRect.TopLeft());
|
2007-03-20 15:14:52 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// otherwise, there was no region so just set the rectangle to
|
|
|
|
// the size of the primary frame of the content.
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(dragNode);
|
2009-12-25 00:20:06 +03:00
|
|
|
nsIFrame* frame = content->GetPrimaryFrame();
|
2007-03-20 15:14:52 +03:00
|
|
|
if (frame) {
|
2016-10-19 22:01:39 +03:00
|
|
|
dragRect = frame->GetScreenRect();
|
2007-03-20 15:14:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:01:39 +03:00
|
|
|
dragRect = ToAppUnits(dragRect, nsPresContext::AppUnitsPerCSSPixel()).
|
|
|
|
ToOutsidePixels((*aPresContext)->AppUnitsPerDevPixel());
|
|
|
|
aScreenDragRect->SizeTo(dragRect.width, dragRect.height);
|
2007-03-20 15:14:52 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// draw the image for selections
|
|
|
|
if (mSelection) {
|
2016-10-19 22:01:39 +03:00
|
|
|
LayoutDeviceIntPoint pnt(aScreenDragRect->TopLeft());
|
2015-07-11 19:15:19 +03:00
|
|
|
*aSurface = presShell->RenderSelection(mSelection, pnt, aScreenDragRect,
|
2016-05-13 13:48:00 +03:00
|
|
|
mImage ? 0 : nsIPresShell::RENDER_AUTO_SCALE);
|
2007-03-20 15:14:52 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-04-26 05:37:20 +04:00
|
|
|
// if a custom image was specified, check if it is an image node and draw
|
2007-03-20 15:14:52 +03:00
|
|
|
// using the source rather than the displayed image. But if mImage isn't
|
2011-04-26 05:37:20 +04:00
|
|
|
// an image or canvas, fall through to RenderNode below.
|
2007-03-20 15:14:52 +03:00
|
|
|
if (mImage) {
|
2014-04-17 09:30:45 +04:00
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(dragNode);
|
|
|
|
HTMLCanvasElement *canvas = HTMLCanvasElement::FromContentOrNull(content);
|
2008-09-10 20:57:58 +04:00
|
|
|
if (canvas) {
|
2016-10-19 22:01:40 +03:00
|
|
|
return DrawDragForImage(*aPresContext, nullptr, canvas, aScreenDragRect, aSurface);
|
2008-09-10 20:57:58 +04:00
|
|
|
}
|
|
|
|
|
2007-03-20 15:14:52 +03:00
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(dragNode);
|
|
|
|
// for image nodes, create the drag image from the actual image data
|
|
|
|
if (imageLoader) {
|
2016-10-19 22:01:40 +03:00
|
|
|
return DrawDragForImage(*aPresContext, imageLoader, nullptr, aScreenDragRect, aSurface);
|
2007-03-20 15:14:52 +03:00
|
|
|
}
|
|
|
|
|
2011-04-26 05:37:20 +04:00
|
|
|
// If the image is a popup, use that as the image. This allows custom drag
|
|
|
|
// images that can change during the drag, but means that any platform
|
|
|
|
// default image handling won't occur.
|
|
|
|
// XXXndeakin this should be chrome-only
|
|
|
|
|
|
|
|
nsIFrame* frame = content->GetPrimaryFrame();
|
|
|
|
if (frame && frame->GetType() == nsGkAtoms::menuPopupFrame) {
|
|
|
|
mDragPopup = content;
|
|
|
|
}
|
2010-06-06 00:29:49 +04:00
|
|
|
}
|
2007-03-20 15:14:52 +03:00
|
|
|
|
2011-04-26 05:37:20 +04:00
|
|
|
if (!mDragPopup) {
|
|
|
|
// otherwise, just draw the node
|
|
|
|
nsIntRegion clipRegion;
|
2016-05-13 13:48:00 +03:00
|
|
|
uint32_t renderFlags = mImage ? 0 : nsIPresShell::RENDER_AUTO_SCALE;
|
2011-04-26 05:37:20 +04:00
|
|
|
if (aRegion) {
|
|
|
|
aRegion->GetRegion(&clipRegion);
|
|
|
|
}
|
|
|
|
|
2016-05-13 13:48:00 +03:00
|
|
|
if (renderFlags) {
|
|
|
|
nsCOMPtr<nsIDOMNode> child;
|
|
|
|
nsCOMPtr<nsIDOMNodeList> childList;
|
|
|
|
uint32_t length;
|
|
|
|
uint32_t count = 0;
|
|
|
|
nsAutoString childNodeName;
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(dragNode->GetChildNodes(getter_AddRefs(childList))) &&
|
|
|
|
NS_SUCCEEDED(childList->GetLength(&length))) {
|
|
|
|
// check every childnode for being a img-tag
|
|
|
|
while (count < length) {
|
|
|
|
if (NS_FAILED(childList->Item(count, getter_AddRefs(child))) ||
|
|
|
|
NS_FAILED(child->GetNodeName(childNodeName))) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// here the node is checked for being a img-tag
|
|
|
|
if (childNodeName.LowerCaseEqualsLiteral("img")) {
|
|
|
|
// if the dragnnode contains a image, set RENDER_IS_IMAGE flag
|
|
|
|
renderFlags = renderFlags | nsIPresShell::RENDER_IS_IMAGE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-10-19 22:01:39 +03:00
|
|
|
LayoutDeviceIntPoint pnt(aScreenDragRect->TopLeft());
|
2014-01-29 04:10:33 +04:00
|
|
|
*aSurface = presShell->RenderNode(dragNode, aRegion ? &clipRegion : nullptr,
|
2016-10-19 22:01:39 +03:00
|
|
|
pnt, aScreenDragRect,
|
|
|
|
renderFlags);
|
2011-04-26 05:37:20 +04:00
|
|
|
}
|
2007-03-20 15:14:52 +03:00
|
|
|
|
2016-10-19 22:01:39 +03:00
|
|
|
// If an image was specified, reset the position from the offset that was supplied.
|
2007-03-20 15:14:52 +03:00
|
|
|
if (mImage) {
|
2016-10-19 22:01:39 +03:00
|
|
|
aScreenDragRect->x = screenPoint.x;
|
|
|
|
aScreenDragRect->y = screenPoint.y;
|
2007-03-20 15:14:52 +03:00
|
|
|
}
|
|
|
|
|
1999-05-07 23:51:50 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-20 15:14:52 +03:00
|
|
|
|
|
|
|
nsresult
|
2016-10-19 22:01:40 +03:00
|
|
|
nsBaseDragService::DrawDragForImage(nsPresContext* aPresContext,
|
|
|
|
nsIImageLoadingContent* aImageLoader,
|
2014-04-17 09:30:45 +04:00
|
|
|
HTMLCanvasElement* aCanvas,
|
2016-10-19 22:01:39 +03:00
|
|
|
LayoutDeviceIntRect* aScreenDragRect,
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SourceSurface>* aSurface)
|
2007-03-20 15:14:52 +03:00
|
|
|
{
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 05:50:15 +04:00
|
|
|
nsCOMPtr<imgIContainer> imgContainer;
|
2008-09-10 20:57:58 +04:00
|
|
|
if (aImageLoader) {
|
|
|
|
nsCOMPtr<imgIRequest> imgRequest;
|
|
|
|
nsresult rv = aImageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
|
|
|
|
getter_AddRefs(imgRequest));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!imgRequest)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
rv = imgRequest->GetImage(getter_AddRefs(imgContainer));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!imgContainer)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
// use the size of the image as the size of the drag image
|
2016-10-19 22:01:40 +03:00
|
|
|
int32_t imageWidth, imageHeight;
|
|
|
|
rv = imgContainer->GetWidth(&imageWidth);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = imgContainer->GetHeight(&imageHeight);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
aScreenDragRect->width = aPresContext->CSSPixelsToDevPixels(imageWidth);
|
|
|
|
aScreenDragRect->height = aPresContext->CSSPixelsToDevPixels(imageHeight);
|
2008-09-10 20:57:58 +04:00
|
|
|
}
|
|
|
|
else {
|
2016-10-19 22:01:40 +03:00
|
|
|
// XXX The canvas size should be converted to dev pixels.
|
2008-09-10 20:57:58 +04:00
|
|
|
NS_ASSERTION(aCanvas, "both image and canvas are null");
|
2014-04-17 09:30:45 +04:00
|
|
|
nsIntSize sz = aCanvas->GetSize();
|
2010-05-18 08:04:22 +04:00
|
|
|
aScreenDragRect->width = sz.width;
|
|
|
|
aScreenDragRect->height = sz.height;
|
2008-09-10 20:57:58 +04:00
|
|
|
}
|
2007-03-20 15:14:52 +03:00
|
|
|
|
2016-10-19 22:01:39 +03:00
|
|
|
nsIntSize destSize;
|
|
|
|
destSize.width = aScreenDragRect->width;
|
|
|
|
destSize.height = aScreenDragRect->height;
|
2008-11-05 01:01:21 +03:00
|
|
|
if (destSize.width == 0 || destSize.height == 0)
|
2007-03-20 15:14:52 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2014-04-17 10:43:41 +04:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
if (aImageLoader) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DrawTarget> dt =
|
2014-04-17 09:30:45 +04:00
|
|
|
gfxPlatform::GetPlatform()->
|
2015-03-29 17:59:08 +03:00
|
|
|
CreateOffscreenContentDrawTarget(destSize,
|
2014-04-17 09:30:45 +04:00
|
|
|
SurfaceFormat::B8G8R8A8);
|
2016-04-12 22:18:11 +03:00
|
|
|
if (!dt || !dt->IsValid())
|
2014-04-17 09:30:45 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2016-06-07 02:39:56 +03:00
|
|
|
RefPtr<gfxContext> ctx = gfxContext::CreateOrNull(dt);
|
2014-04-17 09:30:45 +04:00
|
|
|
if (!ctx)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2016-03-10 09:37:18 +03:00
|
|
|
DrawResult res =
|
|
|
|
imgContainer->Draw(ctx, destSize, ImageRegion::Create(destSize),
|
|
|
|
imgIContainer::FRAME_CURRENT,
|
2016-05-25 19:01:18 +03:00
|
|
|
SamplingFilter::GOOD, /* no SVGImageContext */ Nothing(),
|
2016-03-10 09:37:18 +03:00
|
|
|
imgIContainer::FLAG_SYNC_DECODE);
|
|
|
|
if (res == DrawResult::BAD_IMAGE || res == DrawResult::BAD_ARGS) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2014-04-17 09:30:45 +04:00
|
|
|
*aSurface = dt->Snapshot();
|
2008-11-05 01:01:21 +03:00
|
|
|
} else {
|
2014-04-17 09:30:45 +04:00
|
|
|
*aSurface = aCanvas->GetSurfaceSnapshot();
|
2008-09-10 20:57:58 +04:00
|
|
|
}
|
2014-01-29 04:10:33 +04:00
|
|
|
|
|
|
|
return result;
|
2007-03-20 15:14:52 +03:00
|
|
|
}
|
2008-01-09 01:03:53 +03:00
|
|
|
|
2016-10-19 22:01:39 +03:00
|
|
|
LayoutDeviceIntPoint
|
2008-01-09 01:03:53 +03:00
|
|
|
nsBaseDragService::ConvertToUnscaledDevPixels(nsPresContext* aPresContext,
|
2016-10-19 22:01:39 +03:00
|
|
|
CSSIntPoint aScreenPosition)
|
2008-01-09 01:03:53 +03:00
|
|
|
{
|
2014-11-13 14:53:02 +03:00
|
|
|
int32_t adj = aPresContext->DeviceContext()->AppUnitsPerDevPixelAtUnitFullZoom();
|
2016-10-19 22:01:39 +03:00
|
|
|
return LayoutDeviceIntPoint(nsPresContext::CSSPixelsToAppUnits(aScreenPosition.x) / adj,
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(aScreenPosition.y) / adj);
|
2008-01-09 01:03:53 +03:00
|
|
|
}
|
|
|
|
|
2008-03-19 03:06:22 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseDragService::Suppress()
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
EndDragSession(false);
|
2008-03-19 03:06:22 +03:00
|
|
|
++mSuppressLevel;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseDragService::Unsuppress()
|
|
|
|
{
|
|
|
|
--mSuppressLevel;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2015-04-08 21:48:11 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseDragService::UserCancelled()
|
|
|
|
{
|
|
|
|
mUserCancelled = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseDragService::UpdateDragEffect()
|
|
|
|
{
|
2015-06-05 15:33:29 +03:00
|
|
|
mDragActionFromChildProcess = mDragAction;
|
2015-04-08 21:48:11 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseDragService::DragEventDispatchedToChildProcess()
|
|
|
|
{
|
|
|
|
mDragEventDispatchedToChildProcess = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsBaseDragService::MaybeAddChildProcess(mozilla::dom::ContentParent* aChild)
|
|
|
|
{
|
|
|
|
if (!mChildProcesses.Contains(aChild)) {
|
|
|
|
mChildProcesses.AppendElement(aChild);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|