diff options
-rw-r--r-- | view/nsView.cpp | 5 | ||||
-rw-r--r-- | widget/nsBaseWidget.cpp | 10 | ||||
-rw-r--r-- | widget/nsBaseWidget.h | 1 | ||||
-rw-r--r-- | widget/nsIWidget.h | 1 | ||||
-rw-r--r-- | widget/windows/nsWindow.cpp | 11 |
5 files changed, 21 insertions, 7 deletions
diff --git a/view/nsView.cpp b/view/nsView.cpp index 8f509cadeb..2c2768a178 100644 --- a/view/nsView.cpp +++ b/view/nsView.cpp @@ -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 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); } |