diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 00288e370c1b..38044f825d01 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -6034,15 +6034,9 @@ nsContentUtils::SetDataTransferInEvent(WidgetDragEvent* aDragEvent) nsCOMPtr dragSession = GetDragSession(); NS_ENSURE_TRUE(dragSession, NS_OK); // no drag in progress - nsCOMPtr dataTransfer; - nsCOMPtr initialDataTransfer; - dragSession->GetDataTransfer(getter_AddRefs(dataTransfer)); - if (dataTransfer) { - initialDataTransfer = do_QueryInterface(dataTransfer); - if (!initialDataTransfer) { - return NS_ERROR_FAILURE; - } - } else { + RefPtr initialDataTransfer = + dragSession->GetDataTransfer(); + if (!initialDataTransfer) { // A dataTransfer won't exist when a drag was started by some other // means, for instance calling the drag service directly, or a drag // from another application. In either case, a new dataTransfer should diff --git a/dom/events/DataTransfer.cpp b/dom/events/DataTransfer.cpp index cce3b3355c33..dedcafc7bef0 100644 --- a/dom/events/DataTransfer.cpp +++ b/dom/events/DataTransfer.cpp @@ -483,22 +483,11 @@ DataTransfer::ClearData(const Optional& aFormat, } } -NS_IMETHODIMP -DataTransfer::GetMozCursor(nsAString& aCursorState) -{ - nsString cursor; - GetMozCursor(cursor); - aCursorState = cursor; - return NS_OK; -} - -NS_IMETHODIMP +void DataTransfer::SetMozCursor(const nsAString& aCursorState) { // Lock the cursor to an arrow during the drag. mCursorState = aCursorState.EqualsLiteral("default"); - - return NS_OK; } already_AddRefed diff --git a/dom/events/DataTransfer.h b/dom/events/DataTransfer.h index 62ffcf6bd66d..1d4bb346338c 100644 --- a/dom/events/DataTransfer.h +++ b/dom/events/DataTransfer.h @@ -205,7 +205,7 @@ public: uint32_t MozItemCount() const; - void GetMozCursor(nsString& aCursor) + void GetMozCursor(nsAString& aCursor) { if (mCursorState) { aCursor.AssignLiteral("default"); @@ -213,6 +213,7 @@ public: aCursor.AssignLiteral("auto"); } } + void SetMozCursor(const nsAString& aCursor); already_AddRefed MozTypesAt(uint32_t aIndex, CallerType aCallerType, diff --git a/dom/events/EventStateManager.cpp b/dom/events/EventStateManager.cpp index 80ff5e806b05..1271d61bd361 100644 --- a/dom/events/EventStateManager.cpp +++ b/dom/events/EventStateManager.cpp @@ -1337,8 +1337,7 @@ EventStateManager::DispatchCrossProcessEvent(WidgetEvent* aEvent, dragSession->DragEventDispatchedToChildProcess(); dragSession->GetDragAction(&action); dragSession->GetTriggeringPrincipalURISpec(principalURISpec); - nsCOMPtr initialDataTransfer; - dragSession->GetDataTransfer(getter_AddRefs(initialDataTransfer)); + RefPtr initialDataTransfer = dragSession->GetDataTransfer(); if (initialDataTransfer) { initialDataTransfer->GetDropEffectInt(&dropEffect); } @@ -3534,8 +3533,7 @@ EventStateManager::PostHandleEvent(nsPresContext* aPresContext, // the initial dataTransfer is the one from the dragstart event that // was set on the dragSession when the drag began. nsCOMPtr dataTransfer; - nsCOMPtr initialDataTransfer; - dragSession->GetDataTransfer(getter_AddRefs(initialDataTransfer)); + RefPtr initialDataTransfer = dragSession->GetDataTransfer(); WidgetDragEvent *dragEvent = aEvent->AsDragEvent(); @@ -4781,8 +4779,7 @@ EventStateManager::UpdateDragDataTransfer(WidgetDragEvent* dragEvent) if (dragSession) { // the initial dataTransfer is the one from the dragstart event that // was set on the dragSession when the drag began. - nsCOMPtr initialDataTransfer; - dragSession->GetDataTransfer(getter_AddRefs(initialDataTransfer)); + RefPtr initialDataTransfer = dragSession->GetDataTransfer(); if (initialDataTransfer) { // retrieve the current moz cursor setting and save it. nsAutoString mozCursor; diff --git a/dom/interfaces/events/nsIDOMDataTransfer.idl b/dom/interfaces/events/nsIDOMDataTransfer.idl index 82ac58d5734e..3eafea7284df 100644 --- a/dom/interfaces/events/nsIDOMDataTransfer.idl +++ b/dom/interfaces/events/nsIDOMDataTransfer.idl @@ -68,20 +68,6 @@ interface nsIDOMDataTransfer : nsISupports */ void addElement(in nsIDOMElement element); - /** - * Sets the drag cursor state. Primarily used to control the cursor during - * tab drags, but could be expanded to other uses. XXX Currently implemented - * on Win32 only. - * - * Possible values: - * auto - use default system behavior. - * default - set the cursor to an arrow during the drag operation. - * - * Values other than 'default' are indentical to setting mozCursor to - * 'auto'. - */ - attribute DOMString mozCursor; - /** * Will be true when the user has cancelled the drag (typically by pressing * Escape) and when the drag has been cancelled unexpectedly. This will be diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index 4b432f892af1..e361eb7b7a54 100644 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -4512,9 +4512,7 @@ ContentParent::MaybeInvokeDragSession(TabParent* aParent) dragService->GetCurrentSession(getter_AddRefs(session)); if (session) { nsTArray dataTransfers; - nsCOMPtr domTransfer; - session->GetDataTransfer(getter_AddRefs(domTransfer)); - nsCOMPtr transfer = do_QueryInterface(domTransfer); + RefPtr transfer = session->GetDataTransfer(); if (!transfer) { // Pass eDrop to get DataTransfer with external // drag formats cached. @@ -4548,8 +4546,7 @@ ContentParent::RecvUpdateDropEffect(const uint32_t& aDragAction, nsCOMPtr dragSession = nsContentUtils::GetDragSession(); if (dragSession) { dragSession->SetDragAction(aDragAction); - nsCOMPtr dt; - dragSession->GetDataTransfer(getter_AddRefs(dt)); + RefPtr dt = dragSession->GetDataTransfer(); if (dt) { dt->SetDropEffectInt(aDropEffect); } diff --git a/dom/ipc/TabChild.cpp b/dom/ipc/TabChild.cpp index 50725636d280..9d5e81bea3d1 100644 --- a/dom/ipc/TabChild.cpp +++ b/dom/ipc/TabChild.cpp @@ -19,6 +19,7 @@ #include "mozilla/BrowserElementParent.h" #include "mozilla/ClearOnShutdown.h" #include "mozilla/EventListenerManager.h" +#include "mozilla/dom/DataTransfer.h" #include "mozilla/dom/indexedDB/PIndexedDBPermissionRequestChild.h" #include "mozilla/dom/PaymentRequestChild.h" #include "mozilla/dom/TelemetryScrollProbe.h" @@ -1955,8 +1956,7 @@ TabChild::RecvRealDragEvent(const WidgetDragEvent& aEvent, if (dragSession) { dragSession->SetDragAction(aDragAction); dragSession->SetTriggeringPrincipalURISpec(aPrincipalURISpec); - nsCOMPtr initialDataTransfer; - dragSession->GetDataTransfer(getter_AddRefs(initialDataTransfer)); + RefPtr initialDataTransfer = dragSession->GetDataTransfer(); if (initialDataTransfer) { initialDataTransfer->SetDropEffectInt(aDropEffect); } diff --git a/dom/ipc/TabParent.cpp b/dom/ipc/TabParent.cpp index d4e3d11ea2e9..65b2c6ab33fd 100644 --- a/dom/ipc/TabParent.cpp +++ b/dom/ipc/TabParent.cpp @@ -1179,8 +1179,7 @@ TabParent::QueryDropLinksForVerification() return false; } - nsCOMPtr initialDataTransfer; - dragSession->GetDataTransfer(getter_AddRefs(initialDataTransfer)); + RefPtr initialDataTransfer = dragSession->GetDataTransfer(); if (!initialDataTransfer) { NS_WARNING("No initialDataTransfer to query links for verification"); return false; diff --git a/widget/cocoa/nsChildView.mm b/widget/cocoa/nsChildView.mm index fd55ccba3e50..9d8a117dcc85 100644 --- a/widget/cocoa/nsChildView.mm +++ b/widget/cocoa/nsChildView.mm @@ -17,6 +17,7 @@ #include "mozilla/MouseEvents.h" #include "mozilla/TextEvents.h" #include "mozilla/TouchEvents.h" +#include "mozilla/dom/DataTransfer.h" #include "mozilla/dom/SimpleGestureEventBinding.h" #include "nsArrayUtils.h" @@ -6260,10 +6261,10 @@ GetIntegerDeltaForEvent(NSEvent* aEvent) // value for NSDragOperationGeneric that is passed by other applications. // All that said, NSDragOperationNone is still reliable. if (aOperation == NSDragOperationNone) { - nsCOMPtr dataTransfer; - dragService->GetDataTransfer(getter_AddRefs(dataTransfer)); - if (dataTransfer) + RefPtr dataTransfer = dragService->GetDataTransfer(); + if (dataTransfer) { dataTransfer->SetDropEffectInt(nsIDragService::DRAGDROP_ACTION_NONE); + } } mDragService->EndDragSession( diff --git a/widget/nsBaseDragService.cpp b/widget/nsBaseDragService.cpp index 727b975895ef..e730c407f897 100644 --- a/widget/nsBaseDragService.cpp +++ b/widget/nsBaseDragService.cpp @@ -23,7 +23,6 @@ #include "nsISelection.h" #include "nsISelectionPrivate.h" #include "nsPresContext.h" -#include "nsIDOMDataTransfer.h" #include "nsIImageLoadingContent.h" #include "imgIContainer.h" #include "imgIRequest.h" @@ -35,6 +34,7 @@ #include "mozilla/MouseEvents.h" #include "mozilla/Preferences.h" #include "mozilla/dom/DataTransferItemList.h" +#include "mozilla/dom/DataTransfer.h" #include "mozilla/gfx/2D.h" #include "mozilla/Unused.h" #include "nsFrameLoader.h" @@ -201,7 +201,7 @@ nsBaseDragService::IsDataFlavorSupported(const char *aDataFlavor, } NS_IMETHODIMP -nsBaseDragService::GetDataTransfer(nsIDOMDataTransfer** aDataTransfer) +nsBaseDragService::GetDataTransferXPCOM(nsIDOMDataTransfer** aDataTransfer) { *aDataTransfer = mDataTransfer; NS_IF_ADDREF(*aDataTransfer); @@ -209,10 +209,23 @@ nsBaseDragService::GetDataTransfer(nsIDOMDataTransfer** aDataTransfer) } NS_IMETHODIMP -nsBaseDragService::SetDataTransfer(nsIDOMDataTransfer* aDataTransfer) +nsBaseDragService::SetDataTransferXPCOM(nsIDOMDataTransfer* aDataTransfer) +{ + // Cast is safe because nsIDOMDataTransfer is builtinclass. + mDataTransfer = static_cast(aDataTransfer); + return NS_OK; +} + +DataTransfer* +nsBaseDragService::GetDataTransfer() +{ + return mDataTransfer; +} + +void +nsBaseDragService::SetDataTransfer(DataTransfer* aDataTransfer) { mDataTransfer = aDataTransfer; - return NS_OK; } //------------------------------------------------------------------------- @@ -271,7 +284,8 @@ nsBaseDragService::InvokeDragSessionWithImage(nsIDOMNode* aDOMNode, NS_ENSURE_TRUE(aDataTransfer, NS_ERROR_NULL_POINTER); NS_ENSURE_TRUE(mSuppressLevel == 0, NS_ERROR_FAILURE); - mDataTransfer = aDataTransfer; + // Cast is safe because nsIDOMDataTransfer is builtinclass. + mDataTransfer = static_cast(aDataTransfer); mSelection = nullptr; mHasImage = true; mDragPopup = nullptr; @@ -308,7 +322,8 @@ nsBaseDragService::InvokeDragSessionWithSelection(nsISelection* aSelection, NS_ENSURE_TRUE(aDragEvent, NS_ERROR_NULL_POINTER); NS_ENSURE_TRUE(mSuppressLevel == 0, NS_ERROR_FAILURE); - mDataTransfer = aDataTransfer; + // Cast is safe because nsIDOMDataTransfer is builtinclass. + mDataTransfer = static_cast(aDataTransfer); mSelection = aSelection; mHasImage = true; mDragPopup = nullptr; diff --git a/widget/nsBaseDragService.h b/widget/nsBaseDragService.h index 3ba847c9be2b..4a578c2ee7d2 100644 --- a/widget/nsBaseDragService.h +++ b/widget/nsBaseDragService.h @@ -10,7 +10,6 @@ #include "nsIDragSession.h" #include "nsITransferable.h" #include "nsIDOMDocument.h" -#include "nsIDOMDataTransfer.h" #include "nsCOMPtr.h" #include "nsRect.h" #include "nsPoint.h" @@ -33,6 +32,10 @@ namespace mozilla { namespace gfx { class SourceSurface; } // namespace gfx + +namespace dom { +class DataTransfer; +} // namespace dom } // namespace mozilla /** @@ -165,7 +168,7 @@ protected: // if it came from outside the app. nsContentPolicyType mContentPolicyType; // the contentpolicy type passed to the channel // when initiating the drag session - nsCOMPtr mDataTransfer; + RefPtr mDataTransfer; // used to determine the image to appear on the cursor while dragging nsCOMPtr mImage; diff --git a/widget/nsIDragSession.idl b/widget/nsIDragSession.idl index 316736fa4b2e..47c57093568c 100644 --- a/widget/nsIDragSession.idl +++ b/widget/nsIDragSession.idl @@ -10,16 +10,22 @@ %{ C++ #include "nsSize.h" + +namespace mozilla { +namespace dom { +class DataTransfer; +} // namespace dom +} // namespace mozilla %} native nsSize (nsSize); - +[ptr] native DataTransferPtr(mozilla::dom::DataTransfer); interface nsIDOMDocument; interface nsIDOMNode; interface nsIDOMDataTransfer; -[scriptable, uuid(25bce737-73f0-43c7-bc20-c71044a73c5a)] +[scriptable, builtinclass, uuid(25bce737-73f0-43c7-bc20-c71044a73c5a)] interface nsIDragSession : nsISupports { /** @@ -72,7 +78,10 @@ interface nsIDragSession : nsISupports /** * The data transfer object for the current drag. */ + [binaryname(DataTransferXPCOM)] attribute nsIDOMDataTransfer dataTransfer; + [notxpcom, nostdcall] DataTransferPtr getDataTransfer(); + [notxpcom, nostdcall] void setDataTransfer(in DataTransferPtr aDataTransfer); /** * Get data from a Drag&Drop. Can be called while the drag is in process diff --git a/widget/windows/nsNativeDragSource.cpp b/widget/windows/nsNativeDragSource.cpp index 857907076703..380a3077cd91 100644 --- a/widget/windows/nsNativeDragSource.cpp +++ b/widget/windows/nsNativeDragSource.cpp @@ -15,12 +15,12 @@ /* * class nsNativeDragSource */ -nsNativeDragSource::nsNativeDragSource(nsIDOMDataTransfer* aDataTransfer) : +nsNativeDragSource::nsNativeDragSource(mozilla::dom::DataTransfer* aDataTransfer) : m_cRef(0), m_hCursor(nullptr), mUserCancelled(false) { - mDataTransfer = do_QueryInterface(aDataTransfer); + mDataTransfer = aDataTransfer; } nsNativeDragSource::~nsNativeDragSource() diff --git a/widget/windows/nsNativeDragSource.h b/widget/windows/nsNativeDragSource.h index 9172291fb129..9784c4e09306 100644 --- a/widget/windows/nsNativeDragSource.h +++ b/widget/windows/nsNativeDragSource.h @@ -7,10 +7,16 @@ #include "nscore.h" #include "nsIDOMDataTransfer.h" -#include "nsCOMPtr.h" #include #include #include "mozilla/Attributes.h" +#inclide "mozilla/RefPtr.h" + +namespace mozilla { +namespace dom { +class DataTransfer; +} // namespace dom +} // namespace mozilla //class nsIDragSource; @@ -24,7 +30,7 @@ public: // construct an nsNativeDragSource referencing adapter // nsNativeDragSource(nsIDragSource * adapter); - explicit nsNativeDragSource(nsIDOMDataTransfer* aDataTransfer); + explicit nsNativeDragSource(mozilla::dom::DataTransfer* aDataTransfer); ~nsNativeDragSource(); // IUnknown methods - see iunknown.h for documentation @@ -53,7 +59,7 @@ protected: ULONG m_cRef; // Data object, hold information about cursor state - nsCOMPtr mDataTransfer; + RefPtr mDataTransfer; // Custom drag cursor HCURSOR m_hCursor;