Bug 594771 - Reset animations when .src changes. r=joe,bz a=blocking-final

This commit is contained in:
Alon Zakai 2011-01-26 10:52:48 -08:00
Родитель c213200d10
Коммит 005eeb4dea
3 изменённых файлов: 37 добавлений и 12 удалений

Просмотреть файл

@ -114,6 +114,9 @@ nsImageLoadingContent::nsImageLoadingContent()
mUserDisabled(PR_FALSE),
mSuppressed(PR_FALSE),
mBlockingOnload(PR_FALSE),
mNewRequestsWillNeedAnimationReset(PR_FALSE),
mPendingRequestNeedsResetAnimation(PR_FALSE),
mCurrentRequestNeedsResetAnimation(PR_FALSE),
mStateChangerDepth(0)
{
if (!nsContentUtils::GetImgLoader()) {
@ -281,10 +284,20 @@ nsImageLoadingContent::OnStopDecode(imgIRequest* aRequest,
if (aRequest == mPendingRequest) {
PrepareCurrentRequest() = mPendingRequest;
mPendingRequest = nsnull;
mCurrentRequestNeedsResetAnimation = mPendingRequestNeedsResetAnimation;
mPendingRequestNeedsResetAnimation = PR_FALSE;
}
NS_ABORT_IF_FALSE(aRequest == mCurrentRequest,
"One way or another, we should be current by now");
if (mCurrentRequestNeedsResetAnimation) {
nsCOMPtr<imgIContainer> container;
mCurrentRequest->GetImage(getter_AddRefs(container));
if (container)
container->ResetAnimation();
mCurrentRequestNeedsResetAnimation = PR_FALSE;
}
// We just loaded all the data we're going to get. If we haven't done an
// initial paint, we want to make sure the image starts decoding for 2
// reasons:
@ -914,6 +927,8 @@ nsImageLoadingContent::PrepareCurrentRequest()
// Get rid of anything that was there previously.
ClearCurrentRequest(NS_ERROR_IMAGE_SRC_CHANGED);
mCurrentRequestNeedsResetAnimation = mNewRequestsWillNeedAnimationReset;
// Return a reference.
return mCurrentRequest;
}
@ -924,6 +939,8 @@ nsImageLoadingContent::PreparePendingRequest()
// Get rid of anything that was there previously.
ClearPendingRequest(NS_ERROR_IMAGE_SRC_CHANGED);
mPendingRequestNeedsResetAnimation = mNewRequestsWillNeedAnimationReset;
// Return a reference.
return mPendingRequest;
}
@ -944,6 +961,7 @@ nsImageLoadingContent::ClearCurrentRequest(nsresult aReason)
UntrackImage(mCurrentRequest);
mCurrentRequest->CancelAndForgetObserver(aReason);
mCurrentRequest = nsnull;
mCurrentRequestNeedsResetAnimation = PR_FALSE;
// We only block onload during the decoding of "current" images. This one is
// going away, so we should unblock unconditionally here.
@ -958,6 +976,7 @@ nsImageLoadingContent::ClearPendingRequest(nsresult aReason)
UntrackImage(mPendingRequest);
mPendingRequest->CancelAndForgetObserver(aReason);
mPendingRequest = nsnull;
mPendingRequestNeedsResetAnimation = PR_FALSE;
}
bool

Просмотреть файл

@ -339,6 +339,21 @@ private:
*/
PRPackedBool mBlockingOnload : 1;
protected:
/**
* A hack to get animations to reset, see bug 594771. On requests
* that originate from setting .src, we mark them for needing their animation
* reset when they are ready. mNewRequestsWillNeedAnimationReset is set to
* true while preparing such requests (as a hack around needing to change an
* interface), and the other two booleans store which of the current
* and pending requests are of the sort that need their animation restarted.
*/
PRPackedBool mNewRequestsWillNeedAnimationReset : 1;
private:
PRPackedBool mPendingRequestNeedsResetAnimation : 1;
PRPackedBool mCurrentRequestNeedsResetAnimation : 1;
/* The number of nested AutoStateChangers currently tracking our state. */
PRUint8 mStateChangerDepth;
};

Просмотреть файл

@ -510,7 +510,8 @@ nsHTMLImageElement::SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
return NS_OK;
}
nsCOMPtr<imgIRequest> oldCurrentRequest = mCurrentRequest;
// A hack to get animations to reset. See bug 594771.
mNewRequestsWillNeedAnimationReset = PR_TRUE;
// Force image loading here, so that we'll try to load the image from
// network if it's set to be not cacheable... If we change things so that
@ -519,17 +520,7 @@ nsHTMLImageElement::SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
// here.
LoadImage(aValue, PR_TRUE, aNotify);
if (mCurrentRequest && !mPendingRequest &&
oldCurrentRequest != mCurrentRequest) {
// We have a current request, and it's not the same one as we used
// to have, and we have no pending request. So imglib already had
// that image. Reset the animation on it -- see bug 210001
nsCOMPtr<imgIContainer> container;
mCurrentRequest->GetImage(getter_AddRefs(container));
if (container) {
container->ResetAnimation();
}
}
mNewRequestsWillNeedAnimationReset = PR_FALSE;
}
return nsGenericHTMLElement::SetAttr(aNameSpaceID, aName, aPrefix, aValue,