mirror of
https://github.com/roytam1/UXP.git
synced 2026-05-26 05:46:58 +00:00
[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:
+4
-1
@@ -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
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user