gecko-dev/widget/nsBaseDragService.h

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

217 строки
6.7 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:22 +04:00
#ifndef nsBaseDragService_h__
#define nsBaseDragService_h__
#include "nsIDragService.h"
1999-05-07 23:51:50 +04:00
#include "nsIDragSession.h"
#include "nsCOMPtr.h"
#include "nsRect.h"
#include "nsPoint.h"
#include "nsString.h"
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
#include "mozilla/RefPtr.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/HTMLCanvasElement.h"
#include "mozilla/dom/RemoteDragStartData.h"
#include "nsTArray.h"
#include "nsRegion.h"
#include "Units.h"
// translucency level for drag images
#define DRAG_TRANSLUCENCY 0.65
class nsIContent;
class nsINode;
class nsPresContext;
class nsIImageLoadingContent;
namespace mozilla {
namespace gfx {
class SourceSurface;
} // namespace gfx
namespace dom {
class DataTransfer;
class Selection;
} // namespace dom
} // namespace mozilla
1999-04-17 01:03:22 +04:00
/**
* XP DragService wrapper base class
*/
class nsBaseDragService : public nsIDragService, public nsIDragSession {
1999-04-17 01:03:22 +04:00
public:
typedef mozilla::gfx::SourceSurface SourceSurface;
1999-04-17 01:03:22 +04:00
nsBaseDragService();
// nsISupports
NS_DECL_ISUPPORTS
1999-09-05 06:28:38 +04:00
// nsIDragSession and nsIDragService
NS_DECL_NSIDRAGSERVICE
NS_DECL_NSIDRAGSESSION
1999-04-17 01:03:22 +04:00
void SetDragEndPoint(nsIntPoint aEndDragPoint) {
mEndDragPoint =
mozilla::LayoutDeviceIntPoint::FromUnknownPoint(aEndDragPoint);
}
void SetDragEndPoint(mozilla::LayoutDeviceIntPoint aEndDragPoint) {
mEndDragPoint = aEndDragPoint;
}
uint16_t GetInputSource() { return mInputSource; }
int32_t TakeChildProcessDragAction();
1999-04-17 01:03:22 +04:00
protected:
virtual ~nsBaseDragService();
1999-04-17 01:03:22 +04:00
/**
* Called from nsBaseDragService to initiate a platform drag from a source
* in this process. This is expected to ensure that StartDragSession() and
* EndDragSession() get called if the platform drag is successfully invoked.
*/
MOZ_CAN_RUN_SCRIPT virtual nsresult InvokeDragSessionImpl(
nsIArray* aTransferableArray,
const mozilla::Maybe<mozilla::CSSIntRegion>& aRegion,
uint32_t aActionType) = 0;
/**
* Draw the drag image, if any, to a surface and return it. The drag image
* is constructed from mImage if specified, or aDOMNode if mImage is null.
*
* aRegion may be used to draw only a subset of the element. This region
* should be supplied using x and y coordinates measured in css pixels
* that are relative to the upper-left corner of the window.
*
* aScreenPosition should be the screen coordinates of the mouse click
* for the drag. These are in CSS pixels.
*
* On return, aScreenDragRect will contain the screen coordinates of the
* area being dragged. This is used by the platform-specific part of the
* drag service to determine the drag feedback. This rect will be in the
* device pixels of the presContext.
*
* If there is no drag image, the returned surface will be null, but
* aScreenDragRect will still be set to the drag area.
*
* aPresContext will be set to the nsPresContext used determined from
* whichever of mImage or aDOMNode is used.
*/
nsresult DrawDrag(nsINode* aDOMNode,
const mozilla::Maybe<mozilla::CSSIntRegion>& aRegion,
mozilla::CSSIntPoint aScreenPosition,
mozilla::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);
/**
* Draw a drag image for an image node specified by aImageLoader or aCanvas.
* This is called by DrawDrag.
*/
nsresult DrawDragForImage(nsPresContext* aPresContext,
nsIImageLoadingContent* aImageLoader,
mozilla::dom::HTMLCanvasElement* aCanvas,
mozilla::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);
/**
* Convert aScreenPosition from CSS pixels into unscaled device pixels.
*/
mozilla::LayoutDeviceIntPoint ConvertToUnscaledDevPixels(
nsPresContext* aPresContext, mozilla::CSSIntPoint aScreenPosition);
/**
* If the drag image is a popup, open the popup when the drag begins.
*/
void OpenDragPopup();
/**
* Free resources contained in DataTransferItems that aren't needed by JS.
*/
void DiscardInternalTransferData();
// Returns true if a drag event was dispatched to a child process after
// the previous TakeDragEventDispatchedToChildProcess() call.
bool TakeDragEventDispatchedToChildProcess() {
bool retval = mDragEventDispatchedToChildProcess;
mDragEventDispatchedToChildProcess = false;
return retval;
}
bool mCanDrop;
bool mOnlyChromeDrop;
bool mDoingDrag;
Bug 1603074 - part 1: Make `synthesizePlainDragAndDrop()` synthesize drag events without `DataTransfer` object r=smaug `synthesizePlainDragAndDrop()` synthesizes drag events with `DataTransfer` object which is set to `DragEvent.dataTransfer` of `dragstart` after starting drag session explicitly. However, this causes `EventStateManager::DoDefaltDragStart()` does not initialize `nsIDragService` instance. Therefore, synthesized drag events cannot work with editor because `DragEvent::GetMozSourceNode()` returns `nullptr` due to `nsIDragSession::GetSourceNode()` returning `nullptr`. On the other hand, synthesized drag events cannot use `nsIDragService::InvodeDragSession()` normally because of hitting an assertion. https://searchfox.org/mozilla-central/rev/690e903ef689a4eca335b96bd903580394864a1c/widget/nsBaseDragService.cpp#230-233 This patch does: - mark drag events caused by synthesized mouse events as "synthesized for tests" - make `synthesizePlainDragAndDrop()` stop using `nsIDragService.startDragSession()` - make `nsBaseDragService` initialize and start session even for synthesized `dragstart` event - make `synthesizePlainDragAndDrop()` stop synthesizing drag events with `DataTransfer` object since it's normal behavior and it'll be initialized with `nsIDragService::GetDataTransfer()` - make `nsBaseDragService` store `effectAllowed` for the session only when it's synthesized session because it's required at initializing synthesized default `dropEffect` value of `dragenter`, `dragover`, `dragexit` and `drop` events' `dataTransfer` - make all tests which use `nsIDragService.startDragSession()` use new API, `nsIDragService.startDragSessionForTests()` to initialize session's `effectAllowed` value - make `EventStateManager::PostHandleEvent()` set drag end point of the test session to `eDrop` event's screen point - make `synthesizePlainDragAndDrop()` set drag end point of the session if it does not synthesize `drop` event because following `endDragSession()` use it at dispatching `dragend` event on the source element Additionally, this adds `dumpFunc` new param to `synthesizePlainDragAndDrop()` because it's really useful to investigate the reason why requesting DnD isn't performed as expected. Differential Revision: https://phabricator.services.mozilla.com/D57425 --HG-- extra : moz-landing-system : lando
2019-12-21 15:27:06 +03:00
bool mSessionIsSynthesizedForTests;
// true if in EndDragSession
bool mEndingSession;
// true if mImage should be used to set a drag image
bool mHasImage;
// true if the user cancelled the drag operation
bool mUserCancelled;
bool mDragEventDispatchedToChildProcess;
uint32_t mDragAction;
uint32_t mDragActionFromChildProcess;
Bug 1603074 - part 1: Make `synthesizePlainDragAndDrop()` synthesize drag events without `DataTransfer` object r=smaug `synthesizePlainDragAndDrop()` synthesizes drag events with `DataTransfer` object which is set to `DragEvent.dataTransfer` of `dragstart` after starting drag session explicitly. However, this causes `EventStateManager::DoDefaltDragStart()` does not initialize `nsIDragService` instance. Therefore, synthesized drag events cannot work with editor because `DragEvent::GetMozSourceNode()` returns `nullptr` due to `nsIDragSession::GetSourceNode()` returning `nullptr`. On the other hand, synthesized drag events cannot use `nsIDragService::InvodeDragSession()` normally because of hitting an assertion. https://searchfox.org/mozilla-central/rev/690e903ef689a4eca335b96bd903580394864a1c/widget/nsBaseDragService.cpp#230-233 This patch does: - mark drag events caused by synthesized mouse events as "synthesized for tests" - make `synthesizePlainDragAndDrop()` stop using `nsIDragService.startDragSession()` - make `nsBaseDragService` initialize and start session even for synthesized `dragstart` event - make `synthesizePlainDragAndDrop()` stop synthesizing drag events with `DataTransfer` object since it's normal behavior and it'll be initialized with `nsIDragService::GetDataTransfer()` - make `nsBaseDragService` store `effectAllowed` for the session only when it's synthesized session because it's required at initializing synthesized default `dropEffect` value of `dragenter`, `dragover`, `dragexit` and `drop` events' `dataTransfer` - make all tests which use `nsIDragService.startDragSession()` use new API, `nsIDragService.startDragSessionForTests()` to initialize session's `effectAllowed` value - make `EventStateManager::PostHandleEvent()` set drag end point of the test session to `eDrop` event's screen point - make `synthesizePlainDragAndDrop()` set drag end point of the session if it does not synthesize `drop` event because following `endDragSession()` use it at dispatching `dragend` event on the source element Additionally, this adds `dumpFunc` new param to `synthesizePlainDragAndDrop()` because it's really useful to investigate the reason why requesting DnD isn't performed as expected. Differential Revision: https://phabricator.services.mozilla.com/D57425 --HG-- extra : moz-landing-system : lando
2019-12-21 15:27:06 +03:00
// mEffectAllowedForTests stores allowed effects at invoking the drag
// for tests.
uint32_t mEffectAllowedForTests;
nsCOMPtr<nsINode> mSourceNode;
nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
nsCOMPtr<nsIContentSecurityPolicy> mCsp;
// the document at the drag source. will be null if it came from outside the
// app.
RefPtr<mozilla::dom::Document> mSourceDocument;
// the contentpolicy type passed to the channel when initiating the drag
// session
nsContentPolicyType mContentPolicyType;
RefPtr<mozilla::dom::DataTransfer> mDataTransfer;
// used to determine the image to appear on the cursor while dragging
nsCOMPtr<nsINode> mImage;
// offset of cursor within the image
mozilla::CSSIntPoint mImageOffset;
// set if a selection is being dragged
RefPtr<mozilla::dom::Selection> mSelection;
// remote drag data
RefPtr<mozilla::dom::RemoteDragStartData> mDragStartData;
// set if the image in mImage is a popup. If this case, the popup will be
// opened and moved instead of using a drag image.
nsCOMPtr<nsIContent> mDragPopup;
// the screen position where drag gesture occurred, used for positioning the
// drag image.
mozilla::CSSIntPoint mScreenPosition;
2008-03-19 03:06:22 +03:00
// the screen position where the drag ended
mozilla::LayoutDeviceIntPoint mEndDragPoint;
uint32_t mSuppressLevel;
// The input source of the drag event. Possible values are from MouseEvent.
uint16_t mInputSource;
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
nsTArray<RefPtr<mozilla::dom::ContentParent>> mChildProcesses;
// Sub-region for tree-selections.
mozilla::Maybe<mozilla::CSSIntRegion> mRegion;
1999-04-17 01:03:22 +04:00
};
#endif // nsBaseDragService_h__