Bug 1362382 - Move RegisterDragDrop to be called during idle time, if possible r=jimm

Additionally, do not call RegisterDragDrop for hidden windows.

MozReview-Commit-ID: Fv8j9FntGGT
This commit is contained in:
Kirk Steuber
2017-08-30 11:18:25 -07:00
parent 56493a67bb
commit 1a30465ba0
5 changed files with 27 additions and 2 deletions

View File

@@ -716,7 +716,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

View File

@@ -125,6 +125,11 @@ int32_t nsIWidget::sPointerIdCounter = 0;
/*static*/ uint64_t AutoObserverNotifier::sObserverId = 0;
/*static*/ nsDataHashtable<nsUint64HashKey, nsCOMPtr<nsIObserver>> AutoObserverNotifier::sSavedObservers;
// The maximum amount of time to let the EnableDragDrop runnable wait in the
// idle queue before timing out and moving it to the regular queue. Value is in
// milliseconds.
const uint32_t kAsyncDragDropTimeout = 1000;
namespace mozilla {
namespace widget {
@@ -2229,6 +2234,18 @@ nsBaseWidget::UnregisterPluginWindowForRemoteUpdates()
#endif
}
nsresult
nsBaseWidget::AsyncEnableDragDrop(bool aEnable)
{
RefPtr<nsBaseWidget> kungFuDeathGrip = this;
return NS_IdleDispatchToCurrentThread(
NS_NewRunnableFunction("AsyncEnableDragDropFn",
[this, aEnable, kungFuDeathGrip]() {
EnableDragDrop(aEnable);
}),
kAsyncDragDropTimeout);
}
// static
nsIWidget*
nsIWidget::LookupRegisteredPluginWindow(uintptr_t aWindowID)

View File

@@ -250,6 +250,7 @@ public:
virtual nsresult SetNonClientMargins(LayoutDeviceIntMargin& aMargins) override;
virtual LayoutDeviceIntPoint GetClientOffset() override;
virtual void EnableDragDrop(bool aEnable) override {};
virtual nsresult AsyncEnableDragDrop(bool aEnable) override;
virtual MOZ_MUST_USE nsresult
GetAttention(int32_t aCycleCount) override
{ return NS_OK; }

View File

@@ -1415,6 +1415,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.

View File

@@ -3772,7 +3772,10 @@ 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;
}
if (aEnable) {
if (!mNativeDragTarget) {