Bug 1893119: Part 22 - Make nsIDragService::StartDragSession return the nsIDragSession r=rkraesig,win-reviewers,gstoll,geckoview-reviewers,m_kato

Differential Revision: https://phabricator.services.mozilla.com/D212298
This commit is contained in:
David P 2024-07-04 07:48:12 +00:00
parent 7376694ac2
commit ce04c3bf58
10 changed files with 28 additions and 38 deletions

View File

@ -2701,12 +2701,9 @@ void nsWindow::OnDragEvent(int32_t aAction, int64_t aTime, float aX, float aY,
if (message == eDragEnter) {
nsIWidget* widget = this;
dragService->StartDragSession(widget);
// For compatibility, we have to set temporary data.
dragSession =
static_cast<nsDragSession*>(dragService->GetCurrentSession(this));
MOZ_ASSERT(dragSession);
static_cast<nsDragSession*>(dragService->StartDragSession(widget));
// For compatibility, we have to set temporary data.
auto dropData =
mozilla::java::GeckoDragAndDrop::DropData::Ref::From(aDropData);
dragSession->SetDropData(dropData);

View File

@ -4126,13 +4126,14 @@ static gfx::IntPoint GetIntegerDeltaForEvent(NSEvent* aEvent) {
if (!mDragService) return NSDragOperationNone;
}
nsCOMPtr<nsIDragSession> dragSession;
if (aMessage == eDragEnter) {
nsIWidget* widget = mGeckoChild;
mDragService->StartDragSession(widget);
dragSession = mDragService->StartDragSession(widget);
} else {
dragSession = mDragService->GetCurrentSession(mGeckoChild);
}
nsCOMPtr<nsIDragSession> dragSession =
mDragService->GetCurrentSession(mGeckoChild);
if (dragSession) {
if (aMessage == eDragOver) {
// fire the drag event at the source. Just ignore whether it was

View File

@ -901,8 +901,7 @@ bool nsDragSession::SetAlphaPixmap(SourceSurface* aSurface,
return true;
}
NS_IMETHODIMP
nsDragService::StartDragSession(nsISupports* aWidgetProvider) {
nsIDragSession* nsDragService::StartDragSession(nsISupports* aWidgetProvider) {
LOGDRAGSERVICE("nsDragService::StartDragSession");
return nsBaseDragService::StartDragSession(aWidgetProvider);
}

View File

@ -391,7 +391,7 @@ class nsDragSession : public nsBaseDragSession, public nsIObserver {
class nsDragService : public nsBaseDragService {
public:
static already_AddRefed<nsDragService> GetInstance();
NS_IMETHOD StartDragSession(nsISupports* aWidgetProvider) override;
nsIDragSession* StartDragSession(nsISupports* aWidgetProvider) override;
protected:
already_AddRefed<nsIDragSession> CreateDragSession() override;

View File

@ -8718,9 +8718,8 @@ gboolean WindowDragMotionHandler(GtkWidget* aWidget,
if (!dragSession) {
// This may be the start of an external drag session.
nsIWidget* widget = window;
static_cast<nsDragSession*>(dragService->StartDragSession(widget));
dragSession =
static_cast<nsDragSession*>(dragService->GetCurrentSession(window));
static_cast<nsDragSession*>(dragService->StartDragSession(widget));
}
NS_ENSURE_TRUE(dragSession, FALSE);

View File

@ -614,21 +614,18 @@ nsBaseDragService::GetCurrentSession(nsISupports* aWidgetProvider,
}
//-------------------------------------------------------------------------
NS_IMETHODIMP
nsBaseDragService::StartDragSession(nsISupports* aWidgetProvider) {
nsIDragSession* nsBaseDragService::StartDragSession(nsISupports* aWidgetProvider) {
MOZ_ASSERT(XRE_IsParentProcess());
if (!aWidgetProvider) {
return NS_ERROR_NULL_POINTER;
return nullptr;
}
if (mCurrentParentDragSession) {
return NS_ERROR_ALREADY_INITIALIZED;
return mCurrentParentDragSession;
}
RefPtr<nsIDragSession> session = CreateDragSession();
if (XRE_IsParentProcess()) {
mCurrentParentDragSession = session;
}
return NS_OK;
mCurrentParentDragSession = session;
return session;
}
NS_IMETHODIMP
@ -644,11 +641,7 @@ NS_IMETHODIMP nsBaseDragService::StartDragSessionForTests(
// This method must set mSessionIsSynthesizedForTests
MOZ_ASSERT(!mNeverAllowSessionIsSynthesizedForTests);
nsresult rv = StartDragSession(aWidgetProvider);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDragSession> session;
GetCurrentSession(aWidgetProvider, getter_AddRefs(session));
RefPtr<nsIDragSession> session = StartDragSession(aWidgetProvider);
MOZ_ASSERT(session);
session->InitForTests(aAllowedEffect);
return NS_OK;

View File

@ -118,23 +118,23 @@ nsresult nsDragSessionProxy::InvokeDragSessionImpl(
return NS_OK;
}
NS_IMETHODIMP
nsIDragSession*
nsDragServiceProxy::StartDragSession(nsISupports* aWidgetProvider) {
nsIWidget* widget = GetWidgetFromWidgetProvider(aWidgetProvider);
NS_ENSURE_TRUE(widget, NS_ERROR_INVALID_ARG);
NS_ENSURE_TRUE(widget, nullptr);
BrowserChild* targetBrowser = widget->GetOwningBrowserChild();
NS_ENSURE_TRUE(targetBrowser, NS_ERROR_INVALID_ARG);
NS_ENSURE_TRUE(targetBrowser, nullptr);
RefPtr<nsIDragSession> session = targetBrowser->GetDragSession();
if (session) {
// session already exists on the browser
return NS_OK;
return session;
}
session = CreateDragSession();
MOZ_ASSERT(session);
static_cast<nsDragSessionProxy*>(session.get())->SetDragTarget(targetBrowser);
targetBrowser->SetDragSession(session);
return NS_OK;
return session;
}
NS_IMETHODIMP

View File

@ -45,7 +45,7 @@ class nsDragServiceProxy : public nsBaseDragService {
already_AddRefed<nsIDragSession> CreateDragSession() override;
NS_IMETHOD StartDragSession(nsISupports* aWidgetProvider) override;
nsIDragSession* StartDragSession(nsISupports* aWidgetProvider) override;
NS_IMETHOD GetCurrentSession(nsISupports* aWidgetProvider,
nsIDragSession** aSession) override;

View File

@ -143,9 +143,10 @@ interface nsIDragService : nsISupports
* @param aWidgetProvider Either the nsIWidget that will be the target of
* the drag, or an nsIDOMWindowProxy for a
* window that is on that widget.
* @returns the new (or pre-existing) session
*/
[noscript]
void startDragSession(in nsISupports aWidgetProvider);
[notxpcom, nostdcall]
nsIDragSession startDragSession(in nsISupports aWidgetProvider);
/**
* Similar to startDragSession(), automated tests may want to start

View File

@ -249,7 +249,9 @@ nsNativeDragTarget::DragEnter(LPDATAOBJECT pIDataSource, DWORD grfKeyState,
// tell the drag service about this drag (it may have come from an
// outside app).
mDragService->StartDragSession(mWidget);
RefPtr<nsDragSession> session =
static_cast<nsDragSession*>(mDragService->StartDragSession(mWidget));
MOZ_ASSERT(session);
void* tempOutData = nullptr;
uint32_t tempDataLen = 0;
@ -264,9 +266,7 @@ nsNativeDragTarget::DragEnter(LPDATAOBJECT pIDataSource, DWORD grfKeyState,
mEffectsPreferred = DROPEFFECT_NONE;
}
// Set the native data object into drag service
RefPtr<nsDragSession> session =
static_cast<nsDragSession*>(mDragService->GetCurrentSession(mWidget));
// Set the native data object into drag session
session->SetIDataObject(pIDataSource);
// Now process the native drag state and then dispatch the event