Bug 1767460 [Linux] Implement RAII class for nsDragService::mEventLoopDepth r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D154584
This commit is contained in:
stransky 2022-08-15 19:30:03 +00:00
Родитель a4ab3bbff8
Коммит c83ad87f6f
3 изменённых файлов: 16 добавлений и 15 удалений

Просмотреть файл

@ -2246,10 +2246,7 @@ gboolean nsDragService::Schedule(DragTask aTask, nsWindow* aWindow,
gboolean nsDragService::TaskDispatchCallback(gpointer data) {
RefPtr<nsDragService> dragService = static_cast<nsDragService*>(data);
dragService->EventLoopEnter();
auto autoLeave = MakeScopeExit([&] { dragService->EventLoopLeave(); });
AutoEventLoop loop(dragService);
return dragService->RunScheduledTask();
}

Просмотреть файл

@ -99,9 +99,17 @@ class nsDragService final : public nsBaseDragService, public nsIObserver {
// set the drag icon during drag-begin
void SetDragIcon(GdkDragContext* aContext);
void EventLoopEnter() { mEventLoopDepth++; };
void EventLoopLeave() { mEventLoopDepth--; };
int GetLoopDepth() { return mEventLoopDepth; };
class AutoEventLoop {
RefPtr<nsDragService> mService;
public:
explicit AutoEventLoop(RefPtr<nsDragService> aService)
: mService(std::move(aService)) {
mService->mEventLoopDepth++;
}
~AutoEventLoop() { mService->mEventLoopDepth--; }
};
int GetLoopDepth() const { return mEventLoopDepth; };
protected:
virtual ~nsDragService();

Просмотреть файл

@ -5119,8 +5119,7 @@ void nsWindow::OnDragDataReceivedEvent(GtkWidget* aWidget,
LOGDRAG("nsWindow::OnDragDataReceived(%p)\n", (void*)this);
RefPtr<nsDragService> dragService = nsDragService::GetInstance();
dragService->EventLoopEnter();
auto autoLeave = MakeScopeExit([&] { dragService->EventLoopLeave(); });
nsDragService::AutoEventLoop loop(dragService);
dragService->TargetDataReceived(aWidget, aDragContext, aX, aY, aSelectionData,
aInfo, aTime);
}
@ -8186,8 +8185,7 @@ gboolean WindowDragMotionHandler(GtkWidget* aWidget,
innerMostWindow.get(), retx, rety);
RefPtr<nsDragService> dragService = nsDragService::GetInstance();
dragService->EventLoopEnter();
auto autoLeave = MakeScopeExit([&] { dragService->EventLoopLeave(); });
nsDragService::AutoEventLoop loop(dragService);
if (!dragService->ScheduleMotionEvent(innerMostWindow, aDragContext, point,
aTime)) {
return FALSE;
@ -8211,8 +8209,7 @@ void WindowDragLeaveHandler(GtkWidget* aWidget) {
}
RefPtr<nsDragService> dragService = nsDragService::GetInstance();
dragService->EventLoopEnter();
auto autoLeave = MakeScopeExit([&] { dragService->EventLoopLeave(); });
nsDragService::AutoEventLoop loop(dragService);
nsWindow* mostRecentDragWindow = dragService->GetMostRecentDestWindow();
if (!mostRecentDragWindow) {
@ -8273,8 +8270,7 @@ gboolean WindowDragDropHandler(GtkWidget* aWidget, GdkDragContext* aDragContext,
innerMostWindow.get(), retx, rety);
RefPtr<nsDragService> dragService = nsDragService::GetInstance();
dragService->EventLoopEnter();
auto autoLeave = MakeScopeExit([&] { dragService->EventLoopLeave(); });
nsDragService::AutoEventLoop loop(dragService);
return dragService->ScheduleDropEvent(innerMostWindow, aDragContext, point,
aTime);
}