Bug 666446, Part 5/10 - Change nsImageBoxFrame to register corresponding image with nsRefreshDriver to facilitate refresh driver-based animations. [r=roc]

This commit is contained in:
Scott Johnson 2011-11-09 13:39:16 -08:00
parent 3a74456f46
commit 20e54963ae
2 changed files with 46 additions and 5 deletions

View File

@ -72,6 +72,7 @@
#include "nsIDOMDocument.h"
#include "nsTransform2D.h"
#include "nsITheme.h"
#include "nsIImageLoadingContent.h"
#include "nsIServiceManager.h"
#include "nsIURI.h"
@ -173,6 +174,7 @@ nsImageBoxFrame::AttributeChanged(PRInt32 aNameSpaceID,
nsImageBoxFrame::nsImageBoxFrame(nsIPresShell* aShell, nsStyleContext* aContext):
nsLeafBoxFrame(aShell, aContext),
mIntrinsicSize(0,0),
mRequestRegistered(false),
mLoadFlags(nsIRequest::LOAD_NORMAL),
mUseSrcAttr(false),
mSuppressStyleCheck(false)
@ -195,9 +197,13 @@ nsImageBoxFrame::MarkIntrinsicWidthsDirty()
void
nsImageBoxFrame::DestroyFrom(nsIFrame* aDestructRoot)
{
// Release image loader first so that it's refcnt can go to zero
if (mImageRequest)
if (mImageRequest) {
nsLayoutUtils::DeregisterImageRequest(PresContext(), mImageRequest,
&mRequestRegistered);
// Release image loader first so that it's refcnt can go to zero
mImageRequest->CancelAndForgetObserver(NS_ERROR_FAILURE);
}
if (mListener)
reinterpret_cast<nsImageBoxListener*>(mListener.get())->SetFrame(nsnull); // set the frame to null so we don't send messages to a dead object.
@ -232,7 +238,11 @@ nsImageBoxFrame::Init(nsIContent* aContent,
void
nsImageBoxFrame::UpdateImage()
{
nsPresContext* presContext = PresContext();
if (mImageRequest) {
nsLayoutUtils::DeregisterImageRequest(presContext, mImageRequest,
&mRequestRegistered);
mImageRequest->CancelAndForgetObserver(NS_ERROR_FAILURE);
mImageRequest = nsnull;
}
@ -259,6 +269,12 @@ nsImageBoxFrame::UpdateImage()
nsContentUtils::LoadImage(uri, doc, mContent->NodePrincipal(),
doc->GetDocumentURI(), mListener, mLoadFlags,
getter_AddRefs(mImageRequest));
if (mImageRequest) {
nsLayoutUtils::RegisterImageRequestIfAnimated(presContext,
mImageRequest,
&mRequestRegistered);
}
}
} else {
// Only get the list-style-image if we aren't being drawn
@ -601,6 +617,15 @@ NS_IMETHODIMP nsImageBoxFrame::OnStopDecode(imgIRequest *request,
return NS_OK;
}
NS_IMETHODIMP nsImageBoxFrame::OnImageIsAnimated(imgIRequest *aRequest)
{
// Register with our refresh driver, if we're animated.
nsLayoutUtils::RegisterImageRequest(PresContext(), aRequest,
&mRequestRegistered);
return NS_OK;
}
NS_IMETHODIMP nsImageBoxFrame::FrameChanged(imgIContainer *aContainer,
const nsIntRect *aDirtyRect)
{
@ -624,7 +649,7 @@ NS_IMETHODIMP nsImageBoxListener::OnStartContainer(imgIRequest *request,
imgIContainer *image)
{
if (!mFrame)
return NS_ERROR_FAILURE;
return NS_OK;
return mFrame->OnStartContainer(request, image);
}
@ -633,7 +658,7 @@ NS_IMETHODIMP nsImageBoxListener::OnStopContainer(imgIRequest *request,
imgIContainer *image)
{
if (!mFrame)
return NS_ERROR_FAILURE;
return NS_OK;
return mFrame->OnStopContainer(request, image);
}
@ -643,11 +668,19 @@ NS_IMETHODIMP nsImageBoxListener::OnStopDecode(imgIRequest *request,
const PRUnichar *statusArg)
{
if (!mFrame)
return NS_ERROR_FAILURE;
return NS_OK;
return mFrame->OnStopDecode(request, status, statusArg);
}
NS_IMETHODIMP nsImageBoxListener::OnImageIsAnimated(imgIRequest* aRequest)
{
if (!mFrame)
return NS_OK;
return mFrame->OnImageIsAnimated(aRequest);
}
NS_IMETHODIMP nsImageBoxListener::FrameChanged(imgIContainer *aContainer,
const nsIntRect *aDirtyRect)
{

View File

@ -58,6 +58,8 @@ public:
NS_IMETHOD OnStopContainer(imgIRequest *request, imgIContainer *image);
NS_IMETHOD OnStopDecode(imgIRequest *request, nsresult status,
const PRUnichar *statusArg);
NS_IMETHOD OnImageIsAnimated(imgIRequest* aRequest);
// imgIContainerObserver (override nsStubImageDecoderObserver)
NS_IMETHOD FrameChanged(imgIContainer *aContainer,
const nsIntRect *aDirtyRect);
@ -122,6 +124,8 @@ public:
NS_IMETHOD OnStopDecode(imgIRequest *request,
nsresult status,
const PRUnichar *statusArg);
NS_IMETHOD OnImageIsAnimated(imgIRequest* aRequest);
NS_IMETHOD FrameChanged(imgIContainer *aContainer,
const nsIntRect *aDirtyRect);
@ -142,6 +146,10 @@ private:
nsSize mIntrinsicSize;
nsSize mImageSize;
// Boolean variable to determine if the current image request has been
// registered with the refresh driver.
bool mRequestRegistered;
nsCOMPtr<imgIRequest> mImageRequest;
nsCOMPtr<imgIDecoderObserver> mListener;