summaryrefslogtreecommitdiff
path: root/widget
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2023-10-25 05:22:32 +0200
committerMoonchild <moonchild@palemoon.org>2023-10-25 06:09:09 +0200
commita71597905c3b3a7ef4912b5d626bc141c7c4c4f9 (patch)
tree276e16d42e651e5145ff908a801d0487d86c9959 /widget
parent028aa731edbec7f60e72011b8bdc93222d5e5279 (diff)
downloaduxp-a71597905c3b3a7ef4912b5d626bc141c7c4c4f9.tar.gz
[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.
Diffstat (limited to 'widget')
-rw-r--r--widget/nsBaseWidget.cpp10
-rw-r--r--widget/nsBaseWidget.h1
-rw-r--r--widget/nsIWidget.h1
-rw-r--r--widget/windows/nsWindow.cpp11
4 files changed, 17 insertions, 6 deletions
diff --git a/widget/nsBaseWidget.cpp b/widget/nsBaseWidget.cpp
index d3cdf72cfc..c72f0364bc 100644
--- a/widget/nsBaseWidget.cpp
+++ b/widget/nsBaseWidget.cpp
@@ -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()
{
diff --git a/widget/nsBaseWidget.h b/widget/nsBaseWidget.h
index bbc6b72383..ab29fcd0ff 100644
--- a/widget/nsBaseWidget.h
+++ b/widget/nsBaseWidget.h
@@ -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;
diff --git a/widget/nsIWidget.h b/widget/nsIWidget.h
index 8e28c24da5..fe21b67275 100644
--- a/widget/nsIWidget.h
+++ b/widget/nsIWidget.h
@@ -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.
diff --git a/widget/windows/nsWindow.cpp b/widget/windows/nsWindow.cpp
index 8f614d8628..295518ea26 100644
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -3715,22 +3715,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);
}