diff --git a/mozilla/content/base/src/nsStyleSet.cpp b/mozilla/content/base/src/nsStyleSet.cpp index ee43b48735f..f29f22de70e 100644 --- a/mozilla/content/base/src/nsStyleSet.cpp +++ b/mozilla/content/base/src/nsStyleSet.cpp @@ -131,6 +131,10 @@ public: nsIStyleSheet* aStyleSheet, nsIStyleRule* aStyleRule); + // Notification that we were unable to render a replaced element. + NS_IMETHOD CantRenderReplacedElement(nsIPresContext* aPresContext, + nsIFrame* aFrame); + virtual void List(FILE* out = stdout, PRInt32 aIndent = 0); private: @@ -809,6 +813,13 @@ StyleSetImpl::StyleRuleRemoved(nsIPresContext* aPresContext, return mFrameConstructor->StyleRuleRemoved(aPresContext, aStyleSheet, aStyleRule); } +NS_IMETHODIMP +StyleSetImpl::CantRenderReplacedElement(nsIPresContext* aPresContext, + nsIFrame* aFrame) +{ + return mFrameConstructor->CantRenderReplacedElement(aPresContext, aFrame); +} + void StyleSetImpl::List(FILE* out, PRInt32 aIndent, nsISupportsArray* aSheets) { PRInt32 count = ((nsnull != aSheets) ? aSheets->Count() : 0); diff --git a/mozilla/content/html/style/src/nsHTMLStyleSheet.cpp b/mozilla/content/html/style/src/nsHTMLStyleSheet.cpp index 299ce60ec47..caedf5ea705 100644 --- a/mozilla/content/html/style/src/nsHTMLStyleSheet.cpp +++ b/mozilla/content/html/style/src/nsHTMLStyleSheet.cpp @@ -50,6 +50,8 @@ #include "nsIListControlFrame.h" #include "nsDeque.h" #include "nsIDOMCharacterData.h" +#include "nsIDOMHTMLImageElement.h" +#include "nsITextContent.h" #ifdef INCLUDE_XUL #include "nsXULAtoms.h" @@ -74,6 +76,8 @@ static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID); static NS_DEFINE_IID(kIDOMHTMLSelectElementIID, NS_IDOMHTMLSELECTELEMENT_IID); static NS_DEFINE_IID(kIComboboxControlFrameIID, NS_ICOMBOBOXCONTROLFRAME_IID); static NS_DEFINE_IID(kIListControlFrameIID, NS_ILISTCONTROLFRAME_IID); +static NS_DEFINE_IID(kIDOMHTMLImageElementIID, NS_IDOMHTMLIMAGEELEMENT_IID); +static NS_DEFINE_IID(kIDOMCharacterDataIID, NS_IDOMCHARACTERDATA_IID); class HTMLAnchorRule : public nsIStyleRule { public: @@ -384,6 +388,10 @@ public: NS_IMETHOD StyleRuleRemoved(nsIPresContext* aPresContext, nsIStyleSheet* aStyleSheet, nsIStyleRule* aStyleRule); + + // Notification that we were unable to render a replaced element. + NS_IMETHOD CantRenderReplacedElement(nsIPresContext* aPresContext, + nsIFrame* aFrame); virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const; @@ -1966,8 +1974,6 @@ HTMLStyleSheetImpl::ConstructTableCellFrameOnly(nsIPresContext* aPresContext, return rv; } -static NS_DEFINE_IID(kIDOMCharacerDataIID, NS_IDOMCHARACTERDATA_IID); - // This is only called by table row groups and rows. It allows children that are not // table related to have a cell wrapped around them. nsresult @@ -2055,7 +2061,7 @@ HTMLStyleSheetImpl::TableProcessChild(nsIPresContext* aPresContext, } else { // wrap it in a table cell, row, row group, table if it is not whitespace PRBool needCell = PR_TRUE; nsIDOMCharacterData* domData = nsnull; - nsresult rv2 = aChildContent->QueryInterface(kIDOMCharacerDataIID, (void**)&domData); + nsresult rv2 = aChildContent->QueryInterface(kIDOMCharacterDataIID, (void**)&domData); if ((NS_OK == rv2) && (nsnull != domData)) { nsString charData; domData->GetData(charData); @@ -4425,6 +4431,83 @@ HTMLStyleSheetImpl::StyleRuleRemoved(nsIPresContext* aPresContext, return NS_OK; } +NS_IMETHODIMP +HTMLStyleSheetImpl::CantRenderReplacedElement(nsIPresContext* aPresContext, + nsIFrame* aFrame) +{ + nsIContent* content; + nsIAtom* tag; + nsIFrame* parentFrame; + + aFrame->GetParent(parentFrame); + + // Get the content object associated with aFrame + aFrame->GetContent(content); + NS_ASSERTION(nsnull != content, "null content object"); + content->GetTag(tag); + if (nsHTMLAtoms::img == tag) { + // The "alt" attribute specifies alternate text that is rendered + // when the image cannot be displayed + nsIDOMHTMLImageElement* element; + if (NS_SUCCEEDED(content->QueryInterface(kIDOMHTMLImageElementIID, (void**)&element))) { + nsAutoString altText; + + element->GetAlt(altText); + if (altText.Length() > 0) { + // Create a text content element for the alt-text + nsIContent* altTextContent; + nsIDOMCharacterData* domData; + + NS_NewTextNode(&altTextContent); + altTextContent->QueryInterface(kIDOMCharacterDataIID, (void**)&domData); + domData->SetData(altText); + NS_RELEASE(domData); + + // Create a text frame to display the alt-text + nsIFrame* textFrame; + NS_NewTextFrame(textFrame); + + // Use a special pseudo element style context for text + nsIStyleContext* textStyleContext; + nsIStyleContext* parentStyleContext; + nsIContent* parentContent; + + parentFrame->GetContent(parentContent); + parentFrame->GetStyleContext(parentStyleContext); + textStyleContext = aPresContext->ResolvePseudoStyleContextFor + (parentContent, nsHTMLAtoms::textPseudo, parentStyleContext); + NS_RELEASE(parentStyleContext); + NS_RELEASE(parentContent); + + // Initialize the text frame + textFrame->Init(*aPresContext, altTextContent, parentFrame, textStyleContext); + NS_RELEASE(textStyleContext); + NS_RELEASE(altTextContent); + + // Get the previous sibling frame + nsIFrame* firstChild; + parentFrame->FirstChild(nsnull, firstChild); + nsFrameList frameList(firstChild); + nsIFrame* prevSibling = frameList.GetPrevSiblingFor(aFrame); + + // Delete the current frame and insert the new frame + nsIPresShell* presShell = aPresContext->GetShell(); + parentFrame->RemoveFrame(*aPresContext, *presShell, nsnull, aFrame); + parentFrame->InsertFrames(*aPresContext, *presShell, nsnull, prevSibling, textFrame); + NS_RELEASE(presShell); + } + } + + } else if (nsHTMLAtoms::object == tag) { + ; + } else { + NS_ASSERTION(PR_FALSE, "unexpected tag"); + } + + NS_IF_RELEASE(tag); + NS_IF_RELEASE(content); + return NS_OK; +} void HTMLStyleSheetImpl::List(FILE* out, PRInt32 aIndent) const { diff --git a/mozilla/layout/base/nsCSSRendering.cpp b/mozilla/layout/base/nsCSSRendering.cpp index dbc6ed9dd45..0505a193375 100644 --- a/mozilla/layout/base/nsCSSRendering.cpp +++ b/mozilla/layout/base/nsCSSRendering.cpp @@ -1682,7 +1682,7 @@ nsCSSRendering::PaintBackground(nsIPresContext& aPresContext, ? nsnull : &aColor.mBackgroundColor, aForFrame, nsnull, - PR_FALSE, loader); + PR_FALSE, PR_FALSE, loader); if ((NS_OK != rv) || (nsnull == loader) || (loader->GetImage(image), (nsnull == image))) { NS_IF_RELEASE(loader); diff --git a/mozilla/layout/base/nsPresContext.cpp b/mozilla/layout/base/nsPresContext.cpp index dc4743477be..79a806e5b2f 100644 --- a/mozilla/layout/base/nsPresContext.cpp +++ b/mozilla/layout/base/nsPresContext.cpp @@ -492,6 +492,7 @@ nsPresContext::StartLoadImage(const nsString& aURL, nsIFrame* aTargetFrame, nsFrameImageLoaderCB aCallBack, PRBool aNeedSizeUpdate, + PRBool aNeedErrorNotification, nsIFrameImageLoader*& aLoaderResult) { if (mStopped) { @@ -563,7 +564,7 @@ nsPresContext::StartLoadImage(const nsString& aURL, mImageLoaders.AppendElement(loader); rv = loader->Init(this, mImageGroup, aURL, aBackgroundColor, aTargetFrame, - aCallBack, aNeedSizeUpdate); + aCallBack, aNeedSizeUpdate, aNeedErrorNotification); if (NS_OK != rv) { mImageLoaders.RemoveElement(loader); NS_RELEASE(loader); diff --git a/mozilla/layout/base/nsPresContext.h b/mozilla/layout/base/nsPresContext.h index 43182d4894e..bd1c051cdf3 100644 --- a/mozilla/layout/base/nsPresContext.h +++ b/mozilla/layout/base/nsPresContext.h @@ -176,6 +176,7 @@ public: nsIFrame* aTargetFrame, nsFrameImageLoaderCB aCallBack, PRBool aNeedSizeUpdate, + PRBool aNeedErrorNotification, nsIFrameImageLoader*& aLoader) = 0; /** diff --git a/mozilla/layout/base/public/nsIFrameImageLoader.h b/mozilla/layout/base/public/nsIFrameImageLoader.h index 62dce9347fa..2fe424e73d9 100644 --- a/mozilla/layout/base/public/nsIFrameImageLoader.h +++ b/mozilla/layout/base/public/nsIFrameImageLoader.h @@ -54,7 +54,8 @@ public: const nscolor* aBackgroundColor, nsIFrame* aTargetFrame, nsFrameImageLoaderCB aCallBack, - PRBool aNeedSizeUpdate) = 0; + PRBool aNeedSizeUpdate, + PRBool aNeedErrorNotification) = 0; NS_IMETHOD StopImageLoad() = 0; @@ -72,10 +73,11 @@ public: }; // Image load status bit values -#define NS_IMAGE_LOAD_STATUS_NONE 0x0 -#define NS_IMAGE_LOAD_STATUS_SIZE_REQUESTED 0x1 -#define NS_IMAGE_LOAD_STATUS_SIZE_AVAILABLE 0x2 -#define NS_IMAGE_LOAD_STATUS_IMAGE_READY 0x4 -#define NS_IMAGE_LOAD_STATUS_ERROR 0x8 +#define NS_IMAGE_LOAD_STATUS_NONE 0x0 +#define NS_IMAGE_LOAD_STATUS_SIZE_REQUESTED 0x1 +#define NS_IMAGE_LOAD_STATUS_SIZE_AVAILABLE 0x2 +#define NS_IMAGE_LOAD_STATUS_IMAGE_READY 0x4 +#define NS_IMAGE_LOAD_STATUS_ERROR 0x8 +#define NS_IMAGE_LOAD_STATUS_ERROR_REQUESTED 0x10 #endif /* nsIFrameImageLoader_h___ */ diff --git a/mozilla/layout/base/public/nsIPresContext.h b/mozilla/layout/base/public/nsIPresContext.h index 43182d4894e..bd1c051cdf3 100644 --- a/mozilla/layout/base/public/nsIPresContext.h +++ b/mozilla/layout/base/public/nsIPresContext.h @@ -176,6 +176,7 @@ public: nsIFrame* aTargetFrame, nsFrameImageLoaderCB aCallBack, PRBool aNeedSizeUpdate, + PRBool aNeedErrorNotification, nsIFrameImageLoader*& aLoader) = 0; /** diff --git a/mozilla/layout/base/public/nsIStyleFrameConstruction.h b/mozilla/layout/base/public/nsIStyleFrameConstruction.h index 1bc0574979f..44ec8bed354 100644 --- a/mozilla/layout/base/public/nsIStyleFrameConstruction.h +++ b/mozilla/layout/base/public/nsIStyleFrameConstruction.h @@ -84,6 +84,10 @@ public: NS_IMETHOD StyleRuleRemoved(nsIPresContext* aPresContext, nsIStyleSheet* aStyleSheet, nsIStyleRule* aStyleRule) = 0; + + // Notification that we were unable to render a replaced element. + NS_IMETHOD CantRenderReplacedElement(nsIPresContext* aPresContext, + nsIFrame* aFrame) = 0; }; #endif /* nsIStyleFrameConstruction_h___ */ diff --git a/mozilla/layout/base/public/nsIStyleSet.h b/mozilla/layout/base/public/nsIStyleSet.h index a6ebc31ec76..7f20bab7437 100644 --- a/mozilla/layout/base/public/nsIStyleSet.h +++ b/mozilla/layout/base/public/nsIStyleSet.h @@ -137,6 +137,14 @@ public: nsIStyleSheet* aStyleSheet, nsIStyleRule* aStyleRule) = 0; + // Notification that we were unable to render a replaced element. + // Called when the replaced element can not be rendered, and we should + // instead render the element's contents. + // The content object associated with aFrame should either be a IMG + // element or an OBJECT element. + NS_IMETHOD CantRenderReplacedElement(nsIPresContext* aPresContext, + nsIFrame* aFrame) = 0; + virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) = 0; virtual void ListContexts(nsIStyleContext* aRootContext, FILE* out = stdout, PRInt32 aIndent = 0) = 0; }; diff --git a/mozilla/layout/base/public/nsPresContext.h b/mozilla/layout/base/public/nsPresContext.h index 43182d4894e..bd1c051cdf3 100644 --- a/mozilla/layout/base/public/nsPresContext.h +++ b/mozilla/layout/base/public/nsPresContext.h @@ -176,6 +176,7 @@ public: nsIFrame* aTargetFrame, nsFrameImageLoaderCB aCallBack, PRBool aNeedSizeUpdate, + PRBool aNeedErrorNotification, nsIFrameImageLoader*& aLoader) = 0; /** diff --git a/mozilla/layout/base/src/nsFrameImageLoader.cpp b/mozilla/layout/base/src/nsFrameImageLoader.cpp index 1cdaca1994d..595d6b4bc15 100644 --- a/mozilla/layout/base/src/nsFrameImageLoader.cpp +++ b/mozilla/layout/base/src/nsFrameImageLoader.cpp @@ -112,7 +112,8 @@ nsFrameImageLoader::Init(nsIPresContext* aPresContext, const nscolor* aBackgroundColor, nsIFrame* aTargetFrame, nsFrameImageLoaderCB aCallBack, - PRBool aNeedSizeUpdate) + PRBool aNeedSizeUpdate, + PRBool aNeedErrorNotification) { NS_PRECONDITION(nsnull != aPresContext, "null ptr"); NS_PRECONDITION(nsnull == mPresContext, "double init"); @@ -130,6 +131,9 @@ nsFrameImageLoader::Init(nsIPresContext* aPresContext, if (aNeedSizeUpdate) { mImageLoadStatus = NS_IMAGE_LOAD_STATUS_SIZE_REQUESTED; } + if (aNeedErrorNotification) { + mImageLoadStatus |= NS_IMAGE_LOAD_STATUS_ERROR_REQUESTED; + } // Translate url to a C string mURL = aURL; @@ -195,7 +199,9 @@ nsFrameImageLoader::Notify(nsIImageRequest *aImageRequest, mSize.height = aParam2; mImageLoadStatus |= NS_IMAGE_LOAD_STATUS_SIZE_AVAILABLE; if (0 != (mImageLoadStatus & NS_IMAGE_LOAD_STATUS_SIZE_REQUESTED)) { - ReflowFrame(); + if (nsnull != mCallBack) { + (*mCallBack)(*mPresContext, mTargetFrame, mImageLoadStatus); + } } break; @@ -267,8 +273,11 @@ nsFrameImageLoader::NotifyError(nsIImageRequest *aImageRequest, mError = aErrorType; mImageLoadStatus |= NS_IMAGE_LOAD_STATUS_ERROR; - if (0 != (mImageLoadStatus & NS_IMAGE_LOAD_STATUS_SIZE_REQUESTED)) { - ReflowFrame(); + if (0 != (mImageLoadStatus & (NS_IMAGE_LOAD_STATUS_SIZE_REQUESTED | + NS_IMAGE_LOAD_STATUS_ERROR_REQUESTED))) { + if (nsnull != mCallBack) { + (*mCallBack)(*mPresContext, mTargetFrame, mImageLoadStatus); + } } else { DamageRepairFrame(nsnull); @@ -345,18 +354,6 @@ nsFrameImageLoader::DamageRepairFrame(const nsRect* aDamageRect) NS_RELEASE(vm); } -void -nsFrameImageLoader::ReflowFrame() -{ - PR_LOG(gFrameImageLoaderLMI, PR_LOG_DEBUG, - ("nsFrameImageLoader::ReflowFrame frame=%p status=%x", - mTargetFrame, mImageLoadStatus)); - - if (nsnull != mCallBack) { - (*mCallBack)(*mPresContext, mTargetFrame, mImageLoadStatus); - } -} - NS_METHOD nsFrameImageLoader::GetTargetFrame(nsIFrame*& aFrameResult) const { diff --git a/mozilla/layout/base/src/nsFrameImageLoader.h b/mozilla/layout/base/src/nsFrameImageLoader.h index 7976291afa4..f1ac46e5208 100644 --- a/mozilla/layout/base/src/nsFrameImageLoader.h +++ b/mozilla/layout/base/src/nsFrameImageLoader.h @@ -49,7 +49,8 @@ public: const nscolor* aBackgroundColor, nsIFrame* aTargetFrame, nsFrameImageLoaderCB aCallBack, - PRBool aNeedSizeUpdate); + PRBool aNeedSizeUpdate, + PRBool aNeedErrorNotification); NS_IMETHOD StopImageLoad(); NS_IMETHOD AbortImageLoad(); NS_IMETHOD GetTargetFrame(nsIFrame*& aFrameResult) const; @@ -62,8 +63,6 @@ protected: nsFrameImageLoader(); ~nsFrameImageLoader(); - void ReflowFrame(); - void DamageRepairFrame(const nsRect* aDamageRect); nsString mURL; diff --git a/mozilla/layout/base/src/nsPresContext.cpp b/mozilla/layout/base/src/nsPresContext.cpp index dc4743477be..79a806e5b2f 100644 --- a/mozilla/layout/base/src/nsPresContext.cpp +++ b/mozilla/layout/base/src/nsPresContext.cpp @@ -492,6 +492,7 @@ nsPresContext::StartLoadImage(const nsString& aURL, nsIFrame* aTargetFrame, nsFrameImageLoaderCB aCallBack, PRBool aNeedSizeUpdate, + PRBool aNeedErrorNotification, nsIFrameImageLoader*& aLoaderResult) { if (mStopped) { @@ -563,7 +564,7 @@ nsPresContext::StartLoadImage(const nsString& aURL, mImageLoaders.AppendElement(loader); rv = loader->Init(this, mImageGroup, aURL, aBackgroundColor, aTargetFrame, - aCallBack, aNeedSizeUpdate); + aCallBack, aNeedSizeUpdate, aNeedErrorNotification); if (NS_OK != rv) { mImageLoaders.RemoveElement(loader); NS_RELEASE(loader); diff --git a/mozilla/layout/base/src/nsPresContext.h b/mozilla/layout/base/src/nsPresContext.h index 067db6ebeea..64c15e02579 100644 --- a/mozilla/layout/base/src/nsPresContext.h +++ b/mozilla/layout/base/src/nsPresContext.h @@ -72,6 +72,7 @@ public: nsIFrame* aTargetFrame, nsFrameImageLoaderCB aCallBack, PRBool aNeedSizeUpdate, + PRBool aNeedErrorNotification, nsIFrameImageLoader*& aLoader); NS_IMETHOD StopLoadImage(nsIFrame* aForFrame); NS_IMETHOD SetContainer(nsISupports* aContainer); diff --git a/mozilla/layout/base/src/nsStyleSet.cpp b/mozilla/layout/base/src/nsStyleSet.cpp index ee43b48735f..f29f22de70e 100644 --- a/mozilla/layout/base/src/nsStyleSet.cpp +++ b/mozilla/layout/base/src/nsStyleSet.cpp @@ -131,6 +131,10 @@ public: nsIStyleSheet* aStyleSheet, nsIStyleRule* aStyleRule); + // Notification that we were unable to render a replaced element. + NS_IMETHOD CantRenderReplacedElement(nsIPresContext* aPresContext, + nsIFrame* aFrame); + virtual void List(FILE* out = stdout, PRInt32 aIndent = 0); private: @@ -809,6 +813,13 @@ StyleSetImpl::StyleRuleRemoved(nsIPresContext* aPresContext, return mFrameConstructor->StyleRuleRemoved(aPresContext, aStyleSheet, aStyleRule); } +NS_IMETHODIMP +StyleSetImpl::CantRenderReplacedElement(nsIPresContext* aPresContext, + nsIFrame* aFrame) +{ + return mFrameConstructor->CantRenderReplacedElement(aPresContext, aFrame); +} + void StyleSetImpl::List(FILE* out, PRInt32 aIndent, nsISupportsArray* aSheets) { PRInt32 count = ((nsnull != aSheets) ? aSheets->Count() : 0); diff --git a/mozilla/layout/generic/nsImageFrame.cpp b/mozilla/layout/generic/nsImageFrame.cpp index 12ba4811606..55198a4b1f7 100644 --- a/mozilla/layout/generic/nsImageFrame.cpp +++ b/mozilla/layout/generic/nsImageFrame.cpp @@ -47,6 +47,7 @@ #include "nsINameSpaceManager.h" #include "nsTextFragment.h" #include "nsIDOMHTMLMapElement.h" +#include "nsIStyleSet.h" #ifndef _WIN32 #define BROKEN_IMAGE_URL "resource:/res/html/broken-image.gif" @@ -156,7 +157,7 @@ nsHTMLImageLoader::StartLoadImage(nsIPresContext* aPresContext, // 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, aCallBack, - aNeedSizeUpdate, mImageLoader); + aNeedSizeUpdate, PR_TRUE, mImageLoader); if ((NS_OK != rv) || (nsnull == mImageLoader)) { return rv; } @@ -370,6 +371,17 @@ UpdateImageFrame(nsIPresContext& aPresContext, nsIFrame* aFrame, } NS_RELEASE(content); } + } else if (NS_IMAGE_LOAD_STATUS_ERROR & aStatus) { +#if 0 + // We failed to load the image. Notify the style system + nsIPresShell* presShell = aPresContext.GetShell(); + nsIStyleSet* styleSet = presShell->GetStyleSet(); + styleSet->CantRenderReplacedElement(&aPresContext, aFrame); + NS_RELEASE(styleSet); + NS_RELEASE(presShell); +#else + ; +#endif } return NS_OK; } diff --git a/mozilla/layout/html/base/src/nsImageFrame.cpp b/mozilla/layout/html/base/src/nsImageFrame.cpp index 12ba4811606..55198a4b1f7 100644 --- a/mozilla/layout/html/base/src/nsImageFrame.cpp +++ b/mozilla/layout/html/base/src/nsImageFrame.cpp @@ -47,6 +47,7 @@ #include "nsINameSpaceManager.h" #include "nsTextFragment.h" #include "nsIDOMHTMLMapElement.h" +#include "nsIStyleSet.h" #ifndef _WIN32 #define BROKEN_IMAGE_URL "resource:/res/html/broken-image.gif" @@ -156,7 +157,7 @@ nsHTMLImageLoader::StartLoadImage(nsIPresContext* aPresContext, // 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, aCallBack, - aNeedSizeUpdate, mImageLoader); + aNeedSizeUpdate, PR_TRUE, mImageLoader); if ((NS_OK != rv) || (nsnull == mImageLoader)) { return rv; } @@ -370,6 +371,17 @@ UpdateImageFrame(nsIPresContext& aPresContext, nsIFrame* aFrame, } NS_RELEASE(content); } + } else if (NS_IMAGE_LOAD_STATUS_ERROR & aStatus) { +#if 0 + // We failed to load the image. Notify the style system + nsIPresShell* presShell = aPresContext.GetShell(); + nsIStyleSet* styleSet = presShell->GetStyleSet(); + styleSet->CantRenderReplacedElement(&aPresContext, aFrame); + NS_RELEASE(styleSet); + NS_RELEASE(presShell); +#else + ; +#endif } return NS_OK; } diff --git a/mozilla/layout/html/style/src/nsCSSRendering.cpp b/mozilla/layout/html/style/src/nsCSSRendering.cpp index dbc6ed9dd45..0505a193375 100644 --- a/mozilla/layout/html/style/src/nsCSSRendering.cpp +++ b/mozilla/layout/html/style/src/nsCSSRendering.cpp @@ -1682,7 +1682,7 @@ nsCSSRendering::PaintBackground(nsIPresContext& aPresContext, ? nsnull : &aColor.mBackgroundColor, aForFrame, nsnull, - PR_FALSE, loader); + PR_FALSE, PR_FALSE, loader); if ((NS_OK != rv) || (nsnull == loader) || (loader->GetImage(image), (nsnull == image))) { NS_IF_RELEASE(loader); diff --git a/mozilla/layout/html/style/src/nsHTMLStyleSheet.cpp b/mozilla/layout/html/style/src/nsHTMLStyleSheet.cpp index 299ce60ec47..caedf5ea705 100644 --- a/mozilla/layout/html/style/src/nsHTMLStyleSheet.cpp +++ b/mozilla/layout/html/style/src/nsHTMLStyleSheet.cpp @@ -50,6 +50,8 @@ #include "nsIListControlFrame.h" #include "nsDeque.h" #include "nsIDOMCharacterData.h" +#include "nsIDOMHTMLImageElement.h" +#include "nsITextContent.h" #ifdef INCLUDE_XUL #include "nsXULAtoms.h" @@ -74,6 +76,8 @@ static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID); static NS_DEFINE_IID(kIDOMHTMLSelectElementIID, NS_IDOMHTMLSELECTELEMENT_IID); static NS_DEFINE_IID(kIComboboxControlFrameIID, NS_ICOMBOBOXCONTROLFRAME_IID); static NS_DEFINE_IID(kIListControlFrameIID, NS_ILISTCONTROLFRAME_IID); +static NS_DEFINE_IID(kIDOMHTMLImageElementIID, NS_IDOMHTMLIMAGEELEMENT_IID); +static NS_DEFINE_IID(kIDOMCharacterDataIID, NS_IDOMCHARACTERDATA_IID); class HTMLAnchorRule : public nsIStyleRule { public: @@ -384,6 +388,10 @@ public: NS_IMETHOD StyleRuleRemoved(nsIPresContext* aPresContext, nsIStyleSheet* aStyleSheet, nsIStyleRule* aStyleRule); + + // Notification that we were unable to render a replaced element. + NS_IMETHOD CantRenderReplacedElement(nsIPresContext* aPresContext, + nsIFrame* aFrame); virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const; @@ -1966,8 +1974,6 @@ HTMLStyleSheetImpl::ConstructTableCellFrameOnly(nsIPresContext* aPresContext, return rv; } -static NS_DEFINE_IID(kIDOMCharacerDataIID, NS_IDOMCHARACTERDATA_IID); - // This is only called by table row groups and rows. It allows children that are not // table related to have a cell wrapped around them. nsresult @@ -2055,7 +2061,7 @@ HTMLStyleSheetImpl::TableProcessChild(nsIPresContext* aPresContext, } else { // wrap it in a table cell, row, row group, table if it is not whitespace PRBool needCell = PR_TRUE; nsIDOMCharacterData* domData = nsnull; - nsresult rv2 = aChildContent->QueryInterface(kIDOMCharacerDataIID, (void**)&domData); + nsresult rv2 = aChildContent->QueryInterface(kIDOMCharacterDataIID, (void**)&domData); if ((NS_OK == rv2) && (nsnull != domData)) { nsString charData; domData->GetData(charData); @@ -4425,6 +4431,83 @@ HTMLStyleSheetImpl::StyleRuleRemoved(nsIPresContext* aPresContext, return NS_OK; } +NS_IMETHODIMP +HTMLStyleSheetImpl::CantRenderReplacedElement(nsIPresContext* aPresContext, + nsIFrame* aFrame) +{ + nsIContent* content; + nsIAtom* tag; + nsIFrame* parentFrame; + + aFrame->GetParent(parentFrame); + + // Get the content object associated with aFrame + aFrame->GetContent(content); + NS_ASSERTION(nsnull != content, "null content object"); + content->GetTag(tag); + if (nsHTMLAtoms::img == tag) { + // The "alt" attribute specifies alternate text that is rendered + // when the image cannot be displayed + nsIDOMHTMLImageElement* element; + if (NS_SUCCEEDED(content->QueryInterface(kIDOMHTMLImageElementIID, (void**)&element))) { + nsAutoString altText; + + element->GetAlt(altText); + if (altText.Length() > 0) { + // Create a text content element for the alt-text + nsIContent* altTextContent; + nsIDOMCharacterData* domData; + + NS_NewTextNode(&altTextContent); + altTextContent->QueryInterface(kIDOMCharacterDataIID, (void**)&domData); + domData->SetData(altText); + NS_RELEASE(domData); + + // Create a text frame to display the alt-text + nsIFrame* textFrame; + NS_NewTextFrame(textFrame); + + // Use a special pseudo element style context for text + nsIStyleContext* textStyleContext; + nsIStyleContext* parentStyleContext; + nsIContent* parentContent; + + parentFrame->GetContent(parentContent); + parentFrame->GetStyleContext(parentStyleContext); + textStyleContext = aPresContext->ResolvePseudoStyleContextFor + (parentContent, nsHTMLAtoms::textPseudo, parentStyleContext); + NS_RELEASE(parentStyleContext); + NS_RELEASE(parentContent); + + // Initialize the text frame + textFrame->Init(*aPresContext, altTextContent, parentFrame, textStyleContext); + NS_RELEASE(textStyleContext); + NS_RELEASE(altTextContent); + + // Get the previous sibling frame + nsIFrame* firstChild; + parentFrame->FirstChild(nsnull, firstChild); + nsFrameList frameList(firstChild); + nsIFrame* prevSibling = frameList.GetPrevSiblingFor(aFrame); + + // Delete the current frame and insert the new frame + nsIPresShell* presShell = aPresContext->GetShell(); + parentFrame->RemoveFrame(*aPresContext, *presShell, nsnull, aFrame); + parentFrame->InsertFrames(*aPresContext, *presShell, nsnull, prevSibling, textFrame); + NS_RELEASE(presShell); + } + } + + } else if (nsHTMLAtoms::object == tag) { + ; + } else { + NS_ASSERTION(PR_FALSE, "unexpected tag"); + } + + NS_IF_RELEASE(tag); + NS_IF_RELEASE(content); + return NS_OK; +} void HTMLStyleSheetImpl::List(FILE* out, PRInt32 aIndent) const { diff --git a/mozilla/layout/style/nsHTMLStyleSheet.cpp b/mozilla/layout/style/nsHTMLStyleSheet.cpp index 299ce60ec47..caedf5ea705 100644 --- a/mozilla/layout/style/nsHTMLStyleSheet.cpp +++ b/mozilla/layout/style/nsHTMLStyleSheet.cpp @@ -50,6 +50,8 @@ #include "nsIListControlFrame.h" #include "nsDeque.h" #include "nsIDOMCharacterData.h" +#include "nsIDOMHTMLImageElement.h" +#include "nsITextContent.h" #ifdef INCLUDE_XUL #include "nsXULAtoms.h" @@ -74,6 +76,8 @@ static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID); static NS_DEFINE_IID(kIDOMHTMLSelectElementIID, NS_IDOMHTMLSELECTELEMENT_IID); static NS_DEFINE_IID(kIComboboxControlFrameIID, NS_ICOMBOBOXCONTROLFRAME_IID); static NS_DEFINE_IID(kIListControlFrameIID, NS_ILISTCONTROLFRAME_IID); +static NS_DEFINE_IID(kIDOMHTMLImageElementIID, NS_IDOMHTMLIMAGEELEMENT_IID); +static NS_DEFINE_IID(kIDOMCharacterDataIID, NS_IDOMCHARACTERDATA_IID); class HTMLAnchorRule : public nsIStyleRule { public: @@ -384,6 +388,10 @@ public: NS_IMETHOD StyleRuleRemoved(nsIPresContext* aPresContext, nsIStyleSheet* aStyleSheet, nsIStyleRule* aStyleRule); + + // Notification that we were unable to render a replaced element. + NS_IMETHOD CantRenderReplacedElement(nsIPresContext* aPresContext, + nsIFrame* aFrame); virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const; @@ -1966,8 +1974,6 @@ HTMLStyleSheetImpl::ConstructTableCellFrameOnly(nsIPresContext* aPresContext, return rv; } -static NS_DEFINE_IID(kIDOMCharacerDataIID, NS_IDOMCHARACTERDATA_IID); - // This is only called by table row groups and rows. It allows children that are not // table related to have a cell wrapped around them. nsresult @@ -2055,7 +2061,7 @@ HTMLStyleSheetImpl::TableProcessChild(nsIPresContext* aPresContext, } else { // wrap it in a table cell, row, row group, table if it is not whitespace PRBool needCell = PR_TRUE; nsIDOMCharacterData* domData = nsnull; - nsresult rv2 = aChildContent->QueryInterface(kIDOMCharacerDataIID, (void**)&domData); + nsresult rv2 = aChildContent->QueryInterface(kIDOMCharacterDataIID, (void**)&domData); if ((NS_OK == rv2) && (nsnull != domData)) { nsString charData; domData->GetData(charData); @@ -4425,6 +4431,83 @@ HTMLStyleSheetImpl::StyleRuleRemoved(nsIPresContext* aPresContext, return NS_OK; } +NS_IMETHODIMP +HTMLStyleSheetImpl::CantRenderReplacedElement(nsIPresContext* aPresContext, + nsIFrame* aFrame) +{ + nsIContent* content; + nsIAtom* tag; + nsIFrame* parentFrame; + + aFrame->GetParent(parentFrame); + + // Get the content object associated with aFrame + aFrame->GetContent(content); + NS_ASSERTION(nsnull != content, "null content object"); + content->GetTag(tag); + if (nsHTMLAtoms::img == tag) { + // The "alt" attribute specifies alternate text that is rendered + // when the image cannot be displayed + nsIDOMHTMLImageElement* element; + if (NS_SUCCEEDED(content->QueryInterface(kIDOMHTMLImageElementIID, (void**)&element))) { + nsAutoString altText; + + element->GetAlt(altText); + if (altText.Length() > 0) { + // Create a text content element for the alt-text + nsIContent* altTextContent; + nsIDOMCharacterData* domData; + + NS_NewTextNode(&altTextContent); + altTextContent->QueryInterface(kIDOMCharacterDataIID, (void**)&domData); + domData->SetData(altText); + NS_RELEASE(domData); + + // Create a text frame to display the alt-text + nsIFrame* textFrame; + NS_NewTextFrame(textFrame); + + // Use a special pseudo element style context for text + nsIStyleContext* textStyleContext; + nsIStyleContext* parentStyleContext; + nsIContent* parentContent; + + parentFrame->GetContent(parentContent); + parentFrame->GetStyleContext(parentStyleContext); + textStyleContext = aPresContext->ResolvePseudoStyleContextFor + (parentContent, nsHTMLAtoms::textPseudo, parentStyleContext); + NS_RELEASE(parentStyleContext); + NS_RELEASE(parentContent); + + // Initialize the text frame + textFrame->Init(*aPresContext, altTextContent, parentFrame, textStyleContext); + NS_RELEASE(textStyleContext); + NS_RELEASE(altTextContent); + + // Get the previous sibling frame + nsIFrame* firstChild; + parentFrame->FirstChild(nsnull, firstChild); + nsFrameList frameList(firstChild); + nsIFrame* prevSibling = frameList.GetPrevSiblingFor(aFrame); + + // Delete the current frame and insert the new frame + nsIPresShell* presShell = aPresContext->GetShell(); + parentFrame->RemoveFrame(*aPresContext, *presShell, nsnull, aFrame); + parentFrame->InsertFrames(*aPresContext, *presShell, nsnull, prevSibling, textFrame); + NS_RELEASE(presShell); + } + } + + } else if (nsHTMLAtoms::object == tag) { + ; + } else { + NS_ASSERTION(PR_FALSE, "unexpected tag"); + } + + NS_IF_RELEASE(tag); + NS_IF_RELEASE(content); + return NS_OK; +} void HTMLStyleSheetImpl::List(FILE* out, PRInt32 aIndent) const { diff --git a/mozilla/layout/style/nsStyleSet.cpp b/mozilla/layout/style/nsStyleSet.cpp index ee43b48735f..f29f22de70e 100644 --- a/mozilla/layout/style/nsStyleSet.cpp +++ b/mozilla/layout/style/nsStyleSet.cpp @@ -131,6 +131,10 @@ public: nsIStyleSheet* aStyleSheet, nsIStyleRule* aStyleRule); + // Notification that we were unable to render a replaced element. + NS_IMETHOD CantRenderReplacedElement(nsIPresContext* aPresContext, + nsIFrame* aFrame); + virtual void List(FILE* out = stdout, PRInt32 aIndent = 0); private: @@ -809,6 +813,13 @@ StyleSetImpl::StyleRuleRemoved(nsIPresContext* aPresContext, return mFrameConstructor->StyleRuleRemoved(aPresContext, aStyleSheet, aStyleRule); } +NS_IMETHODIMP +StyleSetImpl::CantRenderReplacedElement(nsIPresContext* aPresContext, + nsIFrame* aFrame) +{ + return mFrameConstructor->CantRenderReplacedElement(aPresContext, aFrame); +} + void StyleSetImpl::List(FILE* out, PRInt32 aIndent, nsISupportsArray* aSheets) { PRInt32 count = ((nsnull != aSheets) ? aSheets->Count() : 0);