[widget] Change RegisterDragDrop to be called on idle.

This is a low-priority init function that should not be called with
immediate dispatch to the current thread, for performance reasons.
Additionally, do not call RegisterDragDrop for hidden windows.
This commit is contained in:
Moonchild
2023-10-25 05:22:32 +02:00
committed by roytam1
parent 38f8fde3e3
commit f2b0066036
5 changed files with 21 additions and 7 deletions
+4 -1
View File
@@ -695,7 +695,10 @@ nsresult nsView::AttachToTopLevelWidget(nsIWidget* aWidget)
mWindow = aWidget;
mWindow->SetAttachedWidgetListener(this);
mWindow->EnableDragDrop(true);
if (mWindow->WindowType() != eWindowType_invisible) {
nsresult rv = mWindow->AsyncEnableDragDrop(true);
NS_ENSURE_SUCCESS(rv, rv);
}
mWidgetIsTopLevel = true;
// Refresh the view bounds
+10
View File
@@ -2133,6 +2133,16 @@ nsBaseWidget::UpdateSynthesizedTouchState(MultiTouchInput* aState,
return inputToDispatch;
}
nsresult
nsBaseWidget::AsyncEnableDragDrop(bool aEnable)
{
RefPtr<nsBaseWidget> kungFuDeathGrip = this;
return NS_IdleDispatchToCurrentThread(
NS_NewRunnableFunction([this, aEnable, kungFuDeathGrip]() {
EnableDragDrop(aEnable);
}));
}
void
nsBaseWidget::RegisterPluginWindowForRemoteUpdates()
{
+1
View File
@@ -243,6 +243,7 @@ public:
NS_IMETHOD SetNonClientMargins(LayoutDeviceIntMargin& aMargins) override;
virtual LayoutDeviceIntPoint GetClientOffset() override;
virtual void EnableDragDrop(bool aEnable) override {};
virtual nsresult AsyncEnableDragDrop(bool aEnable) override;
NS_IMETHOD GetAttention(int32_t aCycleCount) override;
virtual bool HasPendingInputEvent() override;
NS_IMETHOD SetIcon(const nsAString &anIconSpec) override;
+1
View File
@@ -1378,6 +1378,7 @@ class nsIWidget : public nsISupports
* Enables the dropping of files to a widget.
*/
virtual void EnableDragDrop(bool aEnable) = 0;
virtual nsresult AsyncEnableDragDrop(bool aEnable) = 0;
/**
* Enables/Disables system mouse capture.
+5 -6
View File
@@ -3734,22 +3734,21 @@ nsWindow::ClientToWindowSize(const LayoutDeviceIntSize& aClientSize)
void
nsWindow::EnableDragDrop(bool aEnable)
{
NS_ASSERTION(mWnd, "nsWindow::EnableDragDrop() called after Destroy()");
if (!mWnd) {
// Return early if the window already closed
return;
}
nsresult rv = NS_ERROR_FAILURE;
if (aEnable) {
if (!mNativeDragTarget) {
mNativeDragTarget = new nsNativeDragTarget(this);
mNativeDragTarget->AddRef();
if (SUCCEEDED(::CoLockObjectExternal((LPUNKNOWN)mNativeDragTarget,
TRUE, FALSE))) {
::RegisterDragDrop(mWnd, (LPDROPTARGET)mNativeDragTarget);
}
::RegisterDragDrop(mWnd, (LPDROPTARGET)mNativeDragTarget);
}
} else {
if (mWnd && mNativeDragTarget) {
::RevokeDragDrop(mWnd);
::CoLockObjectExternal((LPUNKNOWN)mNativeDragTarget, FALSE, TRUE);
mNativeDragTarget->DragCancel();
NS_RELEASE(mNativeDragTarget);
}