make event delayed.
draft
--- a/image/RasterImage.cpp
+++ b/image/RasterImage.cpp
@@ -1789,18 +1789,43 @@ RasterImage::NotifyDecodeComplete(const
if (mWantFullDecode) {
mWantFullDecode = false;
RequestDecodeForSize(mSize, DECODE_FLAGS_DEFAULT);
}
} else {
// We've decoded fully; if we're still waiting to send the
// load event, do it now.
if (mLoadProgress) {
- NotifyForLoadEvent(*mLoadProgress);
+ // If we intentionally delayed until full decode, delay
+ // dispatch of the event itself, since we want to ensure that
+ // whatever needed the decode has time to act on it (reflow,
+ // for example).
+ Progress progress = *mLoadProgress;
mLoadProgress = Nothing();
+
+ if (mDelayLoadEventUntilDecode) {
+ // Dispatch the event as a runnable.
+ nsCOMPtr<nsIEventTarget> eventTarget;
+ if (mProgressTracker) {
+ eventTarget = mProgressTracker->GetEventTarget();
+ } else {
+ eventTarget = do_GetMainThread();
+ }
+
+ RefPtr<RasterImage> image = this;
+ nsCOMPtr<nsIRunnable> ev = NS_NewRunnableFunction(
+ "RasterImage::NotifyDecodeComplete",
+ [=]() -> void {
+ image->NotifyForLoadEvent(progress);
+ });
+ eventTarget->Dispatch(ev.forget(), NS_DISPATCH_NORMAL);
+ } else {
+ // Run the event directly.
+ NotifyForLoadEvent(progress);
+ }
}
}
}
}
void
RasterImage::ReportDecoderError()
{