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"
|
|
|
|
|
2018-10-04 13:31:32 +03:00
|
|
|
#include "nsArrayUtils.h"
|
1999-04-17 01:03:32 +04:00
|
|
|
#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"
|
2019-02-16 01:20:53 +03:00
|
|
|
#include "nsFrameLoaderOwner.h"
|
2019-01-02 16:05:23 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2000-08-16 05:46:34 +04:00
|
|
|
#include "nsIContent.h"
|
2013-01-05 07:12:24 +04:00
|
|
|
#include "nsViewManager.h"
|
2018-05-30 05:58:48 +03:00
|
|
|
#include "nsINode.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.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"
|
2018-03-13 23:24:00 +03:00
|
|
|
#include "nsQueryObject.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"
|
2018-08-07 16:32:07 +03:00
|
|
|
#ifdef MOZ_XUL
|
|
|
|
# include "nsTreeBodyFrame.h"
|
|
|
|
#endif
|
2013-09-25 15:21:18 +04:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2011-05-23 18:54:03 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2019-03-29 18:12:47 +03:00
|
|
|
#include "mozilla/PresShell.h"
|
2018-03-17 05:25:25 +03:00
|
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
2016-11-28 14:39:22 +03:00
|
|
|
#include "mozilla/dom/DataTransferItemList.h"
|
2018-03-13 23:23:59 +03:00
|
|
|
#include "mozilla/dom/DataTransfer.h"
|
2018-03-17 05:25:25 +03:00
|
|
|
#include "mozilla/dom/DragEvent.h"
|
2018-03-20 07:16:06 +03:00
|
|
|
#include "mozilla/dom/MouseEventBinding.h"
|
2018-03-27 07:35:22 +03:00
|
|
|
#include "mozilla/dom/Selection.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"
|
2019-04-10 00:38:15 +03:00
|
|
|
#include "BrowserParent.h"
|
2019-10-08 00:01:57 +03:00
|
|
|
#include "nsIMutableArray.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),
|
2018-11-20 04:17:54 +03:00
|
|
|
mDragActionFromChildProcess(DRAGDROP_ACTION_UNINITIALIZED),
|
2015-08-10 22:56:47 +03:00
|
|
|
mContentPolicyType(nsIContentPolicy::TYPE_OTHER),
|
2018-08-07 16:32:08 +03:00
|
|
|
mSuppressLevel(0),
|
|
|
|
mInputSource(MouseEvent_Binding::MOZ_SOURCE_MOUSE) {}
|
1999-04-17 01:03:32 +04:00
|
|
|
|
2016-11-16 17:23:37 +03:00
|
|
|
nsBaseDragService::~nsBaseDragService() = default;
|
1999-04-17 01:03:32 +04:00
|
|
|
|
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) {
|
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) {
|
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-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
|
2019-01-02 16:05:23 +03:00
|
|
|
nsBaseDragService::GetSourceDocument(Document** 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
|
2018-05-30 05:58:48 +03:00
|
|
|
nsBaseDragService::GetSourceNode(nsINode** aSourceNode) {
|
|
|
|
*aSourceNode = do_AddRef(mSourceNode).take();
|
2001-05-20 09:58:25 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-02-09 04:43:53 +03:00
|
|
|
NS_IMETHODIMP
|
2019-01-04 06:16:46 +03:00
|
|
|
nsBaseDragService::GetTriggeringPrincipal(nsIPrincipal** aPrincipal) {
|
|
|
|
NS_IF_ADDREF(*aPrincipal = mTriggeringPrincipal);
|
2018-02-09 04:43:53 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-01-04 06:16:46 +03:00
|
|
|
nsBaseDragService::SetTriggeringPrincipal(nsIPrincipal* aPrincipal) {
|
|
|
|
mTriggeringPrincipal = aPrincipal;
|
2018-02-09 04:43:53 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-04-17 01:03:32 +04:00
|
|
|
|
2019-08-20 15:43:02 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseDragService::GetCsp(nsIContentSecurityPolicy** aCsp) {
|
|
|
|
NS_IF_ADDREF(*aCsp = mCsp);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseDragService::SetCsp(nsIContentSecurityPolicy* aCsp) {
|
|
|
|
mCsp = aCsp;
|
|
|
|
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
|
2018-04-07 01:32:25 +03:00
|
|
|
nsBaseDragService::GetDataTransferXPCOM(DataTransfer** aDataTransfer) {
|
2008-08-27 16:07:27 +04:00
|
|
|
*aDataTransfer = mDataTransfer;
|
|
|
|
NS_IF_ADDREF(*aDataTransfer);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-04-07 01:32:25 +03:00
|
|
|
nsBaseDragService::SetDataTransferXPCOM(DataTransfer* aDataTransfer) {
|
|
|
|
NS_ENSURE_STATE(aDataTransfer);
|
|
|
|
mDataTransfer = aDataTransfer;
|
2008-08-27 16:07:27 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-03-13 23:23:59 +03:00
|
|
|
DataTransfer* nsBaseDragService::GetDataTransfer() { return mDataTransfer; }
|
|
|
|
|
|
|
|
void nsBaseDragService::SetDataTransfer(DataTransfer* aDataTransfer) {
|
|
|
|
mDataTransfer = aDataTransfer;
|
|
|
|
}
|
|
|
|
|
1999-05-07 23:51:50 +04:00
|
|
|
//-------------------------------------------------------------------------
|
2005-03-15 01:49:00 +03:00
|
|
|
NS_IMETHODIMP
|
2018-05-30 05:58:48 +03:00
|
|
|
nsBaseDragService::InvokeDragSession(
|
2019-08-20 15:43:02 +03:00
|
|
|
nsINode* aDOMNode, nsIPrincipal* aPrincipal, nsIContentSecurityPolicy* aCsp,
|
|
|
|
nsIArray* aTransferableArray, uint32_t aActionType,
|
2015-08-10 22:56:47 +03:00
|
|
|
nsContentPolicyType aContentPolicyType = nsIContentPolicy::TYPE_OTHER) {
|
Bug 1375392 - Tweak the PROFILER_LABEL* macros. r=mstange.
This patch makes the following changes to the macros.
- Removes PROFILER_LABEL_FUNC. It's only suitable for use in functions outside
classes, due to PROFILER_FUNCTION_NAME not getting class names, and it was
mostly misused.
- Removes PROFILER_FUNCTION_NAME. It's no longer used, and __func__ is
universally available now anyway.
- Combines the first two string literal arguments of PROFILER_LABEL and
PROFILER_LABEL_DYNAMIC into a single argument. There was no good reason for
them to be separate, and it forced a '::' in the label, which isn't always
appropriate. Also, the meaning of the "name_space" argument was interpreted
in an interesting variety of ways.
- Adds an "AUTO_" prefix to PROFILER_LABEL and PROFILER_LABEL_DYNAMIC, to make
it clearer they construct RAII objects rather than just being function calls.
(I myself have screwed up the scoping because of this in the past.)
- Fills in the 'js::ProfileEntry::Category::' qualifier within the macro, so
the caller doesn't need to. This makes a *lot* more of the uses fit onto a
single line.
The patch also makes the following changes to the macro uses (beyond those
required by the changes described above).
- Fixes a bunch of labels that had gotten out of sync with the name of the
class and/or function that encloses them.
- Removes a useless PROFILER_LABEL use within a trivial scope in
EventStateManager::DispatchMouseOrPointerEvent(). It clearly wasn't serving
any useful purpose. It also serves as extra evidence that the AUTO_ prefix is
a good idea.
- Tweaks DecodePool::SyncRunIf{Preferred,Possible} so that the labelling is
done within them, instead of at their callsites, because that's a more
standard way of doing things.
--HG--
extra : rebase_source : 318d1bc6fc1425a94aacbf489dd46e4f83211de4
2017-06-22 10:08:53 +03:00
|
|
|
AUTO_PROFILER_LABEL("nsBaseDragService::InvokeDragSession", OTHER);
|
2016-01-15 13:38:03 +03:00
|
|
|
|
2019-04-11 20:17:36 +03:00
|
|
|
// If you're hitting this, a test is causing the browser to attempt to enter
|
|
|
|
// the drag-drop native nested event loop, which will put the browser in a
|
|
|
|
// state that won't run tests properly until there's manual intervention
|
|
|
|
// to exit the drag-drop loop (either by moving the mouse or hitting escape),
|
|
|
|
// which can't be done from script since we're in the nested loop.
|
|
|
|
//
|
|
|
|
// The best way to avoid this is to catch the dragstart event on the item
|
|
|
|
// being dragged, and then to call preventDefault() and stopPropagating() on
|
|
|
|
// it. Alternatively, use EventUtils.synthesizeDragStart, which will do this
|
|
|
|
// for you.
|
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
MOZ_ASSERT(
|
|
|
|
!xpc::IsInAutomation(),
|
|
|
|
"About to start drag-drop native loop on which will prevent later "
|
|
|
|
"tests from running properly.");
|
|
|
|
}
|
|
|
|
|
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
|
2018-05-30 05:58:48 +03:00
|
|
|
mSourceDocument = aDOMNode->OwnerDoc();
|
2019-01-04 06:16:46 +03:00
|
|
|
mTriggeringPrincipal = aPrincipal;
|
2019-08-20 15:43:02 +03:00
|
|
|
mCsp = aCsp;
|
2005-03-16 03:40:21 +03:00
|
|
|
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.
|
2019-04-30 03:26:57 +03:00
|
|
|
PresShell::ClearMouseCapture(nullptr);
|
2005-03-16 03:40:21 +03:00
|
|
|
|
2018-10-04 13:31:32 +03:00
|
|
|
uint32_t length = 0;
|
|
|
|
mozilla::Unused << aTransferableArray->GetLength(&length);
|
2019-10-08 00:01:57 +03:00
|
|
|
if (!length) {
|
|
|
|
nsCOMPtr<nsIMutableArray> mutableArray =
|
|
|
|
do_QueryInterface(aTransferableArray);
|
|
|
|
if (mutableArray) {
|
|
|
|
// In order to be able trigger dnd, we need to have some transferable
|
|
|
|
// object.
|
|
|
|
nsCOMPtr<nsITransferable> trans =
|
|
|
|
do_CreateInstance("@mozilla.org/widget/transferable;1");
|
|
|
|
trans->Init(nullptr);
|
2018-10-04 13:31:32 +03:00
|
|
|
trans->SetRequestingPrincipal(mSourceNode->NodePrincipal());
|
|
|
|
trans->SetContentPolicyType(mContentPolicyType);
|
2019-10-08 00:01:57 +03:00
|
|
|
mutableArray->AppendElement(trans);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (uint32_t i = 0; i < length; ++i) {
|
|
|
|
nsCOMPtr<nsITransferable> trans =
|
|
|
|
do_QueryElementAt(aTransferableArray, i);
|
|
|
|
if (trans) {
|
|
|
|
// Set the requestingPrincipal on the transferable.
|
|
|
|
trans->SetRequestingPrincipal(mSourceNode->NodePrincipal());
|
|
|
|
trans->SetContentPolicyType(mContentPolicyType);
|
|
|
|
}
|
2018-10-04 13:31:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-21 12:16:40 +03:00
|
|
|
nsresult rv = InvokeDragSessionImpl(aTransferableArray, mRegion, aActionType);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
2018-08-02 16:50:20 +03:00
|
|
|
// Set mDoingDrag so that EndDragSession cleans up and sends the dragend
|
|
|
|
// event after the aborted drag.
|
|
|
|
mDoingDrag = true;
|
|
|
|
EndDragSession(true, 0);
|
2015-10-21 12:16:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
1999-04-17 01:03:32 +04:00
|
|
|
}
|
|
|
|
|
2007-03-20 15:14:52 +03:00
|
|
|
NS_IMETHODIMP
|
2018-05-30 05:58:48 +03:00
|
|
|
nsBaseDragService::InvokeDragSessionWithImage(
|
2019-08-20 15:43:02 +03:00
|
|
|
nsINode* aDOMNode, nsIPrincipal* aPrincipal, nsIContentSecurityPolicy* aCsp,
|
|
|
|
nsIArray* aTransferableArray, uint32_t aActionType, nsINode* aImage,
|
|
|
|
int32_t aImageX, int32_t aImageY, DragEvent* aDragEvent,
|
|
|
|
DataTransfer* 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
|
|
|
|
2018-03-13 23:24:00 +03: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);
|
2019-05-14 18:04:38 +03:00
|
|
|
mDragStartData = nullptr;
|
2007-03-20 15:14:52 +03:00
|
|
|
|
2018-04-07 01:32:25 +03:00
|
|
|
mScreenPosition.x = aDragEvent->ScreenX(CallerType::System);
|
|
|
|
mScreenPosition.y = aDragEvent->ScreenY(CallerType::System);
|
|
|
|
mInputSource = aDragEvent->MozInputSource();
|
2010-04-06 16:59:24 +04:00
|
|
|
|
2018-08-07 16:32:07 +03:00
|
|
|
// If dragging within a XUL tree and no custom drag image was
|
|
|
|
// set, the region argument to InvokeDragSessionWithImage needs
|
|
|
|
// to be set to the area encompassing the selected rows of the
|
|
|
|
// tree to ensure that the drag feedback gets clipped to those
|
|
|
|
// rows. For other content, region should be null.
|
2018-08-07 16:32:08 +03:00
|
|
|
mRegion = Nothing();
|
2018-08-07 16:32:07 +03:00
|
|
|
#ifdef MOZ_XUL
|
|
|
|
if (aDOMNode && aDOMNode->IsContent() && !aImage) {
|
|
|
|
if (aDOMNode->NodeInfo()->Equals(nsGkAtoms::treechildren,
|
|
|
|
kNameSpaceID_XUL)) {
|
|
|
|
nsTreeBodyFrame* treeBody =
|
|
|
|
do_QueryFrame(aDOMNode->AsContent()->GetPrimaryFrame());
|
|
|
|
if (treeBody) {
|
2018-08-07 16:32:08 +03:00
|
|
|
mRegion = treeBody->GetSelectionRegion();
|
2018-08-07 16:32:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-08-07 16:32:07 +03:00
|
|
|
nsresult rv =
|
2019-08-20 15:43:02 +03:00
|
|
|
InvokeDragSession(aDOMNode, aPrincipal, aCsp, aTransferableArray,
|
|
|
|
aActionType, nsIContentPolicy::TYPE_INTERNAL_IMAGE);
|
2018-08-07 16:32:08 +03:00
|
|
|
mRegion = Nothing();
|
2018-08-07 16:32:07 +03:00
|
|
|
return rv;
|
2007-03-20 15:14:52 +03:00
|
|
|
}
|
|
|
|
|
2019-05-14 18:04:38 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseDragService::InvokeDragSessionWithRemoteImage(
|
2019-08-20 15:43:02 +03:00
|
|
|
nsINode* aDOMNode, nsIPrincipal* aPrincipal, nsIContentSecurityPolicy* aCsp,
|
|
|
|
nsIArray* aTransferableArray, uint32_t aActionType,
|
|
|
|
RemoteDragStartData* aDragStartData, DragEvent* aDragEvent,
|
|
|
|
DataTransfer* aDataTransfer) {
|
2019-05-14 18:04:38 +03:00
|
|
|
NS_ENSURE_TRUE(aDragEvent, NS_ERROR_NULL_POINTER);
|
|
|
|
NS_ENSURE_TRUE(aDataTransfer, NS_ERROR_NULL_POINTER);
|
|
|
|
NS_ENSURE_TRUE(mSuppressLevel == 0, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
mDataTransfer = aDataTransfer;
|
|
|
|
mSelection = nullptr;
|
|
|
|
mHasImage = true;
|
|
|
|
mDragPopup = nullptr;
|
|
|
|
mImage = nullptr;
|
|
|
|
mDragStartData = aDragStartData;
|
|
|
|
mImageOffset = CSSIntPoint(0, 0);
|
|
|
|
|
|
|
|
mScreenPosition.x = aDragEvent->ScreenX(CallerType::System);
|
|
|
|
mScreenPosition.y = aDragEvent->ScreenY(CallerType::System);
|
|
|
|
mInputSource = aDragEvent->MozInputSource();
|
|
|
|
|
|
|
|
nsresult rv =
|
2019-08-20 15:43:02 +03:00
|
|
|
InvokeDragSession(aDOMNode, aPrincipal, aCsp, aTransferableArray,
|
|
|
|
aActionType, nsIContentPolicy::TYPE_INTERNAL_IMAGE);
|
2019-05-14 18:04:38 +03:00
|
|
|
mRegion = Nothing();
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2007-03-20 15:14:52 +03:00
|
|
|
NS_IMETHODIMP
|
2019-08-20 15:43:02 +03:00
|
|
|
nsBaseDragService::InvokeDragSessionWithSelection(
|
|
|
|
Selection* aSelection, nsIPrincipal* aPrincipal,
|
|
|
|
nsIContentSecurityPolicy* aCsp, nsIArray* aTransferableArray,
|
|
|
|
uint32_t aActionType, DragEvent* aDragEvent, DataTransfer* 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
|
|
|
|
2018-03-13 23:24:00 +03:00
|
|
|
mDataTransfer = aDataTransfer;
|
2018-05-08 20:52:36 +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();
|
2019-05-14 18:04:38 +03:00
|
|
|
mDragStartData = nullptr;
|
2018-08-07 16:32:08 +03:00
|
|
|
mRegion = Nothing();
|
2007-03-20 15:14:52 +03:00
|
|
|
|
2018-04-07 01:32:25 +03:00
|
|
|
mScreenPosition.x = aDragEvent->ScreenX(CallerType::System);
|
|
|
|
mScreenPosition.y = aDragEvent->ScreenY(CallerType::System);
|
|
|
|
mInputSource = aDragEvent->MozInputSource();
|
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
|
2018-05-30 05:58:48 +03:00
|
|
|
nsCOMPtr<nsINode> node = aSelection->GetFocusNode();
|
2007-03-20 15:14:52 +03:00
|
|
|
|
2019-08-20 15:43:02 +03:00
|
|
|
return InvokeDragSession(node, aPrincipal, aCsp, aTransferableArray,
|
|
|
|
aActionType, nsIContentPolicy::TYPE_OTHER);
|
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
|
|
|
if (!aSession) 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
|
2017-02-17 06:29:42 +03:00
|
|
|
nsBaseDragService::EndDragSession(bool aDoneDrag, uint32_t aKeyModifiers) {
|
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) {
|
2017-02-17 06:29:42 +03:00
|
|
|
FireDragEventAtSource(eDragEnd, aKeyModifiers);
|
2015-09-02 09:08:02 +03:00
|
|
|
}
|
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(
|
2017-02-17 06:29:42 +03:00
|
|
|
aDoneDrag, mUserCancelled, mEndDragPoint, aKeyModifiers);
|
2017-08-02 10:23:35 +03:00
|
|
|
// Continue sending input events with input priority when stopping the dnd
|
|
|
|
// session.
|
|
|
|
mChildProcesses[i]->SetInputPriorityEventEnabled(true);
|
2015-04-08 21:48:11 +03:00
|
|
|
}
|
|
|
|
mChildProcesses.Clear();
|
|
|
|
|
2016-11-28 14:39:22 +03:00
|
|
|
// mDataTransfer and the items it owns are going to die anyway, but we
|
|
|
|
// explicitly deref the contained data here so that we don't have to wait for
|
|
|
|
// CC to reclaim the memory.
|
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
DiscardInternalTransferData();
|
|
|
|
}
|
|
|
|
|
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;
|
2019-01-04 06:16:46 +03:00
|
|
|
mTriggeringPrincipal = nullptr;
|
2019-08-20 15:43:02 +03:00
|
|
|
mCsp = nullptr;
|
2012-07-30 18:20:58 +04:00
|
|
|
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;
|
2019-05-14 18:04:38 +03:00
|
|
|
mDragStartData = nullptr;
|
2012-07-30 18:20:58 +04:00
|
|
|
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);
|
2018-06-26 00:20:54 +03:00
|
|
|
mInputSource = MouseEvent_Binding::MOZ_SOURCE_MOUSE;
|
2018-08-07 16:32:08 +03:00
|
|
|
mRegion = Nothing();
|
2007-03-20 15:14:52 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-11-28 14:39:22 +03:00
|
|
|
void nsBaseDragService::DiscardInternalTransferData() {
|
|
|
|
if (mDataTransfer && mSourceNode) {
|
2018-03-13 23:24:00 +03:00
|
|
|
MOZ_ASSERT(mDataTransfer);
|
2016-11-28 14:39:22 +03:00
|
|
|
|
2018-03-13 23:24:00 +03:00
|
|
|
DataTransferItemList* items = mDataTransfer->Items();
|
2016-11-28 14:39:22 +03:00
|
|
|
for (size_t i = 0; i < items->Length(); i++) {
|
|
|
|
bool found;
|
|
|
|
DataTransferItem* item = items->IndexedGetter(i, found);
|
|
|
|
|
|
|
|
// Non-OTHER items may still be needed by JS. Skip them.
|
|
|
|
if (!found || item->Kind() != DataTransferItem::KIND_OTHER) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIVariant> variant = item->DataNoSecurityCheck();
|
|
|
|
nsCOMPtr<nsIWritableVariant> writable = do_QueryInterface(variant);
|
|
|
|
|
|
|
|
if (writable) {
|
|
|
|
writable->SetAsEmpty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-12 08:37:39 +04:00
|
|
|
NS_IMETHODIMP
|
2017-02-17 06:29:42 +03:00
|
|
|
nsBaseDragService::FireDragEventAtSource(EventMessage aEventMessage,
|
|
|
|
uint32_t aKeyModifiers) {
|
2018-05-11 20:46:15 +03:00
|
|
|
if (mSourceNode && mSourceDocument && !mSuppressLevel) {
|
2019-03-29 18:12:47 +03:00
|
|
|
RefPtr<PresShell> presShell = mSourceDocument->GetPresShell();
|
2018-05-11 20:46:15 +03:00
|
|
|
if (presShell) {
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
WidgetDragEvent event(true, aEventMessage, nullptr);
|
2019-04-21 21:19:43 +03:00
|
|
|
event.mInputSource = mInputSource;
|
2018-05-11 20:46:15 +03:00
|
|
|
if (aEventMessage == eDragEnd) {
|
|
|
|
event.mRefPoint = mEndDragPoint;
|
|
|
|
event.mUserCancelled = mUserCancelled;
|
|
|
|
}
|
|
|
|
event.mModifiers = aKeyModifiers;
|
|
|
|
// 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);
|
2016-04-18 21:24:28 +03:00
|
|
|
}
|
2007-04-12 08:37:39 +04:00
|
|
|
}
|
2018-05-11 20:46:15 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(mSourceNode);
|
|
|
|
return presShell->HandleDOMEventWithTarget(content, &event, &status);
|
2007-04-12 08:37:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2017-04-30 18:30:08 +03:00
|
|
|
if (frame && frame->IsMenuPopupFrame()) {
|
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;
|
|
|
|
}
|
|
|
|
|
2019-05-01 21:52:59 +03:00
|
|
|
static PresShell* GetPresShellForContent(nsINode* aDOMNode) {
|
2007-03-29 01:18:11 +04:00
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(aDOMNode);
|
2012-07-30 18:20:58 +04:00
|
|
|
if (!content) return nullptr;
|
2010-02-28 14:18:19 +03:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
RefPtr<Document> document = content->GetComposedDoc();
|
2007-03-20 15:14:52 +03:00
|
|
|
if (document) {
|
2017-01-05 10:31:56 +03:00
|
|
|
document->FlushPendingNotifications(FlushType::Display);
|
2019-03-29 18:12:47 +03:00
|
|
|
return document->GetPresShell();
|
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
|
|
|
}
|
|
|
|
|
2018-05-30 05:58:48 +03:00
|
|
|
nsresult nsBaseDragService::DrawDrag(nsINode* aDOMNode,
|
2018-08-07 16:32:08 +03:00
|
|
|
const Maybe<CSSIntRegion>& 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) {
|
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.
|
2018-01-10 19:14:16 +03:00
|
|
|
aScreenDragRect->SetRect(aScreenPosition.x - mImageOffset.x,
|
|
|
|
aScreenPosition.y - mImageOffset.y, 1, 1);
|
2007-03-20 15:14:52 +03:00
|
|
|
|
|
|
|
// if a drag image was specified, use that, otherwise, use the source node
|
2018-05-30 05:58:48 +03:00
|
|
|
nsCOMPtr<nsINode> dragNode = mImage ? mImage.get() : aDOMNode;
|
2007-03-20 15:14:52 +03:00
|
|
|
|
|
|
|
// 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
|
2019-05-01 21:52:59 +03:00
|
|
|
PresShell* presShell = GetPresShellForContent(dragNode);
|
|
|
|
if (!presShell && mImage) {
|
|
|
|
presShell = GetPresShellForContent(aDOMNode);
|
|
|
|
}
|
|
|
|
if (!presShell) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2007-03-20 15:14:52 +03:00
|
|
|
|
2008-01-09 01:03:53 +03:00
|
|
|
*aPresContext = presShell->GetPresContext();
|
|
|
|
|
2019-05-14 18:04:38 +03:00
|
|
|
if (mDragStartData) {
|
|
|
|
if (mImage) {
|
|
|
|
// Just clear the surface if chrome has overridden it with an image.
|
|
|
|
*aSurface = nullptr;
|
|
|
|
} else {
|
|
|
|
*aSurface = mDragStartData->TakeVisualization(aScreenDragRect);
|
2015-04-08 21:48:11 +03:00
|
|
|
}
|
2019-06-04 15:51:23 +03:00
|
|
|
|
|
|
|
mDragStartData = nullptr;
|
|
|
|
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);
|
2018-01-10 19:14:16 +03:00
|
|
|
aScreenDragRect->MoveTo(screenPoint.x, 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
|
2017-04-25 01:33:13 +03:00
|
|
|
CSSIntRect dragRect;
|
2007-03-20 15:14:52 +03:00
|
|
|
if (aRegion) {
|
|
|
|
// the region's coordinates are relative to the root frame
|
2018-08-07 16:32:08 +03:00
|
|
|
dragRect = aRegion->GetBounds();
|
2016-10-19 22:01:39 +03:00
|
|
|
|
2007-03-20 15:14:52 +03:00
|
|
|
nsIFrame* rootFrame = presShell->GetRootFrame();
|
2017-04-25 01:33:13 +03:00
|
|
|
CSSIntRect screenRect = rootFrame->GetScreenRect();
|
2016-10-19 22:01:39 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-25 01:33:13 +03:00
|
|
|
nsIntRect dragRectDev =
|
2018-08-11 07:46:23 +03:00
|
|
|
ToAppUnits(dragRect, AppUnitsPerCSSPixel())
|
2017-04-25 01:33:13 +03:00
|
|
|
.ToOutsidePixels((*aPresContext)->AppUnitsPerDevPixel());
|
2018-01-10 19:14:16 +03:00
|
|
|
aScreenDragRect->SizeTo(dragRectDev.Width(), dragRectDev.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,
|
2019-04-25 08:04:23 +03:00
|
|
|
mImage ? RenderImageFlags::None : RenderImageFlags::AutoScale);
|
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);
|
2018-03-22 00:39:04 +03:00
|
|
|
HTMLCanvasElement* canvas = HTMLCanvasElement::FromNodeOrNull(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();
|
2017-04-30 18:30:08 +03:00
|
|
|
if (frame && frame->IsMenuPopupFrame()) {
|
2011-04-26 05:37:20 +04:00
|
|
|
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
|
2019-04-25 08:04:23 +03:00
|
|
|
RenderImageFlags renderFlags =
|
|
|
|
mImage ? RenderImageFlags::None : RenderImageFlags::AutoScale;
|
|
|
|
if (renderFlags != RenderImageFlags::None) {
|
2017-10-18 20:16:03 +03:00
|
|
|
// check if the dragged node itself is an img element
|
2018-10-02 00:38:01 +03:00
|
|
|
if (dragNode->NodeName().LowerCaseEqualsLiteral("img")) {
|
2019-04-25 08:04:23 +03:00
|
|
|
renderFlags = renderFlags | RenderImageFlags::IsImage;
|
2018-01-30 07:10:50 +03:00
|
|
|
} else {
|
2018-10-02 00:38:01 +03:00
|
|
|
nsINodeList* childList = dragNode->ChildNodes();
|
2018-01-30 07:10:50 +03:00
|
|
|
uint32_t length = childList->Length();
|
2017-10-18 20:16:03 +03:00
|
|
|
// check every childnode for being an img element
|
2018-01-30 07:10:50 +03:00
|
|
|
// XXXbz why don't we need to check descendants recursively?
|
|
|
|
for (uint32_t count = 0; count < length; ++count) {
|
|
|
|
if (childList->Item(count)->NodeName().LowerCaseEqualsLiteral(
|
|
|
|
"img")) {
|
2019-04-25 08:04:23 +03:00
|
|
|
// if the dragnode contains an image, set RenderImageFlags::IsImage
|
|
|
|
// flag
|
|
|
|
renderFlags = renderFlags | RenderImageFlags::IsImage;
|
2016-05-13 13:48:00 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-10-19 22:01:39 +03:00
|
|
|
LayoutDeviceIntPoint pnt(aScreenDragRect->TopLeft());
|
2018-08-07 16:32:08 +03:00
|
|
|
*aSurface = presShell->RenderNode(dragNode, aRegion, pnt, aScreenDragRect,
|
2016-10-19 22:01:39 +03:00
|
|
|
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) {
|
2018-01-10 19:14:16 +03:00
|
|
|
aScreenDragRect->MoveTo(screenPoint.x, 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
|
|
|
|
2016-10-19 22:01:40 +03:00
|
|
|
nsresult nsBaseDragService::DrawDragForImage(
|
|
|
|
nsPresContext* aPresContext, nsIImageLoadingContent* aImageLoader,
|
2016-10-19 22:01:39 +03:00
|
|
|
HTMLCanvasElement* aCanvas, LayoutDeviceIntRect* aScreenDragRect,
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SourceSurface>* aSurface) {
|
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);
|
|
|
|
|
2018-01-10 19:14:16 +03:00
|
|
|
aScreenDragRect->SizeTo(aPresContext->CSSPixelsToDevPixels(imageWidth),
|
|
|
|
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();
|
2018-01-10 19:14:16 +03:00
|
|
|
aScreenDragRect->SizeTo(sz.width, 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;
|
2018-01-10 19:14:16 +03:00
|
|
|
destSize.width = aScreenDragRect->Width();
|
|
|
|
destSize.height = aScreenDragRect->Height();
|
2008-11-05 01:01:21 +03:00
|
|
|
if (destSize.width == 0 || destSize.height == 0) return NS_ERROR_FAILURE;
|
2007-03-20 15:14:52 +03:00
|
|
|
|
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 =
|
2015-03-29 17:59:08 +03:00
|
|
|
gfxPlatform::GetPlatform()->CreateOffscreenContentDrawTarget(
|
2014-04-17 09:30:45 +04:00
|
|
|
destSize, SurfaceFormat::B8G8R8A8);
|
2016-04-12 22:18:11 +03:00
|
|
|
if (!dt || !dt->IsValid()) return NS_ERROR_FAILURE;
|
2014-04-17 09:30:45 +04:00
|
|
|
|
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;
|
|
|
|
|
2017-12-11 18:37:59 +03:00
|
|
|
ImgDrawResult res =
|
2016-03-10 09:37:18 +03:00
|
|
|
imgContainer->Draw(ctx, destSize, ImageRegion::Create(destSize),
|
|
|
|
imgIContainer::FRAME_CURRENT, SamplingFilter::GOOD,
|
2016-05-25 19:01:18 +03:00
|
|
|
/* no SVGImageContext */ Nothing(),
|
2017-01-03 08:53:22 +03:00
|
|
|
imgIContainer::FLAG_SYNC_DECODE, 1.0);
|
2018-09-14 02:48:21 +03:00
|
|
|
if (res == ImgDrawResult::BAD_IMAGE || res == ImgDrawResult::BAD_ARGS ||
|
|
|
|
res == ImgDrawResult::NOT_SUPPORTED) {
|
2016-03-10 09:37:18 +03:00
|
|
|
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
|
|
|
|
|
|
|
LayoutDeviceIntPoint nsBaseDragService::ConvertToUnscaledDevPixels(
|
2016-10-19 22:01:39 +03:00
|
|
|
nsPresContext* aPresContext, CSSIntPoint aScreenPosition) {
|
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() {
|
2017-02-17 06:29:42 +03:00
|
|
|
EndDragSession(false, 0);
|
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;
|
|
|
|
}
|
|
|
|
|
2016-12-24 02:09:44 +03:00
|
|
|
NS_IMETHODIMP
|
2018-05-30 05:58:48 +03:00
|
|
|
nsBaseDragService::UpdateDragImage(nsINode* aImage, int32_t aImageX,
|
|
|
|
int32_t aImageY) {
|
2016-12-24 02:09:44 +03:00
|
|
|
// Don't change the image if this is a drag from another source or if there
|
|
|
|
// is a drag popup.
|
|
|
|
if (!mSourceNode || mDragPopup) return NS_OK;
|
|
|
|
|
|
|
|
mImage = aImage;
|
|
|
|
mImageOffset = CSSIntPoint(aImageX, aImageY);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-04-08 21:48:11 +03:00
|
|
|
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;
|
|
|
|
}
|
2019-10-01 17:07:27 +03:00
|
|
|
|
|
|
|
bool nsBaseDragService::RemoveAllChildProcesses() {
|
|
|
|
for (uint32_t c = 0; c < mChildProcesses.Length(); c++) {
|
|
|
|
mozilla::Unused << mChildProcesses[c]->SendEndDragSession(
|
2019-10-08 00:01:57 +03:00
|
|
|
true, false, LayoutDeviceIntPoint(), 0);
|
2019-10-01 17:07:27 +03:00
|
|
|
}
|
|
|
|
mChildProcesses.Clear();
|
|
|
|
return true;
|
|
|
|
}
|