From b9b410659ca32a5d92c04d1ef12abd266e85e608 Mon Sep 17 00:00:00 2001 From: Joe Drew Date: Fri, 18 Jan 2013 16:47:17 -0500 Subject: [PATCH] Bug 716140 - Factor out notification of a particular imgStatusTracker state into its own function. r=seth --HG-- extra : rebase_source : ba72f5c3aa1b47d8c6f36d1c2d0202d55671a1d2 --- image/src/imgStatusTracker.cpp | 91 +++++++++++++++++++--------------- image/src/imgStatusTracker.h | 4 ++ 2 files changed, 54 insertions(+), 41 deletions(-) diff --git a/image/src/imgStatusTracker.cpp b/image/src/imgStatusTracker.cpp index 237a8b92daf..1ea54d25cfa 100644 --- a/image/src/imgStatusTracker.cpp +++ b/image/src/imgStatusTracker.cpp @@ -433,6 +433,53 @@ imgStatusTracker::NotifyCurrentState(imgRequestProxy* proxy) NS_DispatchToCurrentThread(ev); } +/* static */ void +imgStatusTracker::SyncNotifyState(imgRequestProxy* proxy, bool hasImage, uint32_t state, nsIntRect& dirtyRect, bool hadLastPart) +{ + nsCOMPtr kungFuDeathGrip(proxy); + + // OnStartRequest + if (state & stateRequestStarted) + proxy->OnStartRequest(); + + // OnStartContainer + if (state & stateHasSize) + proxy->OnStartContainer(); + + // OnStartDecode + if (state & stateDecodeStarted) + proxy->OnStartDecode(); + + // BlockOnload + if (state & stateBlockingOnload) + proxy->BlockOnload(); + + if (hasImage) { + // OnFrameUpdate + // If there's any content in this frame at all (always true for + // vector images, true for raster images that have decoded at + // least one frame) then send OnFrameUpdate. + if (!dirtyRect.IsEmpty()) + proxy->OnFrameUpdate(&dirtyRect); + + if (state & stateFrameStopped) + proxy->OnStopFrame(); + + // OnImageIsAnimated + if (state & stateImageIsAnimated) + proxy->OnImageIsAnimated(); + } + + if (state & stateDecodeStopped) { + NS_ABORT_IF_FALSE(hasImage, "stopped decoding without ever having an image?"); + proxy->OnStopDecode(); + } + + if (state & stateRequestStopped) { + proxy->OnStopRequest(hadLastPart); + } +} + void imgStatusTracker::SyncNotify(imgRequestProxy* proxy) { @@ -444,52 +491,14 @@ imgStatusTracker::SyncNotify(imgRequestProxy* proxy) LOG_SCOPE_WITH_PARAM(GetImgLog(), "imgStatusTracker::SyncNotify", "uri", spec.get()); #endif - nsCOMPtr kungFuDeathGrip(proxy); - - // OnStartRequest - if (mState & stateRequestStarted) - proxy->OnStartRequest(); - - // OnStartContainer - if (mState & stateHasSize) - proxy->OnStartContainer(); - - // OnStartDecode - if (mState & stateDecodeStarted) - proxy->OnStartDecode(); - - // BlockOnload - if (mState & stateBlockingOnload) - proxy->BlockOnload(); - + nsIntRect r; if (mImage) { - // OnFrameUpdate // XXX - Should only send partial rects here, but that needs to // wait until we fix up the observer interface - nsIntRect r(mImage->FrameRect(imgIContainer::FRAME_CURRENT)); - - // If there's any content in this frame at all (always true for - // vector images, true for raster images that have decoded at - // least one frame) then send OnFrameUpdate. - if (!r.IsEmpty()) - proxy->OnFrameUpdate(&r); - - if (mState & stateFrameStopped) - proxy->OnStopFrame(); - - // OnImageIsAnimated - if (mState & stateImageIsAnimated) - proxy->OnImageIsAnimated(); + r = mImage->FrameRect(imgIContainer::FRAME_CURRENT); } - if (mState & stateDecodeStopped) { - NS_ABORT_IF_FALSE(mImage, "stopped decoding without ever having an image?"); - proxy->OnStopDecode(); - } - - if (mState & stateRequestStopped) { - proxy->OnStopRequest(mHadLastPart); - } + SyncNotifyState(proxy, !!mImage, mState, r, mHadLastPart); } void diff --git a/image/src/imgStatusTracker.h b/image/src/imgStatusTracker.h index d80d8dc5b6d..9cae09ef93a 100644 --- a/image/src/imgStatusTracker.h +++ b/image/src/imgStatusTracker.h @@ -188,6 +188,10 @@ private: void FireFailureNotification(); + static void SyncNotifyState(imgRequestProxy* proxy, bool hasImage, + uint32_t state, nsIntRect& dirtyRect, + bool hadLastPart); + nsCOMPtr mRequestRunnable; // The invalid area of the most recent frame we know about. (All previous