gecko-dev/widget/nsBaseDragService.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

798 строки
26 KiB
C++
Исходник Обычный вид История

/* -*- 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 "nsArrayUtils.h"
1999-04-17 01:03:32 +04:00
#include "nsIServiceManager.h"
#include "nsITransferable.h"
#include "nsSize.h"
#include "nsXPCOM.h"
#include "nsISupportsPrimitives.h"
#include "nsCOMPtr.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIFrame.h"
#include "mozilla/dom/Document.h"
#include "nsIContent.h"
#include "nsIPresShell.h"
#include "nsViewManager.h"
#include "nsINode.h"
#include "nsPresContext.h"
#include "nsIImageLoadingContent.h"
#include "imgIContainer.h"
#include "imgIRequest.h"
#include "ImageRegion.h"
#include "nsQueryObject.h"
#include "nsRegion.h"
#include "nsXULPopupManager.h"
#include "nsMenuPopupFrame.h"
#include "SVGImageContext.h"
#ifdef MOZ_XUL
#include "nsTreeBodyFrame.h"
#endif
#include "mozilla/MouseEvents.h"
#include "mozilla/Preferences.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/DataTransferItemList.h"
#include "mozilla/dom/DataTransfer.h"
#include "mozilla/dom/DragEvent.h"
#include "mozilla/dom/MouseEventBinding.h"
#include "mozilla/dom/Selection.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/Unused.h"
#include "nsFrameLoader.h"
#include "TabParent.h"
#include "gfxContext.h"
#include "gfxPlatform.h"
#include <algorithm>
using namespace mozilla;
using namespace mozilla::dom;
using namespace mozilla::gfx;
using namespace mozilla::image;
#define DRAGIMAGES_PREF "nglayout.enable_drag_images"
nsBaseDragService::nsBaseDragService()
: mCanDrop(false),
mOnlyChromeDrop(false),
mDoingDrag(false),
mHasImage(false),
mUserCancelled(false),
mDragEventDispatchedToChildProcess(false),
mDragAction(DRAGDROP_ACTION_NONE),
mDragActionFromChildProcess(DRAGDROP_ACTION_UNINITIALIZED),
mContentPolicyType(nsIContentPolicy::TYPE_OTHER),
mSuppressLevel(0),
mInputSource(MouseEvent_Binding::MOZ_SOURCE_MOUSE) {}
1999-04-17 01:03:32 +04:00
nsBaseDragService::~nsBaseDragService() = default;
1999-04-17 01:03:32 +04:00
NS_IMPL_ISUPPORTS(nsBaseDragService, nsIDragService, nsIDragSession)
1999-04-17 01:03:32 +04:00
//---------------------------------------------------------
NS_IMETHODIMP
nsBaseDragService::SetCanDrop(bool aCanDrop) {
mCanDrop = aCanDrop;
return NS_OK;
1999-04-17 01:03:32 +04:00
}
//---------------------------------------------------------
NS_IMETHODIMP
nsBaseDragService::GetCanDrop(bool* aCanDrop) {
1999-04-17 01:03:32 +04:00
*aCanDrop = mCanDrop;
return NS_OK;
}
//---------------------------------------------------------
NS_IMETHODIMP
nsBaseDragService::SetOnlyChromeDrop(bool aOnlyChrome) {
mOnlyChromeDrop = aOnlyChrome;
return NS_OK;
}
//---------------------------------------------------------
NS_IMETHODIMP
nsBaseDragService::GetOnlyChromeDrop(bool* aOnlyChrome) {
*aOnlyChrome = mOnlyChromeDrop;
return NS_OK;
}
1999-04-17 01:03:32 +04:00
1999-04-23 18:13:06 +04:00
//---------------------------------------------------------
NS_IMETHODIMP
nsBaseDragService::SetDragAction(uint32_t anAction) {
mDragAction = anAction;
return NS_OK;
1999-04-23 18:13:06 +04:00
}
//---------------------------------------------------------
NS_IMETHODIMP
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
//-------------------------------------------------------------------------
NS_IMETHODIMP
nsBaseDragService::GetNumDropItems(uint32_t* aNumItems) {
1999-05-27 01:08:14 +04:00
*aNumItems = 0;
return NS_ERROR_FAILURE;
}
//
// GetSourceDocument
//
// Returns the DOM document where the drag was initiated. This will be
// nullptr if the drag began outside of our application.
//
NS_IMETHODIMP
nsBaseDragService::GetSourceDocument(Document** aSourceDocument) {
*aSourceDocument = mSourceDocument.get();
NS_IF_ADDREF(*aSourceDocument);
return NS_OK;
}
//
// GetSourceNode
//
// Returns the DOM node where the drag was initiated. This will be
// nullptr if the drag began outside of our application.
//
NS_IMETHODIMP
nsBaseDragService::GetSourceNode(nsINode** aSourceNode) {
*aSourceNode = do_AddRef(mSourceNode).take();
return NS_OK;
}
NS_IMETHODIMP
nsBaseDragService::GetTriggeringPrincipal(nsIPrincipal** aPrincipal) {
NS_IF_ADDREF(*aPrincipal = mTriggeringPrincipal);
return NS_OK;
}
NS_IMETHODIMP
nsBaseDragService::SetTriggeringPrincipal(nsIPrincipal* aPrincipal) {
mTriggeringPrincipal = aPrincipal;
return NS_OK;
}
1999-04-17 01:03:32 +04:00
//-------------------------------------------------------------------------
1999-05-27 01:08:14 +04:00
NS_IMETHODIMP
nsBaseDragService::GetData(nsITransferable* aTransferable,
uint32_t aItemIndex) {
1999-05-07 23:51:50 +04:00
return NS_ERROR_FAILURE;
}
//-------------------------------------------------------------------------
NS_IMETHODIMP
nsBaseDragService::IsDataFlavorSupported(const char* aDataFlavor,
bool* _retval) {
1999-05-07 23:51:50 +04:00
return NS_ERROR_FAILURE;
}
1999-04-17 01:03:32 +04:00
NS_IMETHODIMP
nsBaseDragService::GetDataTransferXPCOM(DataTransfer** aDataTransfer) {
*aDataTransfer = mDataTransfer;
NS_IF_ADDREF(*aDataTransfer);
return NS_OK;
}
NS_IMETHODIMP
nsBaseDragService::SetDataTransferXPCOM(DataTransfer* aDataTransfer) {
NS_ENSURE_STATE(aDataTransfer);
mDataTransfer = aDataTransfer;
return NS_OK;
}
DataTransfer* nsBaseDragService::GetDataTransfer() { return mDataTransfer; }
void nsBaseDragService::SetDataTransfer(DataTransfer* aDataTransfer) {
mDataTransfer = aDataTransfer;
}
1999-05-07 23:51:50 +04:00
//-------------------------------------------------------------------------
NS_IMETHODIMP
nsBaseDragService::InvokeDragSession(
nsINode* aDOMNode, nsIPrincipal* aPrincipal, nsIArray* aTransferableArray,
uint32_t aActionType,
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);
NS_ENSURE_TRUE(aDOMNode, NS_ERROR_INVALID_ARG);
2008-03-19 03:06:22 +03:00
NS_ENSURE_TRUE(mSuppressLevel == 0, NS_ERROR_FAILURE);
// stash the document of the dom node
mSourceDocument = aDOMNode->OwnerDoc();
mTriggeringPrincipal = aPrincipal;
mSourceNode = aDOMNode;
mContentPolicyType = aContentPolicyType;
mEndDragPoint = LayoutDeviceIntPoint(0, 0);
// 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
// are in the wrong coord system, so turn off mouse capture.
nsIPresShell::ClearMouseCapture(nullptr);
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);
}
}
nsresult rv = InvokeDragSessionImpl(aTransferableArray, mRegion, aActionType);
if (NS_FAILED(rv)) {
// Set mDoingDrag so that EndDragSession cleans up and sends the dragend
// event after the aborted drag.
mDoingDrag = true;
EndDragSession(true, 0);
}
return rv;
1999-04-17 01:03:32 +04:00
}
NS_IMETHODIMP
nsBaseDragService::InvokeDragSessionWithImage(
nsINode* aDOMNode, nsIPrincipal* aPrincipal, nsIArray* aTransferableArray,
uint32_t aActionType, nsINode* aImage, int32_t aImageX, int32_t aImageY,
DragEvent* aDragEvent, DataTransfer* aDataTransfer) {
NS_ENSURE_TRUE(aDragEvent, NS_ERROR_NULL_POINTER);
NS_ENSURE_TRUE(aDataTransfer, NS_ERROR_NULL_POINTER);
2008-03-19 03:06:22 +03:00
NS_ENSURE_TRUE(mSuppressLevel == 0, NS_ERROR_FAILURE);
mDataTransfer = aDataTransfer;
mSelection = nullptr;
mHasImage = true;
mDragPopup = nullptr;
mImage = aImage;
mImageOffset = CSSIntPoint(aImageX, aImageY);
mScreenPosition.x = aDragEvent->ScreenX(CallerType::System);
mScreenPosition.y = aDragEvent->ScreenY(CallerType::System);
mInputSource = aDragEvent->MozInputSource();
// 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.
mRegion = Nothing();
#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) {
mRegion = treeBody->GetSelectionRegion();
}
}
}
#endif
nsresult rv =
InvokeDragSession(aDOMNode, aPrincipal, aTransferableArray, aActionType,
nsIContentPolicy::TYPE_INTERNAL_IMAGE);
mRegion = Nothing();
return rv;
}
NS_IMETHODIMP
nsBaseDragService::InvokeDragSessionWithSelection(Selection* aSelection,
nsIPrincipal* aPrincipal,
nsIArray* aTransferableArray,
uint32_t aActionType,
DragEvent* aDragEvent,
DataTransfer* aDataTransfer) {
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);
mDataTransfer = aDataTransfer;
mSelection = aSelection;
mHasImage = true;
mDragPopup = nullptr;
mImage = nullptr;
mImageOffset = CSSIntPoint();
mRegion = Nothing();
mScreenPosition.x = aDragEvent->ScreenX(CallerType::System);
mScreenPosition.y = aDragEvent->ScreenY(CallerType::System);
mInputSource = aDragEvent->MozInputSource();
// just get the focused node from the selection
// XXXndeakin this should actually be the deepest node that contains both
// endpoints of the selection
nsCOMPtr<nsINode> node = aSelection->GetFocusNode();
return InvokeDragSession(node, aPrincipal, aTransferableArray, aActionType,
nsIContentPolicy::TYPE_OTHER);
}
1999-05-07 23:51:50 +04:00
//-------------------------------------------------------------------------
NS_IMETHODIMP
nsBaseDragService::GetCurrentSession(nsIDragSession** aSession) {
1999-05-07 23:51:50 +04:00
if (!aSession) return NS_ERROR_INVALID_ARG;
// "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;
NS_ADDREF(*aSession); // addRef because we're a "getter"
1999-05-07 23:51:50 +04:00
} else
*aSession = nullptr;
1999-05-07 23:51:50 +04:00
return NS_OK;
}
//-------------------------------------------------------------------------
NS_IMETHODIMP
nsBaseDragService::StartDragSession() {
1999-05-07 23:51:50 +04:00
if (mDoingDrag) {
return NS_ERROR_FAILURE;
}
mDoingDrag = true;
// By default dispatch drop also to content.
mOnlyChromeDrop = false;
1999-05-07 23:51:50 +04:00
return NS_OK;
}
void nsBaseDragService::OpenDragPopup() {
if (mDragPopup) {
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
if (pm) {
pm->ShowPopupAtScreen(mDragPopup, mScreenPosition.x - mImageOffset.x,
mScreenPosition.y - mImageOffset.y, false, nullptr);
}
}
}
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
//-------------------------------------------------------------------------
NS_IMETHODIMP
nsBaseDragService::EndDragSession(bool aDoneDrag, uint32_t aKeyModifiers) {
1999-05-07 23:51:50 +04:00
if (!mDoingDrag) {
return NS_ERROR_FAILURE;
}
if (aDoneDrag && !mSuppressLevel) {
FireDragEventAtSource(eDragEnd, aKeyModifiers);
}
if (mDragPopup) {
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
if (pm) {
pm->HidePopup(mDragPopup, false, true, false, false);
}
}
for (uint32_t i = 0; i < mChildProcesses.Length(); ++i) {
mozilla::Unused << mChildProcesses[i]->SendEndDragSession(
aDoneDrag, mUserCancelled, mEndDragPoint, aKeyModifiers);
// Continue sending input events with input priority when stopping the dnd
// session.
mChildProcesses[i]->SetInputPriorityEventEnabled(true);
}
mChildProcesses.Clear();
// 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();
}
mDoingDrag = false;
mCanDrop = false;
// release the source we've been holding on to.
mSourceDocument = nullptr;
mSourceNode = nullptr;
mTriggeringPrincipal = nullptr;
mSelection = nullptr;
mDataTransfer = nullptr;
mHasImage = false;
mUserCancelled = false;
mDragPopup = nullptr;
mImage = nullptr;
mImageOffset = CSSIntPoint();
mScreenPosition = CSSIntPoint();
mEndDragPoint = LayoutDeviceIntPoint(0, 0);
mInputSource = MouseEvent_Binding::MOZ_SOURCE_MOUSE;
mRegion = Nothing();
return NS_OK;
}
void nsBaseDragService::DiscardInternalTransferData() {
if (mDataTransfer && mSourceNode) {
MOZ_ASSERT(mDataTransfer);
DataTransferItemList* items = mDataTransfer->Items();
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();
}
}
}
}
NS_IMETHODIMP
nsBaseDragService::FireDragEventAtSource(EventMessage aEventMessage,
uint32_t aKeyModifiers) {
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);
}
}
nsCOMPtr<nsIContent> content = do_QueryInterface(mSourceNode);
return presShell->HandleDOMEventWithTarget(content, &event, &status);
}
}
return NS_OK;
}
/* 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
nsBaseDragService::DragMoved(int32_t aX, int32_t aY) {
if (mDragPopup) {
nsIFrame* frame = mDragPopup->GetPrimaryFrame();
if (frame && frame->IsMenuPopupFrame()) {
CSSIntPoint cssPos =
RoundedToInt(LayoutDeviceIntPoint(aX, aY) /
frame->PresContext()->CSSToDevPixelScale()) -
mImageOffset;
(static_cast<nsMenuPopupFrame*>(frame))->MoveTo(cssPos, true);
}
}
return NS_OK;
}
static nsIPresShell* GetPresShellForContent(nsINode* aDOMNode) {
nsCOMPtr<nsIContent> content = do_QueryInterface(aDOMNode);
if (!content) return nullptr;
RefPtr<Document> document = content->GetComposedDoc();
if (document) {
document->FlushPendingNotifications(FlushType::Display);
return document->GetShell();
}
return nullptr;
}
nsresult nsBaseDragService::DrawDrag(nsINode* aDOMNode,
const Maybe<CSSIntRegion>& aRegion,
CSSIntPoint aScreenPosition,
LayoutDeviceIntRect* aScreenDragRect,
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 08:24:48 +03:00
RefPtr<SourceSurface>* aSurface,
nsPresContext** aPresContext) {
*aSurface = nullptr;
*aPresContext = nullptr;
// use a default size, in case of an error.
aScreenDragRect->SetRect(aScreenPosition.x - mImageOffset.x,
aScreenPosition.y - mImageOffset.y, 1, 1);
// if a drag image was specified, use that, otherwise, use the source node
nsCOMPtr<nsINode> 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;
*aPresContext = presShell->GetPresContext();
nsCOMPtr<nsIFrameLoaderOwner> flo = do_QueryInterface(dragNode);
if (flo) {
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 08:24:48 +03:00
RefPtr<nsFrameLoader> fl = flo->GetFrameLoader();
if (fl) {
auto* tp = static_cast<mozilla::dom::TabParent*>(fl->GetRemoteBrowser());
if (tp && tp->TakeDragVisualization(*aSurface, aScreenDragRect)) {
if (mImage) {
// Just clear the surface if chrome has overridden it with an image.
*aSurface = nullptr;
}
return NS_OK;
}
}
}
// convert mouse position to dev pixels of the prescontext
CSSIntPoint screenPosition(aScreenPosition);
screenPosition.x -= mImageOffset.x;
screenPosition.y -= mImageOffset.y;
LayoutDeviceIntPoint screenPoint =
ConvertToUnscaledDevPixels(*aPresContext, screenPosition);
aScreenDragRect->MoveTo(screenPoint.x, screenPoint.y);
// check if drag images are disabled
bool enableDragImages = Preferences::GetBool(DRAGIMAGES_PREF, true);
// didn't want an image, so just set the screen rectangle to the frame size
if (!enableDragImages || !mHasImage) {
// if a region was specified, set the screen rectangle to the area that
// the region occupies
CSSIntRect dragRect;
if (aRegion) {
// the region's coordinates are relative to the root frame
dragRect = aRegion->GetBounds();
nsIFrame* rootFrame = presShell->GetRootFrame();
CSSIntRect screenRect = rootFrame->GetScreenRect();
dragRect.MoveBy(screenRect.TopLeft());
} 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);
nsIFrame* frame = content->GetPrimaryFrame();
if (frame) {
dragRect = frame->GetScreenRect();
}
}
nsIntRect dragRectDev =
ToAppUnits(dragRect, AppUnitsPerCSSPixel())
.ToOutsidePixels((*aPresContext)->AppUnitsPerDevPixel());
aScreenDragRect->SizeTo(dragRectDev.Width(), dragRectDev.Height());
return NS_OK;
}
// draw the image for selections
if (mSelection) {
LayoutDeviceIntPoint pnt(aScreenDragRect->TopLeft());
*aSurface = presShell->RenderSelection(
mSelection, pnt, aScreenDragRect,
mImage ? 0 : nsIPresShell::RENDER_AUTO_SCALE);
return NS_OK;
}
// if a custom image was specified, check if it is an image node and draw
// using the source rather than the displayed image. But if mImage isn't
// an image or canvas, fall through to RenderNode below.
if (mImage) {
nsCOMPtr<nsIContent> content = do_QueryInterface(dragNode);
HTMLCanvasElement* canvas = HTMLCanvasElement::FromNodeOrNull(content);
if (canvas) {
return DrawDragForImage(*aPresContext, nullptr, canvas, aScreenDragRect,
aSurface);
}
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(dragNode);
// for image nodes, create the drag image from the actual image data
if (imageLoader) {
return DrawDragForImage(*aPresContext, imageLoader, nullptr,
aScreenDragRect, aSurface);
}
// 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->IsMenuPopupFrame()) {
mDragPopup = content;
}
}
if (!mDragPopup) {
// otherwise, just draw the node
uint32_t renderFlags = mImage ? 0 : nsIPresShell::RENDER_AUTO_SCALE;
if (renderFlags) {
// check if the dragged node itself is an img element
if (dragNode->NodeName().LowerCaseEqualsLiteral("img")) {
renderFlags = renderFlags | nsIPresShell::RENDER_IS_IMAGE;
} else {
nsINodeList* childList = dragNode->ChildNodes();
uint32_t length = childList->Length();
// check every childnode for being an img element
// 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")) {
// if the dragnode contains an image, set RENDER_IS_IMAGE flag
renderFlags = renderFlags | nsIPresShell::RENDER_IS_IMAGE;
break;
}
}
}
}
LayoutDeviceIntPoint pnt(aScreenDragRect->TopLeft());
*aSurface = presShell->RenderNode(dragNode, aRegion, pnt, aScreenDragRect,
renderFlags);
}
// If an image was specified, reset the position from the offset that was
// supplied.
if (mImage) {
aScreenDragRect->MoveTo(screenPoint.x, screenPoint.y);
}
1999-05-07 23:51:50 +04:00
return NS_OK;
}
nsresult nsBaseDragService::DrawDragForImage(
nsPresContext* aPresContext, nsIImageLoadingContent* aImageLoader,
HTMLCanvasElement* aCanvas, LayoutDeviceIntRect* aScreenDragRect,
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 08:24:48 +03:00
RefPtr<SourceSurface>* aSurface) {
nsCOMPtr<imgIContainer> imgContainer;
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
int32_t imageWidth, imageHeight;
rv = imgContainer->GetWidth(&imageWidth);
NS_ENSURE_SUCCESS(rv, rv);
rv = imgContainer->GetHeight(&imageHeight);
NS_ENSURE_SUCCESS(rv, rv);
aScreenDragRect->SizeTo(aPresContext->CSSPixelsToDevPixels(imageWidth),
aPresContext->CSSPixelsToDevPixels(imageHeight));
} else {
// XXX The canvas size should be converted to dev pixels.
NS_ASSERTION(aCanvas, "both image and canvas are null");
nsIntSize sz = aCanvas->GetSize();
aScreenDragRect->SizeTo(sz.width, sz.height);
}
nsIntSize destSize;
destSize.width = aScreenDragRect->Width();
destSize.height = aScreenDragRect->Height();
if (destSize.width == 0 || destSize.height == 0) return NS_ERROR_FAILURE;
nsresult result = NS_OK;
if (aImageLoader) {
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 08:24:48 +03:00
RefPtr<DrawTarget> dt =
gfxPlatform::GetPlatform()->CreateOffscreenContentDrawTarget(
destSize, SurfaceFormat::B8G8R8A8);
if (!dt || !dt->IsValid()) return NS_ERROR_FAILURE;
RefPtr<gfxContext> ctx = gfxContext::CreateOrNull(dt);
if (!ctx) return NS_ERROR_FAILURE;
ImgDrawResult res =
imgContainer->Draw(ctx, destSize, ImageRegion::Create(destSize),
imgIContainer::FRAME_CURRENT, SamplingFilter::GOOD,
/* no SVGImageContext */ Nothing(),
imgIContainer::FLAG_SYNC_DECODE, 1.0);
if (res == ImgDrawResult::BAD_IMAGE || res == ImgDrawResult::BAD_ARGS ||
res == ImgDrawResult::NOT_SUPPORTED) {
return NS_ERROR_FAILURE;
}
*aSurface = dt->Snapshot();
} else {
*aSurface = aCanvas->GetSurfaceSnapshot();
}
return result;
}
LayoutDeviceIntPoint nsBaseDragService::ConvertToUnscaledDevPixels(
nsPresContext* aPresContext, CSSIntPoint aScreenPosition) {
int32_t adj =
aPresContext->DeviceContext()->AppUnitsPerDevPixelAtUnitFullZoom();
return LayoutDeviceIntPoint(
nsPresContext::CSSPixelsToAppUnits(aScreenPosition.x) / adj,
nsPresContext::CSSPixelsToAppUnits(aScreenPosition.y) / adj);
}
2008-03-19 03:06:22 +03:00
NS_IMETHODIMP
nsBaseDragService::Suppress() {
EndDragSession(false, 0);
2008-03-19 03:06:22 +03:00
++mSuppressLevel;
return NS_OK;
}
NS_IMETHODIMP
nsBaseDragService::Unsuppress() {
--mSuppressLevel;
return NS_OK;
}
NS_IMETHODIMP
nsBaseDragService::UserCancelled() {
mUserCancelled = true;
return NS_OK;
}
NS_IMETHODIMP
nsBaseDragService::UpdateDragEffect() {
mDragActionFromChildProcess = mDragAction;
return NS_OK;
}
NS_IMETHODIMP
nsBaseDragService::UpdateDragImage(nsINode* aImage, int32_t aImageX,
int32_t aImageY) {
// 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;
}
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;
}