diff --git a/dom/events/EventStateManager.cpp b/dom/events/EventStateManager.cpp index d895a4642817..69674b95da0a 100644 --- a/dom/events/EventStateManager.cpp +++ b/dom/events/EventStateManager.cpp @@ -2414,8 +2414,8 @@ void EventStateManager::StopTrackingDragGesture(bool aClearInChildProcesses) { nsCOMPtr dragService = do_GetService("@mozilla.org/widget/dragservice;1"); if (dragService) { - nsCOMPtr dragSession; - dragService->GetCurrentSession(getter_AddRefs(dragSession)); + RefPtr dragSession = + dragService->GetCurrentSession(mPresContext->GetRootWidget()); if (!dragSession) { // Only notify if there isn't a drag session active. dragService->RemoveAllChildProcesses(); @@ -2807,8 +2807,11 @@ bool EventStateManager::DoDefaultDragStart( // began. However, if we're handling drag session for synthesized events, // we need to initialize some information of the session. Therefore, we // need to keep going for synthesized case. - nsCOMPtr dragSession; - dragService->GetCurrentSession(getter_AddRefs(dragSession)); + if (MOZ_UNLIKELY(!mPresContext)) { + return true; + } + nsCOMPtr dragSession = + dragService->GetCurrentSession(mPresContext->GetRootWidget()); if (dragSession && !dragSession->IsSynthesizedForTests()) { return true; } diff --git a/layout/xul/nsXULTooltipListener.cpp b/layout/xul/nsXULTooltipListener.cpp index 0f00f36d17a4..3069ae38671e 100644 --- a/layout/xul/nsXULTooltipListener.cpp +++ b/layout/xul/nsXULTooltipListener.cpp @@ -248,8 +248,12 @@ nsXULTooltipListener::HandleEvent(Event* aEvent) { nsCOMPtr dragService = do_GetService("@mozilla.org/widget/dragservice;1"); NS_ENSURE_TRUE(dragService, NS_OK); - nsCOMPtr dragSession; - dragService->GetCurrentSession(getter_AddRefs(dragSession)); + auto* widgetGuiEvent = aEvent->WidgetEventPtr()->AsGUIEvent(); + if (!widgetGuiEvent) { + return NS_OK; + } + nsCOMPtr dragSession = + dragService->GetCurrentSession(widgetGuiEvent->mWidget); if (dragSession) { return NS_OK; } diff --git a/widget/MockDragServiceController.cpp b/widget/MockDragServiceController.cpp index ea4926f85244..a4c460a10b61 100644 --- a/widget/MockDragServiceController.cpp +++ b/widget/MockDragServiceController.cpp @@ -142,10 +142,9 @@ MockDragServiceController::SendEvent( ds->StartDragSession(); } - nsCOMPtr currentDragSession; - nsresult rv = ds->GetCurrentSession(getter_AddRefs(currentDragSession)); - NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr currentDragSession = ds->GetCurrentSession(widget); + nsresult rv; switch (aEventType) { case EventType::eMouseDown: case EventType::eMouseMove: diff --git a/widget/android/nsWindow.cpp b/widget/android/nsWindow.cpp index 7f124b7bb5dc..a072bf33e352 100644 --- a/widget/android/nsWindow.cpp +++ b/widget/android/nsWindow.cpp @@ -2692,8 +2692,7 @@ void nsWindow::OnDragEvent(int32_t aAction, int64_t aTime, float aX, float aY, nsDragService::SetDropData(dropData); } - nsCOMPtr dragSession; - dragService->GetCurrentSession(getter_AddRefs(dragSession)); + nsCOMPtr dragSession = dragService->GetCurrentSession(this); if (dragSession) { switch (message) { case eDragOver: diff --git a/widget/cocoa/nsChildView.mm b/widget/cocoa/nsChildView.mm index b57df1582542..7a524a6ac6dc 100644 --- a/widget/cocoa/nsChildView.mm +++ b/widget/cocoa/nsChildView.mm @@ -3975,8 +3975,8 @@ static gfx::IntPoint GetIntegerDeltaForEvent(NSEvent* aEvent) { - (BOOL)isDragInProgress { if (!mDragService) return NO; - nsCOMPtr dragSession; - mDragService->GetCurrentSession(getter_AddRefs(dragSession)); + nsCOMPtr dragSession = + mDragService->GetCurrentSession(mGeckoChild); return dragSession != nullptr; } @@ -4112,8 +4112,8 @@ static gfx::IntPoint GetIntegerDeltaForEvent(NSEvent* aEvent) { mDragService->StartDragSession(); } - nsCOMPtr dragSession; - mDragService->GetCurrentSession(getter_AddRefs(dragSession)); + nsCOMPtr dragSession = + mDragService->GetCurrentSession(mGeckoChild); if (dragSession) { if (aMessage == eDragOver) { // fire the drag event at the source. Just ignore whether it was diff --git a/widget/gtk/nsWindow.cpp b/widget/gtk/nsWindow.cpp index e3f3cf40f5e6..2411a206d481 100644 --- a/widget/gtk/nsWindow.cpp +++ b/widget/gtk/nsWindow.cpp @@ -4940,8 +4940,8 @@ void nsWindow::OnContainerFocusOutEvent(GdkEventFocus* aEvent) { const bool shouldRollupMenus = [&] { nsCOMPtr dragService = do_GetService("@mozilla.org/widget/dragservice;1"); - nsCOMPtr dragSession; - dragService->GetCurrentSession(getter_AddRefs(dragSession)); + nsCOMPtr dragSession = + dragService->GetCurrentSession(this); if (!dragSession) { return true; } @@ -7668,7 +7668,6 @@ bool nsWindow::CheckForRollup(gdouble aMouseX, gdouble aMouseY, bool aIsWheel, return retVal; } -/* static */ bool nsWindow::DragInProgress() { nsCOMPtr dragService = do_GetService("@mozilla.org/widget/dragservice;1"); @@ -7676,8 +7675,8 @@ bool nsWindow::DragInProgress() { return false; } - nsCOMPtr currentDragSession; - dragService->GetCurrentSession(getter_AddRefs(currentDragSession)); + nsCOMPtr currentDragSession = + dragService->GetCurrentSession(this); return !!currentDragSession; } @@ -7685,7 +7684,8 @@ bool nsWindow::DragInProgress() { // https://bugzilla.mozilla.org/show_bug.cgi?id=1622107 // We try to detect when Wayland compositor / gtk fails to deliver // info about finished D&D operations and cancel it on our own. -MOZ_CAN_RUN_SCRIPT static void WaylandDragWorkaround(GdkEventButton* aEvent) { +MOZ_CAN_RUN_SCRIPT static void WaylandDragWorkaround(nsWindow* aWindow, + GdkEventButton* aEvent) { static int buttonPressCountWithDrag = 0; // We track only left button state as Firefox performs D&D on left @@ -7699,8 +7699,8 @@ MOZ_CAN_RUN_SCRIPT static void WaylandDragWorkaround(GdkEventButton* aEvent) { if (!dragService) { return; } - nsCOMPtr currentDragSession; - dragService->GetCurrentSession(getter_AddRefs(currentDragSession)); + nsCOMPtr currentDragSession = + dragService->GetCurrentSession(aWindow); if (!currentDragSession) { buttonPressCountWithDrag = 0; @@ -8360,7 +8360,7 @@ static gboolean button_press_event_cb(GtkWidget* widget, window->OnButtonPressEvent(event); if (GdkIsWaylandDisplay()) { - WaylandDragWorkaround(event); + WaylandDragWorkaround(window, event); } return TRUE; diff --git a/widget/gtk/nsWindow.h b/widget/gtk/nsWindow.h index 98cec928817f..388501bc50a5 100644 --- a/widget/gtk/nsWindow.h +++ b/widget/gtk/nsWindow.h @@ -802,7 +802,7 @@ class nsWindow final : public nsBaseWidget { InputRegion mInputRegion; - static bool DragInProgress(void); + bool DragInProgress(void); void DispatchMissedButtonReleases(GdkEventCrossing* aGdkEvent); diff --git a/widget/windows/nsNativeDragTarget.cpp b/widget/windows/nsNativeDragTarget.cpp index b615a3e4bcf9..8147a6ef11f6 100644 --- a/widget/windows/nsNativeDragTarget.cpp +++ b/widget/windows/nsNativeDragTarget.cpp @@ -166,8 +166,8 @@ void nsNativeDragTarget::ProcessDrag(EventMessage aEventMessage, GetGeckoDragAction(grfKeyState, pdwEffect, &geckoAction); // Set the current action into the Gecko specific type - nsCOMPtr currSession; - mDragService->GetCurrentSession(getter_AddRefs(currSession)); + RefPtr currSession = + static_cast(mDragService->GetCurrentSession(mWidget)); if (!currSession) { return; } @@ -298,8 +298,8 @@ nsNativeDragTarget::DragOver(DWORD grfKeyState, POINTL ptl, LPDWORD pdwEffect) { // then we should include it as an allowed effect. mEffectsAllowed = (*pdwEffect) | (mEffectsAllowed & DROPEFFECT_LINK); - nsCOMPtr currentDragSession; - mDragService->GetCurrentSession(getter_AddRefs(currentDragSession)); + nsCOMPtr currentDragSession = + mDragService->GetCurrentSession(mWidget); if (!currentDragSession) { return S_OK; // Drag was canceled. } @@ -349,8 +349,8 @@ nsNativeDragTarget::DragLeave() { // dispatch the event into Gecko DispatchDragDropEvent(eDragExit, gDragLastPoint); - nsCOMPtr currentDragSession; - mDragService->GetCurrentSession(getter_AddRefs(currentDragSession)); + nsCOMPtr currentDragSession = + mDragService->GetCurrentSession(mWidget); if (currentDragSession) { nsCOMPtr sourceNode; @@ -426,8 +426,8 @@ nsNativeDragTarget::Drop(LPDATAOBJECT pData, DWORD grfKeyState, POINTL aPT, // Now process the native drag state and then dispatch the event ProcessDrag(eDrop, grfKeyState, aPT, pdwEffect); - nsCOMPtr currentDragSession; - serv->GetCurrentSession(getter_AddRefs(currentDragSession)); + nsCOMPtr currentDragSession = + serv->GetCurrentSession(mWidget); if (!currentDragSession) { return S_OK; // DragCancel() was called. }