Added callback to image loading api

This commit is contained in:
kipp%netscape.com 1998-09-26 18:36:59 +00:00
parent 8aa1262f04
commit bb57a6d08f
14 changed files with 103 additions and 22 deletions

View File

@ -741,7 +741,8 @@ nsCSSRendering::PaintBackground(nsIPresContext& aPresContext,
transparentBG
? nsnull
: &aColor.mBackgroundColor,
aForFrame, PR_FALSE, loader);
aForFrame, nsnull,
PR_FALSE, loader);
if ((NS_OK != rv) || (nsnull == loader) ||
(loader->GetImage(image), (nsnull == image))) {
NS_IF_RELEASE(loader);

View File

@ -394,6 +394,7 @@ NS_IMETHODIMP
nsPresContext::StartLoadImage(const nsString& aURL,
const nscolor* aBackgroundColor,
nsIFrame* aTargetFrame,
nsFrameImageLoaderCB aCallBack,
PRBool aNeedSizeUpdate,
nsIFrameImageLoader*& aLoaderResult)
{
@ -447,7 +448,7 @@ nsPresContext::StartLoadImage(const nsString& aURL,
mImageLoaders.AppendElement(loader);
rv = loader->Init(this, mImageGroup, aURL, aBackgroundColor, aTargetFrame,
aNeedSizeUpdate);
aCallBack, aNeedSizeUpdate);
if (NS_OK != rv) {
mImageLoaders.RemoveElement(loader);
NS_RELEASE(loader);

View File

@ -22,6 +22,7 @@
#include "nsISupports.h"
#include "nsRect.h"
#include "nsColor.h"
#include "nsIFrameImageLoader.h"
struct nsFont;
@ -30,7 +31,6 @@ class nsIDocument;
class nsIDeviceContext;
class nsIFontMetrics;
class nsIFrame;
class nsIFrameImageLoader;
class nsIImageGroup;
class nsILinkHandler;
class nsIPresShell;
@ -162,6 +162,7 @@ public:
NS_IMETHOD StartLoadImage(const nsString& aURL,
const nscolor* aBackgroundColor,
nsIFrame* aTargetFrame,
nsFrameImageLoaderCB aCallBack,
PRBool aNeedSizeUpdate,
nsIFrameImageLoader*& aLoader) = 0;

View File

@ -33,6 +33,14 @@ struct nsSize;
#define NS_IFRAME_IMAGE_LOADER_IID \
{ 0xa9970300,0xe918,0x11d1,{0x89, 0xcc, 0x00, 0x60, 0x08, 0x91, 0x1b, 0x81} }
// Type of callback function used during image loading. The frame
// image loader will invoke this callback as notifications occur from
// the image library.
typedef nsresult (*nsFrameImageLoaderCB)(nsIPresContext& aPresContext,
nsIFrame* aFrame,
PRIntn aStatus);
/**
* Abstract interface for frame image loaders. Frame image loaders
* know how to respond to nsIImageRequestObserver notifications and
@ -46,6 +54,7 @@ public:
const nsString& aURL,
const nscolor* aBackgroundColor,
nsIFrame* aTargetFrame,
nsFrameImageLoaderCB aCallBack,
PRBool aNeedSizeUpdate) = 0;
NS_IMETHOD StopImageLoad() = 0;

View File

@ -22,6 +22,7 @@
#include "nsISupports.h"
#include "nsRect.h"
#include "nsColor.h"
#include "nsIFrameImageLoader.h"
struct nsFont;
@ -30,7 +31,6 @@ class nsIDocument;
class nsIDeviceContext;
class nsIFontMetrics;
class nsIFrame;
class nsIFrameImageLoader;
class nsIImageGroup;
class nsILinkHandler;
class nsIPresShell;
@ -162,6 +162,7 @@ public:
NS_IMETHOD StartLoadImage(const nsString& aURL,
const nscolor* aBackgroundColor,
nsIFrame* aTargetFrame,
nsFrameImageLoaderCB aCallBack,
PRBool aNeedSizeUpdate,
nsIFrameImageLoader*& aLoader) = 0;

View File

@ -22,6 +22,7 @@
#include "nsISupports.h"
#include "nsRect.h"
#include "nsColor.h"
#include "nsIFrameImageLoader.h"
struct nsFont;
@ -30,7 +31,6 @@ class nsIDocument;
class nsIDeviceContext;
class nsIFontMetrics;
class nsIFrame;
class nsIFrameImageLoader;
class nsIImageGroup;
class nsILinkHandler;
class nsIPresShell;
@ -162,6 +162,7 @@ public:
NS_IMETHOD StartLoadImage(const nsString& aURL,
const nscolor* aBackgroundColor,
nsIFrame* aTargetFrame,
nsFrameImageLoaderCB aCallBack,
PRBool aNeedSizeUpdate,
nsIFrameImageLoader*& aLoader) = 0;

View File

@ -48,6 +48,7 @@ public:
const nsString& aURL,
const nscolor* aBackgroundColor,
nsIFrame* aTargetFrame,
nsFrameImageLoaderCB aCallBack,
PRBool aNeedSizeUpdate);
NS_IMETHOD StopImageLoad();
NS_IMETHOD AbortImageLoad();
@ -71,6 +72,7 @@ protected:
nsSize mSize;
nsImageError mError;
nsIFrame* mTargetFrame;
nsFrameImageLoaderCB mCallBack;
nsIPresContext* mPresContext;
nsIImageRequest* mImageRequest;
PRUint8 mImageLoadStatus;

View File

@ -394,6 +394,7 @@ NS_IMETHODIMP
nsPresContext::StartLoadImage(const nsString& aURL,
const nscolor* aBackgroundColor,
nsIFrame* aTargetFrame,
nsFrameImageLoaderCB aCallBack,
PRBool aNeedSizeUpdate,
nsIFrameImageLoader*& aLoaderResult)
{
@ -447,7 +448,7 @@ nsPresContext::StartLoadImage(const nsString& aURL,
mImageLoaders.AppendElement(loader);
rv = loader->Init(this, mImageGroup, aURL, aBackgroundColor, aTargetFrame,
aNeedSizeUpdate);
aCallBack, aNeedSizeUpdate);
if (NS_OK != rv) {
mImageLoaders.RemoveElement(loader);
NS_RELEASE(loader);

View File

@ -60,6 +60,7 @@ public:
NS_IMETHOD StartLoadImage(const nsString& aURL,
const nscolor* aBackgroundColor,
nsIFrame* aTargetFrame,
nsFrameImageLoaderCB aCallBack,
PRBool aNeedSizeUpdate,
nsIFrameImageLoader*& aLoader);
NS_IMETHOD StopLoadImage(nsIFrame* aForFrame);

View File

@ -200,6 +200,7 @@ nsHTMLImageLoader::SetBaseHREF(const nsString& aBaseHREF)
nsresult
nsHTMLImageLoader::StartLoadImage(nsIPresContext* aPresContext,
nsIFrame* aForFrame,
nsFrameImageLoaderCB aCallBack,
PRBool aNeedSizeUpdate,
PRIntn& aLoadStatus)
{
@ -237,8 +238,8 @@ nsHTMLImageLoader::StartLoadImage(nsIPresContext* aPresContext,
if (nsnull == mImageLoader) {
// Start image loading. Note that we don't specify a background color
// so transparent images are always rendered using a transparency mask
rv = aPresContext->StartLoadImage(src, nsnull, aForFrame, aNeedSizeUpdate,
mImageLoader);
rv = aPresContext->StartLoadImage(src, nsnull, aForFrame, aCallBack,
aNeedSizeUpdate, mImageLoader);
if (NS_OK != rv) {
return rv;
}
@ -269,6 +270,8 @@ nsHTMLImageLoader::StartLoadImage(nsIPresContext* aPresContext,
void
nsHTMLImageLoader::GetDesiredSize(nsIPresContext* aPresContext,
const nsReflowState& aReflowState,
nsIFrame* aTargetFrame,
nsFrameImageLoaderCB aCallBack,
nsReflowMetrics& aDesiredSize)
{
nsSize styleSize;
@ -276,13 +279,15 @@ nsHTMLImageLoader::GetDesiredSize(nsIPresContext* aPresContext,
PRIntn loadStatus;
if (0 != ss) {
if (NS_SIZE_HAS_BOTH == ss) {
StartLoadImage(aPresContext, aReflowState.frame, PR_FALSE, loadStatus);
StartLoadImage(aPresContext, aTargetFrame, aCallBack,
PR_FALSE, loadStatus);
aDesiredSize.width = styleSize.width;
aDesiredSize.height = styleSize.height;
}
else {
// Preserve aspect ratio of image with unbound dimension.
StartLoadImage(aPresContext, aReflowState.frame, PR_TRUE, loadStatus);
StartLoadImage(aPresContext, aTargetFrame, aCallBack,
PR_TRUE, loadStatus);
if ((0 == (loadStatus & NS_IMAGE_LOAD_STATUS_SIZE_AVAILABLE)) ||
(nsnull == mImageLoader)) {
// Provide a dummy size for now; later on when the image size
@ -321,7 +326,7 @@ nsHTMLImageLoader::GetDesiredSize(nsIPresContext* aPresContext,
}
}
else {
StartLoadImage(aPresContext, aReflowState.frame, PR_TRUE, loadStatus);
StartLoadImage(aPresContext, aTargetFrame, aCallBack, PR_TRUE, loadStatus);
if ((0 == (loadStatus & NS_IMAGE_LOAD_STATUS_SIZE_AVAILABLE)) ||
(nsnull == mImageLoader)) {
// Provide a dummy size for now; later on when the image size
@ -393,6 +398,27 @@ ImageFrame::SizeOfWithoutThis(nsISizeOfHandler* aHandler) const
}
}
static nsresult
UpdateImageFrame(nsIPresContext& aPresContext, nsIFrame* aFrame,
PRIntn aStatus)
{
if (NS_IMAGE_LOAD_STATUS_SIZE_AVAILABLE & aStatus) {
// Now that the size is available, trigger a content-changed reflow
nsIContent* content = nsnull;
aFrame->GetContent(content);
if (nsnull != content) {
nsIDocument* document = nsnull;
content->GetDocument(document);
if (nsnull != document) {
document->ContentChanged(content, nsnull);
NS_RELEASE(document);
}
NS_RELEASE(content);
}
}
return NS_OK;
}
void
ImageFrame::GetDesiredSize(nsIPresContext* aPresContext,
const nsReflowState& aReflowState,
@ -427,7 +453,9 @@ ImageFrame::GetDesiredSize(nsIPresContext* aPresContext,
mImageLoader.SetBaseHREF(base);
}
}
mImageLoader.GetDesiredSize(aPresContext, aReflowState, aDesiredSize);
mImageLoader.GetDesiredSize(aPresContext, aReflowState,
this, UpdateImageFrame,
aDesiredSize);
}
}
@ -901,7 +929,8 @@ ImageFrame::ContentChanged(nsIPresShell* aShell,
// Fire up a new image load request
PRIntn loadStatus;
mImageLoader.SetURL(newSRC);
mImageLoader.StartLoadImage(aPresContext, this, PR_FALSE, loadStatus);
mImageLoader.StartLoadImage(aPresContext, this, nsnull,
PR_FALSE, loadStatus);
NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS,
("ImageFrame::ContentChanged: loadImage status=%x",

View File

@ -67,11 +67,14 @@ public:
nsresult StartLoadImage(nsIPresContext* aPresContext,
nsIFrame* aForFrame,
nsFrameImageLoaderCB aCallBack,
PRBool aNeedSizeUpdate,
PRIntn& aLoadStatus);
void GetDesiredSize(nsIPresContext* aPresContext,
const nsReflowState& aReflowState,
nsIFrame* aTargetFrame,
nsFrameImageLoaderCB aCallBack,
nsReflowMetrics& aDesiredSize);
PRBool GetLoadImageFailed() {

View File

@ -200,6 +200,7 @@ nsHTMLImageLoader::SetBaseHREF(const nsString& aBaseHREF)
nsresult
nsHTMLImageLoader::StartLoadImage(nsIPresContext* aPresContext,
nsIFrame* aForFrame,
nsFrameImageLoaderCB aCallBack,
PRBool aNeedSizeUpdate,
PRIntn& aLoadStatus)
{
@ -237,8 +238,8 @@ nsHTMLImageLoader::StartLoadImage(nsIPresContext* aPresContext,
if (nsnull == mImageLoader) {
// Start image loading. Note that we don't specify a background color
// so transparent images are always rendered using a transparency mask
rv = aPresContext->StartLoadImage(src, nsnull, aForFrame, aNeedSizeUpdate,
mImageLoader);
rv = aPresContext->StartLoadImage(src, nsnull, aForFrame, aCallBack,
aNeedSizeUpdate, mImageLoader);
if (NS_OK != rv) {
return rv;
}
@ -269,6 +270,8 @@ nsHTMLImageLoader::StartLoadImage(nsIPresContext* aPresContext,
void
nsHTMLImageLoader::GetDesiredSize(nsIPresContext* aPresContext,
const nsReflowState& aReflowState,
nsIFrame* aTargetFrame,
nsFrameImageLoaderCB aCallBack,
nsReflowMetrics& aDesiredSize)
{
nsSize styleSize;
@ -276,13 +279,15 @@ nsHTMLImageLoader::GetDesiredSize(nsIPresContext* aPresContext,
PRIntn loadStatus;
if (0 != ss) {
if (NS_SIZE_HAS_BOTH == ss) {
StartLoadImage(aPresContext, aReflowState.frame, PR_FALSE, loadStatus);
StartLoadImage(aPresContext, aTargetFrame, aCallBack,
PR_FALSE, loadStatus);
aDesiredSize.width = styleSize.width;
aDesiredSize.height = styleSize.height;
}
else {
// Preserve aspect ratio of image with unbound dimension.
StartLoadImage(aPresContext, aReflowState.frame, PR_TRUE, loadStatus);
StartLoadImage(aPresContext, aTargetFrame, aCallBack,
PR_TRUE, loadStatus);
if ((0 == (loadStatus & NS_IMAGE_LOAD_STATUS_SIZE_AVAILABLE)) ||
(nsnull == mImageLoader)) {
// Provide a dummy size for now; later on when the image size
@ -321,7 +326,7 @@ nsHTMLImageLoader::GetDesiredSize(nsIPresContext* aPresContext,
}
}
else {
StartLoadImage(aPresContext, aReflowState.frame, PR_TRUE, loadStatus);
StartLoadImage(aPresContext, aTargetFrame, aCallBack, PR_TRUE, loadStatus);
if ((0 == (loadStatus & NS_IMAGE_LOAD_STATUS_SIZE_AVAILABLE)) ||
(nsnull == mImageLoader)) {
// Provide a dummy size for now; later on when the image size
@ -393,6 +398,27 @@ ImageFrame::SizeOfWithoutThis(nsISizeOfHandler* aHandler) const
}
}
static nsresult
UpdateImageFrame(nsIPresContext& aPresContext, nsIFrame* aFrame,
PRIntn aStatus)
{
if (NS_IMAGE_LOAD_STATUS_SIZE_AVAILABLE & aStatus) {
// Now that the size is available, trigger a content-changed reflow
nsIContent* content = nsnull;
aFrame->GetContent(content);
if (nsnull != content) {
nsIDocument* document = nsnull;
content->GetDocument(document);
if (nsnull != document) {
document->ContentChanged(content, nsnull);
NS_RELEASE(document);
}
NS_RELEASE(content);
}
}
return NS_OK;
}
void
ImageFrame::GetDesiredSize(nsIPresContext* aPresContext,
const nsReflowState& aReflowState,
@ -427,7 +453,9 @@ ImageFrame::GetDesiredSize(nsIPresContext* aPresContext,
mImageLoader.SetBaseHREF(base);
}
}
mImageLoader.GetDesiredSize(aPresContext, aReflowState, aDesiredSize);
mImageLoader.GetDesiredSize(aPresContext, aReflowState,
this, UpdateImageFrame,
aDesiredSize);
}
}
@ -901,7 +929,8 @@ ImageFrame::ContentChanged(nsIPresShell* aShell,
// Fire up a new image load request
PRIntn loadStatus;
mImageLoader.SetURL(newSRC);
mImageLoader.StartLoadImage(aPresContext, this, PR_FALSE, loadStatus);
mImageLoader.StartLoadImage(aPresContext, this, nsnull,
PR_FALSE, loadStatus);
NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS,
("ImageFrame::ContentChanged: loadImage status=%x",

View File

@ -317,7 +317,8 @@ nsButtonControlFrame::GetDesiredSize(nsIPresContext* aPresContext,
if (NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttribute("SRC", src)) {
mImageLoader.SetURL(src);
}
mImageLoader.GetDesiredSize(aPresContext, aReflowState, aDesiredLayoutSize);
mImageLoader.GetDesiredSize(aPresContext, aReflowState, this, nsnull,
aDesiredLayoutSize);
} else { // there is a widget
nsSize styleSize;
GetStyleSize(*aPresContext, aReflowState, styleSize);

View File

@ -741,7 +741,8 @@ nsCSSRendering::PaintBackground(nsIPresContext& aPresContext,
transparentBG
? nsnull
: &aColor.mBackgroundColor,
aForFrame, PR_FALSE, loader);
aForFrame, nsnull,
PR_FALSE, loader);
if ((NS_OK != rv) || (nsnull == loader) ||
(loader->GetImage(image), (nsnull == image))) {
NS_IF_RELEASE(loader);