Backed out changeset 7f708623bf59 (from bug 322475, which made us construct all our image loaders at frame construction time) because of issues with propagation of backgrounds to the canvas (bug 460796).

--HG--
rename : layout/base/nsImageLoadNotifier.cpp => layout/base/nsImageLoader.cpp
rename : layout/base/nsImageLoadNotifier.h => layout/base/nsImageLoader.h
This commit is contained in:
L. David Baron 2008-10-28 14:34:03 -07:00
parent 2bd8ac7a44
commit e7cd23e3ac
6 changed files with 65 additions and 67 deletions

View File

@ -129,7 +129,7 @@ CPPSRCS = \
nsFrameManager.cpp \
nsFrameTraversal.cpp \
nsGenConList.cpp \
nsImageLoadNotifier.cpp \
nsImageLoader.cpp \
nsLayoutDebugger.cpp \
nsLayoutHistoryState.cpp \
nsLayoutUtils.cpp \

View File

@ -39,7 +39,7 @@
/* class to notify frames of background image loads */
#include "nsImageLoadNotifier.h"
#include "nsImageLoader.h"
#include "imgILoader.h"
@ -61,18 +61,17 @@
// Paint forcing
#include "prenv.h"
NS_IMPL_ISUPPORTS2(nsImageLoadNotifier, imgIDecoderObserver, imgIContainerObserver)
NS_IMPL_ISUPPORTS2(nsImageLoader, imgIDecoderObserver, imgIContainerObserver)
nsImageLoadNotifier::nsImageLoadNotifier(nsIFrame *aFrame,
PRBool aReflowOnLoad,
nsImageLoadNotifier *aNextLoader)
nsImageLoader::nsImageLoader(nsIFrame *aFrame, PRBool aReflowOnLoad,
nsImageLoader *aNextLoader)
: mFrame(aFrame),
mReflowOnLoad(aReflowOnLoad),
mNextLoader(aNextLoader)
{
}
nsImageLoadNotifier::~nsImageLoadNotifier()
nsImageLoader::~nsImageLoader()
{
mFrame = nsnull;
@ -81,13 +80,12 @@ nsImageLoadNotifier::~nsImageLoadNotifier()
}
}
/* static */ already_AddRefed<nsImageLoadNotifier>
nsImageLoadNotifier::Create(nsIFrame *aFrame, imgIRequest *aRequest,
PRBool aReflowOnLoad,
nsImageLoadNotifier *aNextLoader)
/* static */ already_AddRefed<nsImageLoader>
nsImageLoader::Create(nsIFrame *aFrame, imgIRequest *aRequest,
PRBool aReflowOnLoad, nsImageLoader *aNextLoader)
{
nsRefPtr<nsImageLoadNotifier> loader =
new nsImageLoadNotifier(aFrame, aReflowOnLoad, aNextLoader);
nsRefPtr<nsImageLoader> loader =
new nsImageLoader(aFrame, aReflowOnLoad, aNextLoader);
loader->Load(aRequest);
@ -95,13 +93,13 @@ nsImageLoadNotifier::Create(nsIFrame *aFrame, imgIRequest *aRequest,
}
void
nsImageLoadNotifier::Destroy()
nsImageLoader::Destroy()
{
// Destroy the chain with only one level of recursion.
nsRefPtr<nsImageLoadNotifier> list = mNextLoader;
nsRefPtr<nsImageLoader> list = mNextLoader;
mNextLoader = nsnull;
while (list) {
nsRefPtr<nsImageLoadNotifier> todestroy = list;
nsRefPtr<nsImageLoader> todestroy = list;
list = todestroy->mNextLoader;
todestroy->mNextLoader = nsnull;
todestroy->Destroy();
@ -117,7 +115,7 @@ nsImageLoadNotifier::Destroy()
}
nsresult
nsImageLoadNotifier::Load(imgIRequest *aImage)
nsImageLoader::Load(imgIRequest *aImage)
{
NS_ASSERTION(!mRequest, "can't reuse image loaders");
@ -138,8 +136,8 @@ nsImageLoadNotifier::Load(imgIRequest *aImage)
NS_IMETHODIMP nsImageLoadNotifier::OnStartContainer(imgIRequest *aRequest,
imgIContainer *aImage)
NS_IMETHODIMP nsImageLoader::OnStartContainer(imgIRequest *aRequest,
imgIContainer *aImage)
{
if (aImage)
{
@ -155,8 +153,8 @@ NS_IMETHODIMP nsImageLoadNotifier::OnStartContainer(imgIRequest *aRequest,
return NS_OK;
}
NS_IMETHODIMP nsImageLoadNotifier::OnStopFrame(imgIRequest *aRequest,
gfxIImageFrame *aFrame)
NS_IMETHODIMP nsImageLoader::OnStopFrame(imgIRequest *aRequest,
gfxIImageFrame *aFrame)
{
if (!mFrame)
return NS_ERROR_FAILURE;
@ -183,9 +181,9 @@ NS_IMETHODIMP nsImageLoadNotifier::OnStopFrame(imgIRequest *aRequest,
return NS_OK;
}
NS_IMETHODIMP nsImageLoadNotifier::FrameChanged(imgIContainer *aContainer,
gfxIImageFrame *newframe,
nsRect * dirtyRect)
NS_IMETHODIMP nsImageLoader::FrameChanged(imgIContainer *aContainer,
gfxIImageFrame *newframe,
nsRect * dirtyRect)
{
if (!mFrame)
return NS_ERROR_FAILURE;
@ -209,7 +207,7 @@ NS_IMETHODIMP nsImageLoadNotifier::FrameChanged(imgIContainer *aContainer,
void
nsImageLoadNotifier::RedrawDirtyFrame(const nsRect* aDamageRect)
nsImageLoader::RedrawDirtyFrame(const nsRect* aDamageRect)
{
if (mReflowOnLoad) {
nsIPresShell *shell = mFrame->PresContext()->GetPresShell();

View File

@ -54,17 +54,17 @@ class nsIURI;
*
* Each frame's image loaders form a linked list.
*/
class nsImageLoadNotifier : public nsStubImageDecoderObserver
class nsImageLoader : public nsStubImageDecoderObserver
{
private:
nsImageLoadNotifier(nsIFrame *aFrame, PRBool aReflowOnLoad,
nsImageLoadNotifier *aNextLoader);
virtual ~nsImageLoadNotifier();
nsImageLoader(nsIFrame *aFrame, PRBool aReflowOnLoad,
nsImageLoader *aNextLoader);
virtual ~nsImageLoader();
public:
static already_AddRefed<nsImageLoadNotifier>
static already_AddRefed<nsImageLoader>
Create(nsIFrame *aFrame, imgIRequest *aRequest,
PRBool aReflowOnLoad, nsImageLoadNotifier *aNextLoader);
PRBool aReflowOnLoad, nsImageLoader *aNextLoader);
NS_DECL_ISUPPORTS
@ -85,7 +85,7 @@ public:
void Destroy();
imgIRequest *GetRequest() { return mRequest; }
nsImageLoadNotifier *GetNextLoader() { return mNextLoader; }
nsImageLoader *GetNextLoader() { return mNextLoader; }
private:
nsresult Load(imgIRequest *aImage);
@ -94,5 +94,5 @@ private:
nsIFrame *mFrame;
nsCOMPtr<imgIRequest> mRequest;
PRBool mReflowOnLoad;
nsRefPtr<nsImageLoadNotifier> mNextLoader;
nsRefPtr<nsImageLoader> mNextLoader;
};

View File

@ -49,7 +49,7 @@
#include "nsPIDOMWindow.h"
#include "nsIFocusController.h"
#include "nsStyleSet.h"
#include "nsImageLoadNotifier.h"
#include "nsImageLoader.h"
#include "nsIContent.h"
#include "nsIFrame.h"
#include "nsIRenderingContext.h"
@ -150,7 +150,7 @@ IsVisualCharset(const nsCString& aCharset)
static PLDHashOperator
destroy_notifiers(const void * aKey, nsRefPtr<nsImageLoadNotifier>& aData, void* closure)
destroy_loads(const void * aKey, nsRefPtr<nsImageLoader>& aData, void* closure)
{
aData->Destroy();
return PL_DHASH_NEXT;
@ -231,7 +231,7 @@ nsPresContext::nsPresContext(nsIDocument* aDocument, nsPresContextType aType)
nsPresContext::~nsPresContext()
{
mImageNotifiers.Enumerate(destroy_notifiers, nsnull);
mImageLoaders.Enumerate(destroy_loads, nsnull);
NS_PRECONDITION(!mShell, "Presshell forgot to clear our mShell pointer");
SetShell(nsnull);
@ -299,7 +299,7 @@ NS_IMPL_CYCLE_COLLECTING_ADDREF(nsPresContext)
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsPresContext)
static PLDHashOperator
TraverseImageNotifier(const void * aKey, nsRefPtr<nsImageLoadNotifier>& aData,
TraverseImageLoader(const void * aKey, nsRefPtr<nsImageLoader>& aData,
void* aClosure)
{
nsCycleCollectionTraversalCallback *cb =
@ -317,7 +317,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsPresContext)
// NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(mLookAndFeel); // a service
// NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(mLangGroup); // an atom
tmp->mImageNotifiers.Enumerate(TraverseImageNotifier, &cb);
tmp->mImageLoaders.Enumerate(TraverseImageLoader, &cb);
// NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mTheme); // a service
// NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLangService); // a service
@ -339,8 +339,8 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsPresContext)
// NS_RELEASE(tmp->mLookAndFeel); // a service
// NS_RELEASE(tmp->mLangGroup); // an atom
tmp->mImageNotifiers.Enumerate(destroy_notifiers, nsnull);
tmp->mImageNotifiers.Clear();
tmp->mImageLoaders.Enumerate(destroy_loads, nsnull);
tmp->mImageLoaders.Clear();
// NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mTheme); // a service
// NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mLangService); // a service
@ -813,7 +813,7 @@ nsPresContext::Init(nsIDeviceContext* aDeviceContext)
mDeviceContext->FlushFontCache();
mCurAppUnitsPerDevPixel = AppUnitsPerDevPixel();
if (!mImageNotifiers.Init())
if (!mImageLoaders.Init())
return NS_ERROR_OUT_OF_MEMORY;
// Get the look and feel service here; default colors will be initialized
@ -1025,9 +1025,9 @@ static void SetImgAnimModeOnImgReq(imgIRequest* aImgReq, PRUint16 aMode)
// Enumeration call back for HashTable
static PLDHashOperator
set_animation_mode(const void * aKey, nsRefPtr<nsImageLoadNotifier>& aData, void* closure)
set_animation_mode(const void * aKey, nsRefPtr<nsImageLoader>& aData, void* closure)
{
for (nsImageLoadNotifier *loader = aData; loader;
for (nsImageLoader *loader = aData; loader;
loader = loader->GetNextLoader()) {
imgIRequest* imgReq = loader->GetRequest();
SetImgAnimModeOnImgReq(imgReq, (PRUint16)NS_PTR_TO_INT32(closure));
@ -1069,7 +1069,7 @@ nsPresContext::SetImageAnimationModeInternal(PRUint16 aMode)
// This hash table contains a list of background images
// so iterate over it and set the mode
mImageNotifiers.Enumerate(set_animation_mode, NS_INT32_TO_PTR(aMode));
mImageLoaders.Enumerate(set_animation_mode, NS_INT32_TO_PTR(aMode));
// Now walk the content tree and set the animation mode
// on all the images
@ -1167,26 +1167,26 @@ nsPresContext::SetFullZoom(float aZoom)
}
void
nsPresContext::SetImageNotifiers(nsIFrame* aTargetFrame,
nsImageLoadNotifier* aImageNotifiers)
nsPresContext::SetImageLoaders(nsIFrame* aTargetFrame,
nsImageLoader* aImageLoaders)
{
nsRefPtr<nsImageLoadNotifier> oldNotifiers;
mImageNotifiers.Get(aTargetFrame, getter_AddRefs(oldNotifiers));
nsRefPtr<nsImageLoader> oldLoaders;
mImageLoaders.Get(aTargetFrame, getter_AddRefs(oldLoaders));
if (aImageNotifiers) {
mImageNotifiers.Put(aTargetFrame, aImageNotifiers);
} else if (oldNotifiers) {
mImageNotifiers.Remove(aTargetFrame);
if (aImageLoaders) {
mImageLoaders.Put(aTargetFrame, aImageLoaders);
} else if (oldLoaders) {
mImageLoaders.Remove(aTargetFrame);
}
if (oldNotifiers)
oldNotifiers->Destroy();
if (oldLoaders)
oldLoaders->Destroy();
}
void
nsPresContext::StopImagesFor(nsIFrame* aTargetFrame)
{
SetImageNotifiers(aTargetFrame, nsnull);
SetImageLoaders(aTargetFrame, nsnull);
}
void

View File

@ -67,7 +67,7 @@
#include "gfxRect.h"
#include "nsRegion.h"
class nsImageLoadNotifier;
class nsImageLoader;
#ifdef IBMBIDI
class nsBidiPresUtils;
#endif // IBMBIDI
@ -364,8 +364,8 @@ public:
* aImage loads, where aImage is its background image. Only a single
* image will be tracked per frame.
*/
NS_HIDDEN_(void) SetImageNotifiers(nsIFrame* aTargetFrame,
nsImageLoadNotifier* aImageNotifiers);
NS_HIDDEN_(void) SetImageLoaders(nsIFrame* aTargetFrame,
nsImageLoader* aImageLoaders);
/**
* This method is called when a frame is being destroyed to
@ -764,7 +764,7 @@ protected:
nsILinkHandler* mLinkHandler; // [WEAK]
nsIAtom* mLangGroup; // [STRONG]
nsRefPtrHashtable<nsVoidPtrHashKey, nsImageLoadNotifier> mImageNotifiers;
nsRefPtrHashtable<nsVoidPtrHashKey, nsImageLoader> mImageLoaders;
nsWeakPtr mContainer;

View File

@ -119,7 +119,7 @@
#include "nsBoxLayoutState.h"
#include "nsBlockFrame.h"
#include "nsDisplayList.h"
#include "nsImageLoadNotifier.h"
#include "nsImageLoader.h"
#ifdef MOZ_SVG
#include "nsSVGIntegrationUtils.h"
@ -555,24 +555,24 @@ NS_IMETHODIMP nsFrame::DidSetStyleContext()
{
// Ensure that this frame gets invalidates (and, in the case of some
// 'border-image's, reflows) when images that affect it load.
nsRefPtr<nsImageLoadNotifier> notifierChain;
nsRefPtr<nsImageLoader> loaderChain;
const nsStyleBackground *background = GetStyleBackground();
imgIRequest *newBackgroundImage = background->mBackgroundImage;
if (newBackgroundImage) {
notifierChain = nsImageLoadNotifier::Create(this, newBackgroundImage,
PR_FALSE, notifierChain);
loaderChain = nsImageLoader::Create(this, newBackgroundImage,
PR_FALSE, loaderChain);
}
const nsStyleBorder *border = GetStyleBorder();
imgIRequest *newBorderImage = border->GetBorderImage();
if (newBorderImage) {
notifierChain = nsImageLoadNotifier::Create(this, newBorderImage,
border->ImageBorderDiffers(),
notifierChain);
loaderChain = nsImageLoader::Create(this, newBorderImage,
border->ImageBorderDiffers(),
loaderChain);
}
PresContext()->SetImageNotifiers(this, notifierChain);
PresContext()->SetImageLoaders(this, loaderChain);
return NS_OK;
}