2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-04-16 21:03:32 +00:00
|
|
|
|
|
|
|
#include "nsBaseDragService.h"
|
|
|
|
#include "nsITransferable.h"
|
|
|
|
|
2018-10-04 10:31:32 +00:00
|
|
|
#include "nsArrayUtils.h"
|
1999-04-16 21:03:32 +00:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsITransferable.h"
|
|
|
|
#include "nsSize.h"
|
2002-09-03 23:36:13 +00:00
|
|
|
#include "nsXPCOM.h"
|
1999-08-25 08:35:06 +00:00
|
|
|
#include "nsISupportsPrimitives.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2007-03-20 12:14:52 +00:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2000-08-16 01:46:34 +00:00
|
|
|
#include "nsIFrame.h"
|
2019-02-15 22:20:53 +00:00
|
|
|
#include "nsFrameLoaderOwner.h"
|
2019-01-02 13:05:23 +00:00
|
|
|
#include "mozilla/dom/Document.h"
|
2000-08-16 01:46:34 +00:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIPresShell.h"
|
2013-01-05 03:12:24 +00:00
|
|
|
#include "nsViewManager.h"
|
2018-05-30 02:58:48 +00:00
|
|
|
#include "nsINode.h"
|
2004-07-31 23:15:21 +00:00
|
|
|
#include "nsPresContext.h"
|
2007-03-20 12:14:52 +00:00
|
|
|
#include "nsIImageLoadingContent.h"
|
|
|
|
#include "imgIContainer.h"
|
|
|
|
#include "imgIRequest.h"
|
2014-08-22 20:12:38 +00:00
|
|
|
#include "ImageRegion.h"
|
2018-03-13 20:24:00 +00:00
|
|
|
#include "nsQueryObject.h"
|
2007-03-20 12:14:52 +00:00
|
|
|
#include "nsRegion.h"
|
2011-04-26 01:37:20 +00:00
|
|
|
#include "nsXULPopupManager.h"
|
|
|
|
#include "nsMenuPopupFrame.h"
|
2014-08-22 20:12:38 +00:00
|
|
|
#include "SVGImageContext.h"
|
2018-08-07 13:32:07 +00:00
|
|
|
#ifdef MOZ_XUL
|
|
|
|
# include "nsTreeBodyFrame.h"
|
|
|
|
#endif
|
2013-09-25 11:21:18 +00:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2011-05-23 14:54:03 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
2018-03-17 02:25:25 +00:00
|
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
2016-11-28 11:39:22 +00:00
|
|
|
#include "mozilla/dom/DataTransferItemList.h"
|
2018-03-13 20:23:59 +00:00
|
|
|
#include "mozilla/dom/DataTransfer.h"
|
2018-03-17 02:25:25 +00:00
|
|
|
#include "mozilla/dom/DragEvent.h"
|
2018-03-20 04:16:06 +00:00
|
|
|
#include "mozilla/dom/MouseEventBinding.h"
|
2018-03-27 04:35:22 +00:00
|
|
|
#include "mozilla/dom/Selection.h"
|
2014-01-29 00:10:33 +00:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2016-08-23 04:09:32 +00:00
|
|
|
#include "mozilla/Unused.h"
|
2015-04-08 18:48:11 +00:00
|
|
|
#include "nsFrameLoader.h"
|
|
|
|
#include "TabParent.h"
|
2007-03-20 12:14:52 +00:00
|
|
|
|
|
|
|
#include "gfxContext.h"
|
2009-04-22 12:55:51 +00:00
|
|
|
#include "gfxPlatform.h"
|
2013-01-15 12:22:03 +00:00
|
|
|
#include <algorithm>
|
2007-03-20 12:14:52 +00:00
|
|
|
|
2011-05-23 14:54:03 +00:00
|
|
|
using namespace mozilla;
|
2014-04-17 05:30:45 +00:00
|
|
|
using namespace mozilla::dom;
|
2014-08-22 20:12:38 +00:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
using namespace mozilla::image;
|
2011-05-23 14:54:03 +00:00
|
|
|
|
2007-05-16 18:05:23 +00:00
|
|
|
#define DRAGIMAGES_PREF "nglayout.enable_drag_images"
|
|
|
|
|
2005-03-14 22:49:00 +00:00
|
|
|
nsBaseDragService::nsBaseDragService()
|
2011-10-17 14:59:28 +00:00
|
|
|
: mCanDrop(false),
|
|
|
|
mOnlyChromeDrop(false),
|
|
|
|
mDoingDrag(false),
|
|
|
|
mHasImage(false),
|
|
|
|
mUserCancelled(false),
|
2015-04-08 18:48:11 +00:00
|
|
|
mDragEventDispatchedToChildProcess(false),
|
2015-06-05 12:33:29 +00:00
|
|
|
mDragAction(DRAGDROP_ACTION_NONE),
|
2018-11-20 01:17:54 +00:00
|
|
|
mDragActionFromChildProcess(DRAGDROP_ACTION_UNINITIALIZED),
|
2015-08-10 19:56:47 +00:00
|
|
|
mContentPolicyType(nsIContentPolicy::TYPE_OTHER),
|
2018-08-07 13:32:08 +00:00
|
|
|
mSuppressLevel(0),
|
|
|
|
mInputSource(MouseEvent_Binding::MOZ_SOURCE_MOUSE) {}
|
1999-04-16 21:03:32 +00:00
|
|
|
|
2016-11-16 14:23:37 +00:00
|
|
|
nsBaseDragService::~nsBaseDragService() = default;
|
1999-04-16 21:03:32 +00:00
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(nsBaseDragService, nsIDragService, nsIDragSession)
|
1999-04-16 21:03:32 +00:00
|
|
|
|
|
|
|
//---------------------------------------------------------
|
2005-03-14 22:49:00 +00:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsBaseDragService::SetCanDrop(bool aCanDrop) {
|
2005-03-14 22:49:00 +00:00
|
|
|
mCanDrop = aCanDrop;
|
|
|
|
return NS_OK;
|
1999-04-16 21:03:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
2005-03-14 22:49:00 +00:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsBaseDragService::GetCanDrop(bool* aCanDrop) {
|
1999-04-16 21:03:32 +00:00
|
|
|
*aCanDrop = mCanDrop;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-10-29 11:11:02 +00:00
|
|
|
//---------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsBaseDragService::SetOnlyChromeDrop(bool aOnlyChrome) {
|
2009-10-29 11:11:02 +00:00
|
|
|
mOnlyChromeDrop = aOnlyChrome;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsBaseDragService::GetOnlyChromeDrop(bool* aOnlyChrome) {
|
2009-10-29 11:11:02 +00:00
|
|
|
*aOnlyChrome = mOnlyChromeDrop;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-04-16 21:03:32 +00:00
|
|
|
|
1999-04-23 14:13:06 +00:00
|
|
|
//---------------------------------------------------------
|
2005-03-14 22:49:00 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsBaseDragService::SetDragAction(uint32_t anAction) {
|
2005-03-16 00:40:21 +00:00
|
|
|
mDragAction = anAction;
|
|
|
|
return NS_OK;
|
1999-04-23 14:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
2005-03-14 22:49:00 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsBaseDragService::GetDragAction(uint32_t* anAction) {
|
1999-04-23 14:13:06 +00:00
|
|
|
*anAction = mDragAction;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-05-26 21:08:14 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
2005-03-14 22:49:00 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsBaseDragService::GetNumDropItems(uint32_t* aNumItems) {
|
1999-05-26 21:08:14 +00:00
|
|
|
*aNumItems = 0;
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2000-07-31 20:51:42 +00:00
|
|
|
//
|
|
|
|
// GetSourceDocument
|
|
|
|
//
|
|
|
|
// Returns the DOM document where the drag was initiated. This will be
|
2012-07-30 14:20:58 +00:00
|
|
|
// nullptr if the drag began outside of our application.
|
2000-07-31 20:51:42 +00:00
|
|
|
//
|
|
|
|
NS_IMETHODIMP
|
2019-01-02 13:05:23 +00:00
|
|
|
nsBaseDragService::GetSourceDocument(Document** aSourceDocument) {
|
2000-07-31 20:51:42 +00:00
|
|
|
*aSourceDocument = mSourceDocument.get();
|
2005-03-14 22:49:00 +00:00
|
|
|
NS_IF_ADDREF(*aSourceDocument);
|
|
|
|
|
2000-07-31 20:51:42 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-05-20 05:58:25 +00:00
|
|
|
//
|
|
|
|
// GetSourceNode
|
|
|
|
//
|
|
|
|
// Returns the DOM node where the drag was initiated. This will be
|
2012-07-30 14:20:58 +00:00
|
|
|
// nullptr if the drag began outside of our application.
|
2001-05-20 05:58:25 +00:00
|
|
|
//
|
|
|
|
NS_IMETHODIMP
|
2018-05-30 02:58:48 +00:00
|
|
|
nsBaseDragService::GetSourceNode(nsINode** aSourceNode) {
|
|
|
|
*aSourceNode = do_AddRef(mSourceNode).take();
|
2001-05-20 05:58:25 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-02-09 01:43:53 +00:00
|
|
|
NS_IMETHODIMP
|
2019-01-04 03:16:46 +00:00
|
|
|
nsBaseDragService::GetTriggeringPrincipal(nsIPrincipal** aPrincipal) {
|
|
|
|
NS_IF_ADDREF(*aPrincipal = mTriggeringPrincipal);
|
2018-02-09 01:43:53 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-01-04 03:16:46 +00:00
|
|
|
nsBaseDragService::SetTriggeringPrincipal(nsIPrincipal* aPrincipal) {
|
|
|
|
mTriggeringPrincipal = aPrincipal;
|
2018-02-09 01:43:53 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-04-16 21:03:32 +00:00
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
1999-05-26 21:08:14 +00:00
|
|
|
|
2005-03-14 22:49:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseDragService::GetData(nsITransferable* aTransferable,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aItemIndex) {
|
1999-05-07 19:51:50 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
2005-03-14 22:49:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseDragService::IsDataFlavorSupported(const char* aDataFlavor,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool* _retval) {
|
1999-05-07 19:51:50 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1999-04-16 21:03:32 +00:00
|
|
|
|
2008-08-27 12:07:27 +00:00
|
|
|
NS_IMETHODIMP
|
2018-04-06 22:32:25 +00:00
|
|
|
nsBaseDragService::GetDataTransferXPCOM(DataTransfer** aDataTransfer) {
|
2008-08-27 12:07:27 +00:00
|
|
|
*aDataTransfer = mDataTransfer;
|
|
|
|
NS_IF_ADDREF(*aDataTransfer);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-04-06 22:32:25 +00:00
|
|
|
nsBaseDragService::SetDataTransferXPCOM(DataTransfer* aDataTransfer) {
|
|
|
|
NS_ENSURE_STATE(aDataTransfer);
|
|
|
|
mDataTransfer = aDataTransfer;
|
2008-08-27 12:07:27 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-03-13 20:23:59 +00:00
|
|
|
DataTransfer* nsBaseDragService::GetDataTransfer() { return mDataTransfer; }
|
|
|
|
|
|
|
|
void nsBaseDragService::SetDataTransfer(DataTransfer* aDataTransfer) {
|
|
|
|
mDataTransfer = aDataTransfer;
|
|
|
|
}
|
|
|
|
|
1999-05-07 19:51:50 +00:00
|
|
|
//-------------------------------------------------------------------------
|
2005-03-14 22:49:00 +00:00
|
|
|
NS_IMETHODIMP
|
2018-05-30 02:58:48 +00:00
|
|
|
nsBaseDragService::InvokeDragSession(
|
2019-01-04 03:16:46 +00:00
|
|
|
nsINode* aDOMNode, nsIPrincipal* aPrincipal, nsIArray* aTransferableArray,
|
|
|
|
uint32_t aActionType,
|
2015-08-10 19:56:47 +00: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 07:08:53 +00:00
|
|
|
AUTO_PROFILER_LABEL("nsBaseDragService::InvokeDragSession", OTHER);
|
2016-01-15 10:38:03 +00:00
|
|
|
|
2005-03-16 00:40:21 +00:00
|
|
|
NS_ENSURE_TRUE(aDOMNode, NS_ERROR_INVALID_ARG);
|
2008-03-19 00:06:22 +00:00
|
|
|
NS_ENSURE_TRUE(mSuppressLevel == 0, NS_ERROR_FAILURE);
|
2005-03-16 00:40:21 +00:00
|
|
|
|
|
|
|
// stash the document of the dom node
|
2018-05-30 02:58:48 +00:00
|
|
|
mSourceDocument = aDOMNode->OwnerDoc();
|
2019-01-04 03:16:46 +00:00
|
|
|
mTriggeringPrincipal = aPrincipal;
|
2005-03-16 00:40:21 +00:00
|
|
|
mSourceNode = aDOMNode;
|
2015-08-10 19:56:47 +00:00
|
|
|
mContentPolicyType = aContentPolicyType;
|
2015-10-26 20:33:13 +00:00
|
|
|
mEndDragPoint = LayoutDeviceIntPoint(0, 0);
|
2005-03-16 00:40:21 +00: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 13:13:16 +00:00
|
|
|
// are in the wrong coord system, so turn off mouse capture.
|
2012-07-30 14:20:58 +00:00
|
|
|
nsIPresShell::ClearMouseCapture(nullptr);
|
2005-03-16 00:40:21 +00:00
|
|
|
|
2018-10-04 10:31:32 +00:00
|
|
|
uint32_t length = 0;
|
|
|
|
mozilla::Unused << aTransferableArray->GetLength(&length);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-21 09:16:40 +00:00
|
|
|
nsresult rv = InvokeDragSessionImpl(aTransferableArray, mRegion, aActionType);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
2018-08-02 13:50:20 +00: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 09:16:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
1999-04-16 21:03:32 +00:00
|
|
|
}
|
|
|
|
|
2007-03-20 12:14:52 +00:00
|
|
|
NS_IMETHODIMP
|
2018-05-30 02:58:48 +00:00
|
|
|
nsBaseDragService::InvokeDragSessionWithImage(
|
2019-01-04 03:16:46 +00:00
|
|
|
nsINode* aDOMNode, nsIPrincipal* aPrincipal, nsIArray* aTransferableArray,
|
|
|
|
uint32_t aActionType, nsINode* aImage, int32_t aImageX, int32_t aImageY,
|
|
|
|
DragEvent* aDragEvent, DataTransfer* aDataTransfer) {
|
2007-03-20 12:14:52 +00:00
|
|
|
NS_ENSURE_TRUE(aDragEvent, NS_ERROR_NULL_POINTER);
|
2008-08-27 12:07:27 +00:00
|
|
|
NS_ENSURE_TRUE(aDataTransfer, NS_ERROR_NULL_POINTER);
|
2008-03-19 00:06:22 +00:00
|
|
|
NS_ENSURE_TRUE(mSuppressLevel == 0, NS_ERROR_FAILURE);
|
2007-03-20 12:14:52 +00:00
|
|
|
|
2018-03-13 20:24:00 +00:00
|
|
|
mDataTransfer = aDataTransfer;
|
2012-07-30 14:20:58 +00:00
|
|
|
mSelection = nullptr;
|
2011-10-17 14:59:28 +00:00
|
|
|
mHasImage = true;
|
2012-07-30 14:20:58 +00:00
|
|
|
mDragPopup = nullptr;
|
2007-03-20 12:14:52 +00:00
|
|
|
mImage = aImage;
|
2015-09-29 00:44:50 +00:00
|
|
|
mImageOffset = CSSIntPoint(aImageX, aImageY);
|
2007-03-20 12:14:52 +00:00
|
|
|
|
2018-04-06 22:32:25 +00:00
|
|
|
mScreenPosition.x = aDragEvent->ScreenX(CallerType::System);
|
|
|
|
mScreenPosition.y = aDragEvent->ScreenY(CallerType::System);
|
|
|
|
mInputSource = aDragEvent->MozInputSource();
|
2010-04-06 12:59:24 +00:00
|
|
|
|
2018-08-07 13:32:07 +00: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 13:32:08 +00:00
|
|
|
mRegion = Nothing();
|
2018-08-07 13:32:07 +00: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 13:32:08 +00:00
|
|
|
mRegion = treeBody->GetSelectionRegion();
|
2018-08-07 13:32:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-08-07 13:32:07 +00:00
|
|
|
nsresult rv =
|
2019-01-04 03:16:46 +00:00
|
|
|
InvokeDragSession(aDOMNode, aPrincipal, aTransferableArray, aActionType,
|
|
|
|
nsIContentPolicy::TYPE_INTERNAL_IMAGE);
|
2018-08-07 13:32:08 +00:00
|
|
|
mRegion = Nothing();
|
2018-08-07 13:32:07 +00:00
|
|
|
return rv;
|
2007-03-20 12:14:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-01-04 03:16:46 +00:00
|
|
|
nsBaseDragService::InvokeDragSessionWithSelection(Selection* aSelection,
|
|
|
|
nsIPrincipal* aPrincipal,
|
|
|
|
nsIArray* aTransferableArray,
|
|
|
|
uint32_t aActionType,
|
|
|
|
DragEvent* aDragEvent,
|
|
|
|
DataTransfer* aDataTransfer) {
|
2007-03-20 12:14:52 +00:00
|
|
|
NS_ENSURE_TRUE(aSelection, NS_ERROR_NULL_POINTER);
|
|
|
|
NS_ENSURE_TRUE(aDragEvent, NS_ERROR_NULL_POINTER);
|
2008-03-19 00:06:22 +00:00
|
|
|
NS_ENSURE_TRUE(mSuppressLevel == 0, NS_ERROR_FAILURE);
|
2007-03-20 12:14:52 +00:00
|
|
|
|
2018-03-13 20:24:00 +00:00
|
|
|
mDataTransfer = aDataTransfer;
|
2018-05-08 17:52:36 +00:00
|
|
|
mSelection = aSelection;
|
2011-10-17 14:59:28 +00:00
|
|
|
mHasImage = true;
|
2012-07-30 14:20:58 +00:00
|
|
|
mDragPopup = nullptr;
|
|
|
|
mImage = nullptr;
|
2015-09-29 00:44:50 +00:00
|
|
|
mImageOffset = CSSIntPoint();
|
2018-08-07 13:32:08 +00:00
|
|
|
mRegion = Nothing();
|
2007-03-20 12:14:52 +00:00
|
|
|
|
2018-04-06 22:32:25 +00:00
|
|
|
mScreenPosition.x = aDragEvent->ScreenX(CallerType::System);
|
|
|
|
mScreenPosition.y = aDragEvent->ScreenY(CallerType::System);
|
|
|
|
mInputSource = aDragEvent->MozInputSource();
|
2010-04-06 12:59:24 +00:00
|
|
|
|
2007-03-20 12:14:52 +00:00
|
|
|
// just get the focused node from the selection
|
2008-08-27 12:07:27 +00:00
|
|
|
// XXXndeakin this should actually be the deepest node that contains both
|
|
|
|
// endpoints of the selection
|
2018-05-30 02:58:48 +00:00
|
|
|
nsCOMPtr<nsINode> node = aSelection->GetFocusNode();
|
2007-03-20 12:14:52 +00:00
|
|
|
|
2019-01-04 03:16:46 +00:00
|
|
|
return InvokeDragSession(node, aPrincipal, aTransferableArray, aActionType,
|
|
|
|
nsIContentPolicy::TYPE_OTHER);
|
2007-03-20 12:14:52 +00:00
|
|
|
}
|
1999-05-07 19:51:50 +00:00
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
2005-03-14 22:49:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseDragService::GetCurrentSession(nsIDragSession** aSession) {
|
1999-05-07 19:51:50 +00:00
|
|
|
if (!aSession) return NS_ERROR_INVALID_ARG;
|
2005-03-14 22:49:00 +00: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 00:06:22 +00:00
|
|
|
if (!mSuppressLevel && mDoingDrag) {
|
1999-05-07 19:51:50 +00:00
|
|
|
*aSession = this;
|
1999-08-25 08:35:06 +00:00
|
|
|
NS_ADDREF(*aSession); // addRef because we're a "getter"
|
1999-05-07 19:51:50 +00:00
|
|
|
} else
|
2012-07-30 14:20:58 +00:00
|
|
|
*aSession = nullptr;
|
2005-03-14 22:49:00 +00:00
|
|
|
|
1999-05-07 19:51:50 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
2005-03-14 22:49:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseDragService::StartDragSession() {
|
1999-05-07 19:51:50 +00:00
|
|
|
if (mDoingDrag) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
mDoingDrag = true;
|
2009-10-29 11:11:02 +00:00
|
|
|
// By default dispatch drop also to content.
|
2011-10-17 14:59:28 +00:00
|
|
|
mOnlyChromeDrop = false;
|
2011-04-26 01:37:20 +00:00
|
|
|
|
1999-05-07 19:51:50 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-04-26 01:37:20 +00:00
|
|
|
void nsBaseDragService::OpenDragPopup() {
|
|
|
|
if (mDragPopup) {
|
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm) {
|
2016-10-19 19:01:39 +00:00
|
|
|
pm->ShowPopupAtScreen(mDragPopup, mScreenPosition.x - mImageOffset.x,
|
|
|
|
mScreenPosition.y - mImageOffset.y, false, nullptr);
|
2011-04-26 01:37:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-05 12:33:29 +00: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 19:51:50 +00:00
|
|
|
//-------------------------------------------------------------------------
|
2005-03-14 22:49:00 +00:00
|
|
|
NS_IMETHODIMP
|
2017-02-17 03:29:42 +00:00
|
|
|
nsBaseDragService::EndDragSession(bool aDoneDrag, uint32_t aKeyModifiers) {
|
1999-05-07 19:51:50 +00:00
|
|
|
if (!mDoingDrag) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2005-03-16 00:40:21 +00:00
|
|
|
|
2015-09-02 06:08:02 +00:00
|
|
|
if (aDoneDrag && !mSuppressLevel) {
|
2017-02-17 03:29:42 +00:00
|
|
|
FireDragEventAtSource(eDragEnd, aKeyModifiers);
|
2015-09-02 06:08:02 +00:00
|
|
|
}
|
2007-04-12 04:37:39 +00:00
|
|
|
|
2011-04-26 01:37:20 +00:00
|
|
|
if (mDragPopup) {
|
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm) {
|
2014-04-08 12:45:52 +00:00
|
|
|
pm->HidePopup(mDragPopup, false, true, false, false);
|
2011-04-26 01:37:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-08 18:48:11 +00:00
|
|
|
for (uint32_t i = 0; i < mChildProcesses.Length(); ++i) {
|
2015-11-02 05:53:26 +00:00
|
|
|
mozilla::Unused << mChildProcesses[i]->SendEndDragSession(
|
2017-02-17 03:29:42 +00:00
|
|
|
aDoneDrag, mUserCancelled, mEndDragPoint, aKeyModifiers);
|
2017-08-02 07:23:35 +00:00
|
|
|
// Continue sending input events with input priority when stopping the dnd
|
|
|
|
// session.
|
|
|
|
mChildProcesses[i]->SetInputPriorityEventEnabled(true);
|
2015-04-08 18:48:11 +00:00
|
|
|
}
|
|
|
|
mChildProcesses.Clear();
|
|
|
|
|
2016-11-28 11:39:22 +00: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 14:59:28 +00:00
|
|
|
mDoingDrag = false;
|
2015-04-08 18:48:11 +00:00
|
|
|
mCanDrop = false;
|
2005-03-16 00:40:21 +00:00
|
|
|
|
|
|
|
// release the source we've been holding on to.
|
2012-07-30 14:20:58 +00:00
|
|
|
mSourceDocument = nullptr;
|
|
|
|
mSourceNode = nullptr;
|
2019-01-04 03:16:46 +00:00
|
|
|
mTriggeringPrincipal = nullptr;
|
2012-07-30 14:20:58 +00:00
|
|
|
mSelection = nullptr;
|
|
|
|
mDataTransfer = nullptr;
|
2011-10-17 14:59:28 +00:00
|
|
|
mHasImage = false;
|
|
|
|
mUserCancelled = false;
|
2012-07-30 14:20:58 +00:00
|
|
|
mDragPopup = nullptr;
|
|
|
|
mImage = nullptr;
|
2015-09-29 00:44:50 +00:00
|
|
|
mImageOffset = CSSIntPoint();
|
2016-10-19 19:01:39 +00:00
|
|
|
mScreenPosition = CSSIntPoint();
|
2015-10-26 20:33:13 +00:00
|
|
|
mEndDragPoint = LayoutDeviceIntPoint(0, 0);
|
2018-06-25 21:20:54 +00:00
|
|
|
mInputSource = MouseEvent_Binding::MOZ_SOURCE_MOUSE;
|
2018-08-07 13:32:08 +00:00
|
|
|
mRegion = Nothing();
|
2007-03-20 12:14:52 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-11-28 11:39:22 +00:00
|
|
|
void nsBaseDragService::DiscardInternalTransferData() {
|
|
|
|
if (mDataTransfer && mSourceNode) {
|
2018-03-13 20:24:00 +00:00
|
|
|
MOZ_ASSERT(mDataTransfer);
|
2016-11-28 11:39:22 +00:00
|
|
|
|
2018-03-13 20:24:00 +00:00
|
|
|
DataTransferItemList* items = mDataTransfer->Items();
|
2016-11-28 11:39:22 +00: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 04:37:39 +00:00
|
|
|
NS_IMETHODIMP
|
2017-02-17 03:29:42 +00:00
|
|
|
nsBaseDragService::FireDragEventAtSource(EventMessage aEventMessage,
|
|
|
|
uint32_t aKeyModifiers) {
|
2018-05-11 17:46:15 +00:00
|
|
|
if (mSourceNode && mSourceDocument && !mSuppressLevel) {
|
|
|
|
nsCOMPtr<nsIPresShell> presShell = mSourceDocument->GetShell();
|
|
|
|
if (presShell) {
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
WidgetDragEvent event(true, aEventMessage, nullptr);
|
|
|
|
event.inputSource = mInputSource;
|
|
|
|
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 18:24:28 +00:00
|
|
|
}
|
2007-04-12 04:37:39 +00:00
|
|
|
}
|
2018-05-11 17:46:15 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(mSourceNode);
|
|
|
|
return presShell->HandleDOMEventWithTarget(content, &event, &status);
|
2007-04-12 04:37:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-04-26 01:37:20 +00: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 15:56:38 +00:00
|
|
|
nsBaseDragService::DragMoved(int32_t aX, int32_t aY) {
|
2011-04-26 01:37:20 +00:00
|
|
|
if (mDragPopup) {
|
|
|
|
nsIFrame* frame = mDragPopup->GetPrimaryFrame();
|
2017-04-30 15:30:08 +00:00
|
|
|
if (frame && frame->IsMenuPopupFrame()) {
|
2015-09-29 00:17:34 +00:00
|
|
|
CSSIntPoint cssPos =
|
|
|
|
RoundedToInt(LayoutDeviceIntPoint(aX, aY) /
|
|
|
|
frame->PresContext()->CSSToDevPixelScale()) -
|
|
|
|
mImageOffset;
|
|
|
|
(static_cast<nsMenuPopupFrame*>(frame))->MoveTo(cssPos, true);
|
2011-04-26 01:37:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-05-30 02:58:48 +00:00
|
|
|
static nsIPresShell* GetPresShellForContent(nsINode* aDOMNode) {
|
2007-03-28 21:18:11 +00:00
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(aDOMNode);
|
2012-07-30 14:20:58 +00:00
|
|
|
if (!content) return nullptr;
|
2010-02-28 11:18:19 +00:00
|
|
|
|
2019-01-02 13:05:23 +00:00
|
|
|
RefPtr<Document> document = content->GetComposedDoc();
|
2007-03-20 12:14:52 +00:00
|
|
|
if (document) {
|
2017-01-05 07:31:56 +00:00
|
|
|
document->FlushPendingNotifications(FlushType::Display);
|
2010-06-25 13:59:57 +00:00
|
|
|
return document->GetShell();
|
2007-03-20 12:14:52 +00:00
|
|
|
}
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2007-03-20 12:14:52 +00:00
|
|
|
}
|
|
|
|
|
2018-05-30 02:58:48 +00:00
|
|
|
nsresult nsBaseDragService::DrawDrag(nsINode* aDOMNode,
|
2018-08-07 13:32:08 +00:00
|
|
|
const Maybe<CSSIntRegion>& aRegion,
|
2016-10-19 19:01:39 +00:00
|
|
|
CSSIntPoint aScreenPosition,
|
2016-10-19 19:01:39 +00:00
|
|
|
LayoutDeviceIntRect* aScreenDragRect,
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<SourceSurface>* aSurface,
|
2008-01-08 22:03:53 +00:00
|
|
|
nsPresContext** aPresContext) {
|
2012-07-30 14:20:58 +00:00
|
|
|
*aSurface = nullptr;
|
|
|
|
*aPresContext = nullptr;
|
2007-03-20 12:14:52 +00:00
|
|
|
|
|
|
|
// use a default size, in case of an error.
|
2018-01-10 16:14:16 +00:00
|
|
|
aScreenDragRect->SetRect(aScreenPosition.x - mImageOffset.x,
|
|
|
|
aScreenPosition.y - mImageOffset.y, 1, 1);
|
2007-03-20 12:14:52 +00:00
|
|
|
|
|
|
|
// if a drag image was specified, use that, otherwise, use the source node
|
2018-05-30 02:58:48 +00:00
|
|
|
nsCOMPtr<nsINode> dragNode = mImage ? mImage.get() : aDOMNode;
|
2007-03-20 12:14:52 +00: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
|
|
|
|
nsIPresShell* presShell = GetPresShellForContent(dragNode);
|
|
|
|
if (!presShell && mImage) presShell = GetPresShellForContent(aDOMNode);
|
|
|
|
if (!presShell) return NS_ERROR_FAILURE;
|
|
|
|
|
2008-01-08 22:03:53 +00:00
|
|
|
*aPresContext = presShell->GetPresContext();
|
|
|
|
|
2019-02-15 22:20:53 +00:00
|
|
|
RefPtr<nsFrameLoaderOwner> flo = do_QueryObject(dragNode);
|
2015-04-08 18:48:11 +00:00
|
|
|
if (flo) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsFrameLoader> fl = flo->GetFrameLoader();
|
2015-04-08 18:48:11 +00:00
|
|
|
if (fl) {
|
2016-11-16 14:22:36 +00:00
|
|
|
auto* tp = static_cast<mozilla::dom::TabParent*>(fl->GetRemoteBrowser());
|
2016-10-19 19:01:39 +00: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 18:48:11 +00:00
|
|
|
}
|
2016-10-19 19:01:39 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
2015-04-08 18:48:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-14 20:25:51 +00:00
|
|
|
// convert mouse position to dev pixels of the prescontext
|
2016-10-19 19:01:39 +00:00
|
|
|
CSSIntPoint screenPosition(aScreenPosition);
|
|
|
|
screenPosition.x -= mImageOffset.x;
|
|
|
|
screenPosition.y -= mImageOffset.y;
|
|
|
|
LayoutDeviceIntPoint screenPoint =
|
|
|
|
ConvertToUnscaledDevPixels(*aPresContext, screenPosition);
|
2018-01-10 16:14:16 +00:00
|
|
|
aScreenDragRect->MoveTo(screenPoint.x, screenPoint.y);
|
2012-12-14 20:25:51 +00:00
|
|
|
|
2007-05-16 18:05:23 +00:00
|
|
|
// check if drag images are disabled
|
2011-09-29 06:19:26 +00:00
|
|
|
bool enableDragImages = Preferences::GetBool(DRAGIMAGES_PREF, true);
|
2007-05-16 18:05:23 +00:00
|
|
|
|
2007-03-20 12:14:52 +00:00
|
|
|
// didn't want an image, so just set the screen rectangle to the frame size
|
2007-05-16 18:05:23 +00:00
|
|
|
if (!enableDragImages || !mHasImage) {
|
2007-03-20 12:14:52 +00:00
|
|
|
// if a region was specified, set the screen rectangle to the area that
|
|
|
|
// the region occupies
|
2017-04-24 22:33:13 +00:00
|
|
|
CSSIntRect dragRect;
|
2007-03-20 12:14:52 +00:00
|
|
|
if (aRegion) {
|
|
|
|
// the region's coordinates are relative to the root frame
|
2018-08-07 13:32:08 +00:00
|
|
|
dragRect = aRegion->GetBounds();
|
2016-10-19 19:01:39 +00:00
|
|
|
|
2007-03-20 12:14:52 +00:00
|
|
|
nsIFrame* rootFrame = presShell->GetRootFrame();
|
2017-04-24 22:33:13 +00:00
|
|
|
CSSIntRect screenRect = rootFrame->GetScreenRect();
|
2016-10-19 19:01:39 +00:00
|
|
|
dragRect.MoveBy(screenRect.TopLeft());
|
2007-03-20 12:14:52 +00: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-24 21:20:06 +00:00
|
|
|
nsIFrame* frame = content->GetPrimaryFrame();
|
2007-03-20 12:14:52 +00:00
|
|
|
if (frame) {
|
2016-10-19 19:01:39 +00:00
|
|
|
dragRect = frame->GetScreenRect();
|
2007-03-20 12:14:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-24 22:33:13 +00:00
|
|
|
nsIntRect dragRectDev =
|
2018-08-11 04:46:23 +00:00
|
|
|
ToAppUnits(dragRect, AppUnitsPerCSSPixel())
|
2017-04-24 22:33:13 +00:00
|
|
|
.ToOutsidePixels((*aPresContext)->AppUnitsPerDevPixel());
|
2018-01-10 16:14:16 +00:00
|
|
|
aScreenDragRect->SizeTo(dragRectDev.Width(), dragRectDev.Height());
|
2007-03-20 12:14:52 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// draw the image for selections
|
|
|
|
if (mSelection) {
|
2016-10-19 19:01:39 +00:00
|
|
|
LayoutDeviceIntPoint pnt(aScreenDragRect->TopLeft());
|
2015-07-11 16:15:19 +00:00
|
|
|
*aSurface = presShell->RenderSelection(
|
|
|
|
mSelection, pnt, aScreenDragRect,
|
2016-05-13 10:48:00 +00:00
|
|
|
mImage ? 0 : nsIPresShell::RENDER_AUTO_SCALE);
|
2007-03-20 12:14:52 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-04-26 01:37:20 +00:00
|
|
|
// if a custom image was specified, check if it is an image node and draw
|
2007-03-20 12:14:52 +00:00
|
|
|
// using the source rather than the displayed image. But if mImage isn't
|
2011-04-26 01:37:20 +00:00
|
|
|
// an image or canvas, fall through to RenderNode below.
|
2007-03-20 12:14:52 +00:00
|
|
|
if (mImage) {
|
2014-04-17 05:30:45 +00:00
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(dragNode);
|
2018-03-21 21:39:04 +00:00
|
|
|
HTMLCanvasElement* canvas = HTMLCanvasElement::FromNodeOrNull(content);
|
2008-09-10 16:57:58 +00:00
|
|
|
if (canvas) {
|
2016-10-19 19:01:40 +00:00
|
|
|
return DrawDragForImage(*aPresContext, nullptr, canvas, aScreenDragRect,
|
|
|
|
aSurface);
|
2008-09-10 16:57:58 +00:00
|
|
|
}
|
|
|
|
|
2007-03-20 12:14:52 +00:00
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(dragNode);
|
|
|
|
// for image nodes, create the drag image from the actual image data
|
|
|
|
if (imageLoader) {
|
2016-10-19 19:01:40 +00:00
|
|
|
return DrawDragForImage(*aPresContext, imageLoader, nullptr,
|
|
|
|
aScreenDragRect, aSurface);
|
2007-03-20 12:14:52 +00:00
|
|
|
}
|
|
|
|
|
2011-04-26 01:37:20 +00: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 15:30:08 +00:00
|
|
|
if (frame && frame->IsMenuPopupFrame()) {
|
2011-04-26 01:37:20 +00:00
|
|
|
mDragPopup = content;
|
|
|
|
}
|
2010-06-05 20:29:49 +00:00
|
|
|
}
|
2007-03-20 12:14:52 +00:00
|
|
|
|
2011-04-26 01:37:20 +00:00
|
|
|
if (!mDragPopup) {
|
|
|
|
// otherwise, just draw the node
|
2016-05-13 10:48:00 +00:00
|
|
|
uint32_t renderFlags = mImage ? 0 : nsIPresShell::RENDER_AUTO_SCALE;
|
|
|
|
if (renderFlags) {
|
2017-10-18 17:16:03 +00:00
|
|
|
// check if the dragged node itself is an img element
|
2018-10-01 21:38:01 +00:00
|
|
|
if (dragNode->NodeName().LowerCaseEqualsLiteral("img")) {
|
2017-10-18 17:16:03 +00:00
|
|
|
renderFlags = renderFlags | nsIPresShell::RENDER_IS_IMAGE;
|
2018-01-30 04:10:50 +00:00
|
|
|
} else {
|
2018-10-01 21:38:01 +00:00
|
|
|
nsINodeList* childList = dragNode->ChildNodes();
|
2018-01-30 04:10:50 +00:00
|
|
|
uint32_t length = childList->Length();
|
2017-10-18 17:16:03 +00:00
|
|
|
// check every childnode for being an img element
|
2018-01-30 04:10:50 +00: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")) {
|
2017-10-18 17:16:03 +00:00
|
|
|
// if the dragnode contains an image, set RENDER_IS_IMAGE flag
|
2016-05-13 10:48:00 +00:00
|
|
|
renderFlags = renderFlags | nsIPresShell::RENDER_IS_IMAGE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-10-19 19:01:39 +00:00
|
|
|
LayoutDeviceIntPoint pnt(aScreenDragRect->TopLeft());
|
2018-08-07 13:32:08 +00:00
|
|
|
*aSurface = presShell->RenderNode(dragNode, aRegion, pnt, aScreenDragRect,
|
2016-10-19 19:01:39 +00:00
|
|
|
renderFlags);
|
2011-04-26 01:37:20 +00:00
|
|
|
}
|
2007-03-20 12:14:52 +00:00
|
|
|
|
2016-10-19 19:01:39 +00:00
|
|
|
// If an image was specified, reset the position from the offset that was
|
|
|
|
// supplied.
|
2007-03-20 12:14:52 +00:00
|
|
|
if (mImage) {
|
2018-01-10 16:14:16 +00:00
|
|
|
aScreenDragRect->MoveTo(screenPoint.x, screenPoint.y);
|
2007-03-20 12:14:52 +00:00
|
|
|
}
|
|
|
|
|
1999-05-07 19:51:50 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-20 12:14:52 +00:00
|
|
|
|
2016-10-19 19:01:40 +00:00
|
|
|
nsresult nsBaseDragService::DrawDragForImage(
|
|
|
|
nsPresContext* aPresContext, nsIImageLoadingContent* aImageLoader,
|
2016-10-19 19:01:39 +00:00
|
|
|
HTMLCanvasElement* aCanvas, LayoutDeviceIntRect* aScreenDragRect,
|
2015-10-18 05:24:48 +00: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 01:50:15 +00:00
|
|
|
nsCOMPtr<imgIContainer> imgContainer;
|
2008-09-10 16:57:58 +00: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 19:01:40 +00: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 16:14:16 +00:00
|
|
|
aScreenDragRect->SizeTo(aPresContext->CSSPixelsToDevPixels(imageWidth),
|
|
|
|
aPresContext->CSSPixelsToDevPixels(imageHeight));
|
2008-09-10 16:57:58 +00:00
|
|
|
} else {
|
2016-10-19 19:01:40 +00:00
|
|
|
// XXX The canvas size should be converted to dev pixels.
|
2008-09-10 16:57:58 +00:00
|
|
|
NS_ASSERTION(aCanvas, "both image and canvas are null");
|
2014-04-17 05:30:45 +00:00
|
|
|
nsIntSize sz = aCanvas->GetSize();
|
2018-01-10 16:14:16 +00:00
|
|
|
aScreenDragRect->SizeTo(sz.width, sz.height);
|
2008-09-10 16:57:58 +00:00
|
|
|
}
|
2007-03-20 12:14:52 +00:00
|
|
|
|
2016-10-19 19:01:39 +00:00
|
|
|
nsIntSize destSize;
|
2018-01-10 16:14:16 +00:00
|
|
|
destSize.width = aScreenDragRect->Width();
|
|
|
|
destSize.height = aScreenDragRect->Height();
|
2008-11-04 22:01:21 +00:00
|
|
|
if (destSize.width == 0 || destSize.height == 0) return NS_ERROR_FAILURE;
|
2007-03-20 12:14:52 +00:00
|
|
|
|
2014-04-17 06:43:41 +00:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
if (aImageLoader) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<DrawTarget> dt =
|
2015-03-29 14:59:08 +00:00
|
|
|
gfxPlatform::GetPlatform()->CreateOffscreenContentDrawTarget(
|
2014-04-17 05:30:45 +00:00
|
|
|
destSize, SurfaceFormat::B8G8R8A8);
|
2016-04-12 19:18:11 +00:00
|
|
|
if (!dt || !dt->IsValid()) return NS_ERROR_FAILURE;
|
2014-04-17 05:30:45 +00:00
|
|
|
|
2016-06-06 23:39:56 +00:00
|
|
|
RefPtr<gfxContext> ctx = gfxContext::CreateOrNull(dt);
|
2014-04-17 05:30:45 +00:00
|
|
|
if (!ctx) return NS_ERROR_FAILURE;
|
|
|
|
|
2017-12-11 15:37:59 +00:00
|
|
|
ImgDrawResult res =
|
2016-03-10 06:37:18 +00:00
|
|
|
imgContainer->Draw(ctx, destSize, ImageRegion::Create(destSize),
|
|
|
|
imgIContainer::FRAME_CURRENT, SamplingFilter::GOOD,
|
2016-05-25 16:01:18 +00:00
|
|
|
/* no SVGImageContext */ Nothing(),
|
2017-01-03 05:53:22 +00:00
|
|
|
imgIContainer::FLAG_SYNC_DECODE, 1.0);
|
2018-09-13 23:48:21 +00:00
|
|
|
if (res == ImgDrawResult::BAD_IMAGE || res == ImgDrawResult::BAD_ARGS ||
|
|
|
|
res == ImgDrawResult::NOT_SUPPORTED) {
|
2016-03-10 06:37:18 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2014-04-17 05:30:45 +00:00
|
|
|
*aSurface = dt->Snapshot();
|
2008-11-04 22:01:21 +00:00
|
|
|
} else {
|
2014-04-17 05:30:45 +00:00
|
|
|
*aSurface = aCanvas->GetSurfaceSnapshot();
|
2008-09-10 16:57:58 +00:00
|
|
|
}
|
2014-01-29 00:10:33 +00:00
|
|
|
|
|
|
|
return result;
|
2007-03-20 12:14:52 +00:00
|
|
|
}
|
2008-01-08 22:03:53 +00:00
|
|
|
|
|
|
|
LayoutDeviceIntPoint nsBaseDragService::ConvertToUnscaledDevPixels(
|
2016-10-19 19:01:39 +00:00
|
|
|
nsPresContext* aPresContext, CSSIntPoint aScreenPosition) {
|
2014-11-13 11:53:02 +00:00
|
|
|
int32_t adj =
|
|
|
|
aPresContext->DeviceContext()->AppUnitsPerDevPixelAtUnitFullZoom();
|
2016-10-19 19:01:39 +00:00
|
|
|
return LayoutDeviceIntPoint(
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(aScreenPosition.x) / adj,
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(aScreenPosition.y) / adj);
|
2008-01-08 22:03:53 +00:00
|
|
|
}
|
|
|
|
|
2008-03-19 00:06:22 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseDragService::Suppress() {
|
2017-02-17 03:29:42 +00:00
|
|
|
EndDragSession(false, 0);
|
2008-03-19 00:06:22 +00:00
|
|
|
++mSuppressLevel;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseDragService::Unsuppress() {
|
|
|
|
--mSuppressLevel;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2015-04-08 18:48:11 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseDragService::UserCancelled() {
|
|
|
|
mUserCancelled = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseDragService::UpdateDragEffect() {
|
2015-06-05 12:33:29 +00:00
|
|
|
mDragActionFromChildProcess = mDragAction;
|
2015-04-08 18:48:11 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-12-23 23:09:44 +00:00
|
|
|
NS_IMETHODIMP
|
2018-05-30 02:58:48 +00:00
|
|
|
nsBaseDragService::UpdateDragImage(nsINode* aImage, int32_t aImageX,
|
|
|
|
int32_t aImageY) {
|
2016-12-23 23:09:44 +00: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 18:48:11 +00: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;
|
|
|
|
}
|