From 28ad847496f785942283ca9f028c0e5e946f59d3 Mon Sep 17 00:00:00 2001 From: "nisheeth%netscape.com" Date: Sat, 1 Apr 2000 00:13:51 +0000 Subject: [PATCH] r=troy. Fix for bugs 8131, 13325. - We no longer display alternate content for broken images inside image - We only display the image loading icon during the initial load of an image not if its src attribute is changed via the DOM. - In AttributeChanged(), se don't call ContentChanged() on the document to reflow the image frame but call the parent frame's ReflowDirtyChild() method instead. --- layout/generic/nsImageFrame.cpp | 31 ++++++++++++++++----------- layout/generic/nsImageFrame.h | 3 ++- layout/html/base/src/nsImageFrame.cpp | 31 ++++++++++++++++----------- layout/html/base/src/nsImageFrame.h | 3 ++- 4 files changed, 42 insertions(+), 26 deletions(-) diff --git a/layout/generic/nsImageFrame.cpp b/layout/generic/nsImageFrame.cpp index c7435c2d537..f90eb20f200 100644 --- a/layout/generic/nsImageFrame.cpp +++ b/layout/generic/nsImageFrame.cpp @@ -152,6 +152,7 @@ nsImageFrame::Init(nsIPresContext* aPresContext, mImageLoader.Init(this, UpdateImageFrame, nsnull, baseURL, src); NS_IF_RELEASE(baseURL); + mInitialLoadCompleted = PR_FALSE; return rv; } @@ -176,9 +177,11 @@ nsImageFrame::UpdateImage(nsIPresContext* aPresContext, PRUint32 aStatus) nsCOMPtr presShell; aPresContext->GetShell(getter_AddRefs(presShell)); - if (NS_IMAGE_LOAD_STATUS_ERROR & aStatus) { - // We failed to load the image. Notify the pres shell - if (presShell) { + if (NS_IMAGE_LOAD_STATUS_ERROR & aStatus) { + nsAutoString usemap; + mContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::usemap, usemap); + // We failed to load the image. Notify the pres shell if we aren't an image map + if (presShell && usemap.Length() == 0) { presShell->CantRenderReplacedElement(aPresContext, this); } } @@ -482,7 +485,8 @@ nsImageFrame::Paint(nsIPresContext* aPresContext, if (nsnull == image) { // No image yet, or image load failed. Draw the alt-text and an icon // indicating the status - if (NS_FRAME_PAINT_LAYER_BACKGROUND == aWhichLayer) { + if (NS_FRAME_PAINT_LAYER_BACKGROUND == aWhichLayer && + !mInitialLoadCompleted) { DisplayAltFeedback(aPresContext, aRenderingContext, mImageLoader.GetLoadImageFailed() ? NS_ICON_BROKEN_IMAGE @@ -490,6 +494,7 @@ nsImageFrame::Paint(nsIPresContext* aPresContext, } } else { + mInitialLoadCompleted = PR_TRUE; if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) { // Now render the image into our content area (the area inside the // borders and padding) @@ -860,14 +865,16 @@ nsImageFrame::AttributeChanged(nsIPresContext* aPresContext, } } else { - // Force a reflow when the image size isn't already known - if (nsnull != mContent) { - nsIDocument* document = nsnull; - mContent->GetDocument(document); - if (nsnull != document) { - document->ContentChanged(mContent, nsnull); - NS_RELEASE(document); - } + // Dirty the image frame and ask its parent to reflow it + // when the image size isn't already known + if (mParent) { + nsCOMPtr presShell; + aPresContext->GetShell(getter_AddRefs(presShell)); + mState |= NS_FRAME_IS_DIRTY; + mParent->ReflowDirtyChild(presShell, (nsIFrame*) this); + } + else { + NS_ASSERTION(0, "No parent to pass the reflow request up to."); } } } diff --git a/layout/generic/nsImageFrame.h b/layout/generic/nsImageFrame.h index 203556bc46f..ffd5042c804 100644 --- a/layout/generic/nsImageFrame.h +++ b/layout/generic/nsImageFrame.h @@ -127,7 +127,8 @@ protected: nsHTMLImageLoader mImageLoader; nsImageMap* mImageMap; - PRBool mSizeFrozen; + PRPackedBool mSizeFrozen; + PRPackedBool mInitialLoadCompleted; nsMargin mBorderPadding; }; diff --git a/layout/html/base/src/nsImageFrame.cpp b/layout/html/base/src/nsImageFrame.cpp index c7435c2d537..f90eb20f200 100644 --- a/layout/html/base/src/nsImageFrame.cpp +++ b/layout/html/base/src/nsImageFrame.cpp @@ -152,6 +152,7 @@ nsImageFrame::Init(nsIPresContext* aPresContext, mImageLoader.Init(this, UpdateImageFrame, nsnull, baseURL, src); NS_IF_RELEASE(baseURL); + mInitialLoadCompleted = PR_FALSE; return rv; } @@ -176,9 +177,11 @@ nsImageFrame::UpdateImage(nsIPresContext* aPresContext, PRUint32 aStatus) nsCOMPtr presShell; aPresContext->GetShell(getter_AddRefs(presShell)); - if (NS_IMAGE_LOAD_STATUS_ERROR & aStatus) { - // We failed to load the image. Notify the pres shell - if (presShell) { + if (NS_IMAGE_LOAD_STATUS_ERROR & aStatus) { + nsAutoString usemap; + mContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::usemap, usemap); + // We failed to load the image. Notify the pres shell if we aren't an image map + if (presShell && usemap.Length() == 0) { presShell->CantRenderReplacedElement(aPresContext, this); } } @@ -482,7 +485,8 @@ nsImageFrame::Paint(nsIPresContext* aPresContext, if (nsnull == image) { // No image yet, or image load failed. Draw the alt-text and an icon // indicating the status - if (NS_FRAME_PAINT_LAYER_BACKGROUND == aWhichLayer) { + if (NS_FRAME_PAINT_LAYER_BACKGROUND == aWhichLayer && + !mInitialLoadCompleted) { DisplayAltFeedback(aPresContext, aRenderingContext, mImageLoader.GetLoadImageFailed() ? NS_ICON_BROKEN_IMAGE @@ -490,6 +494,7 @@ nsImageFrame::Paint(nsIPresContext* aPresContext, } } else { + mInitialLoadCompleted = PR_TRUE; if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) { // Now render the image into our content area (the area inside the // borders and padding) @@ -860,14 +865,16 @@ nsImageFrame::AttributeChanged(nsIPresContext* aPresContext, } } else { - // Force a reflow when the image size isn't already known - if (nsnull != mContent) { - nsIDocument* document = nsnull; - mContent->GetDocument(document); - if (nsnull != document) { - document->ContentChanged(mContent, nsnull); - NS_RELEASE(document); - } + // Dirty the image frame and ask its parent to reflow it + // when the image size isn't already known + if (mParent) { + nsCOMPtr presShell; + aPresContext->GetShell(getter_AddRefs(presShell)); + mState |= NS_FRAME_IS_DIRTY; + mParent->ReflowDirtyChild(presShell, (nsIFrame*) this); + } + else { + NS_ASSERTION(0, "No parent to pass the reflow request up to."); } } } diff --git a/layout/html/base/src/nsImageFrame.h b/layout/html/base/src/nsImageFrame.h index 203556bc46f..ffd5042c804 100644 --- a/layout/html/base/src/nsImageFrame.h +++ b/layout/html/base/src/nsImageFrame.h @@ -127,7 +127,8 @@ protected: nsHTMLImageLoader mImageLoader; nsImageMap* mImageMap; - PRBool mSizeFrozen; + PRPackedBool mSizeFrozen; + PRPackedBool mInitialLoadCompleted; nsMargin mBorderPadding; };