From d1c1168c09c19342ee662fdb05eaf0211a0e4186 Mon Sep 17 00:00:00 2001 From: "dbaron%dbaron.org" Date: Sat, 31 Jul 2004 07:42:12 +0000 Subject: [PATCH] Back out 236889 due to 253755. git-svn-id: svn://10.0.0.236/trunk@160168 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/src/nsRuleNode.cpp | 4 +- .../content/html/style/src/nsCSSDataBlock.cpp | 3 +- .../html/style/src/nsComputedDOMStyle.cpp | 6 +- mozilla/content/shared/public/nsStyleStruct.h | 2 +- mozilla/content/shared/src/nsStyleStruct.cpp | 2 +- mozilla/layout/generic/nsBulletFrame.cpp | 60 ++++-- .../layout/html/base/src/nsBulletFrame.cpp | 60 ++++-- mozilla/layout/style/nsCSSDataBlock.cpp | 3 +- mozilla/layout/style/nsComputedDOMStyle.cpp | 6 +- mozilla/layout/style/nsRuleNode.cpp | 4 +- mozilla/layout/style/nsStyleStruct.cpp | 2 +- mozilla/layout/style/nsStyleStruct.h | 2 +- .../layout/xul/base/src/nsImageBoxFrame.cpp | 180 +++++++++++++----- mozilla/layout/xul/base/src/nsImageBoxFrame.h | 25 ++- .../xul/base/src/tree/src/nsTreeBodyFrame.cpp | 54 +++--- 15 files changed, 282 insertions(+), 131 deletions(-) diff --git a/mozilla/content/base/src/nsRuleNode.cpp b/mozilla/content/base/src/nsRuleNode.cpp index 61d13b35d10..ba4d0181f1b 100644 --- a/mozilla/content/base/src/nsRuleNode.cpp +++ b/mozilla/content/base/src/nsRuleNode.cpp @@ -3517,8 +3517,8 @@ nsRuleNode::ComputeListData(nsStyleStruct* aStartStruct, } // list-style-image: url, none, inherit - if (eCSSUnit_Image == listData.mImage.GetUnit()) { - list->mListStyleImage = listData.mImage.GetImageValue(); + if (eCSSUnit_URL == listData.mImage.GetUnit()) { + list->mListStyleImage = listData.mImage.GetURLValue(); } else if (eCSSUnit_None == listData.mImage.GetUnit()) { list->mListStyleImage = nsnull; diff --git a/mozilla/content/html/style/src/nsCSSDataBlock.cpp b/mozilla/content/html/style/src/nsCSSDataBlock.cpp index e84a30768d6..41196561916 100644 --- a/mozilla/content/html/style/src/nsCSSDataBlock.cpp +++ b/mozilla/content/html/style/src/nsCSSDataBlock.cpp @@ -185,8 +185,7 @@ nsCSSCompressedDataBlock::MapRuleInfoInto(nsRuleData *aRuleData) const if (target->GetUnit() == eCSSUnit_Null) { const nsCSSValue *val = ValueAtCursor(cursor); NS_ASSERTION(val->GetUnit() != eCSSUnit_Null, "oops"); - if ((iProp == eCSSProperty_background_image || - iProp == eCSSProperty_list_style_image) && + if (iProp == eCSSProperty_background_image && val->GetUnit() == eCSSUnit_URL) { val->StartImageLoad(aRuleData->mPresContext->GetDocument()); } diff --git a/mozilla/content/html/style/src/nsComputedDOMStyle.cpp b/mozilla/content/html/style/src/nsComputedDOMStyle.cpp index 0812c7e9fe2..5dfdb339ed1 100644 --- a/mozilla/content/html/style/src/nsComputedDOMStyle.cpp +++ b/mozilla/content/html/style/src/nsComputedDOMStyle.cpp @@ -1411,11 +1411,7 @@ nsComputedDOMStyle::GetListStyleImage(nsIFrame *aFrame, if (!list->mListStyleImage) { val->SetIdent(nsLayoutAtoms::none); } else { - nsCOMPtr uri; - if (list->mListStyleImage) { - list->mListStyleImage->GetURI(getter_AddRefs(uri)); - } - val->SetURI(uri); + val->SetURI(list->mListStyleImage); } } diff --git a/mozilla/content/shared/public/nsStyleStruct.h b/mozilla/content/shared/public/nsStyleStruct.h index 359954c82ad..034d3c27e4f 100644 --- a/mozilla/content/shared/public/nsStyleStruct.h +++ b/mozilla/content/shared/public/nsStyleStruct.h @@ -578,7 +578,7 @@ struct nsStyleList : public nsStyleStruct { PRUint8 mListStyleType; // [inherited] See nsStyleConsts.h PRUint8 mListStylePosition; // [inherited] - nsCOMPtr mListStyleImage; // [inherited] + nsCOMPtr mListStyleImage; // [inherited] nsRect mImageRegion; // [inherited] the rect to use within an image }; diff --git a/mozilla/content/shared/src/nsStyleStruct.cpp b/mozilla/content/shared/src/nsStyleStruct.cpp index 49d427797e0..9ff48068335 100644 --- a/mozilla/content/shared/src/nsStyleStruct.cpp +++ b/mozilla/content/shared/src/nsStyleStruct.cpp @@ -680,7 +680,7 @@ nsStyleList::nsStyleList(const nsStyleList& aSource) nsChangeHint nsStyleList::CalcDifference(const nsStyleList& aOther) const { if (mListStylePosition == aOther.mListStylePosition && - EqualImages(mListStyleImage, aOther.mListStyleImage) && + EqualURIs(mListStyleImage, aOther.mListStyleImage) && mListStyleType == aOther.mListStyleType) { if (mImageRegion == aOther.mImageRegion) return NS_STYLE_HINT_NONE; diff --git a/mozilla/layout/generic/nsBulletFrame.cpp b/mozilla/layout/generic/nsBulletFrame.cpp index 6e0485e3cc6..58ff078b6ce 100644 --- a/mozilla/layout/generic/nsBulletFrame.cpp +++ b/mozilla/layout/generic/nsBulletFrame.cpp @@ -123,11 +123,26 @@ nsBulletFrame::Init(nsIPresContext* aPresContext, mPresContext = aPresContext; nsresult rv = nsFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow); - if (NS_FAILED(rv)) - return rv; - imgIRequest *imgRequest = GetStyleList()->mListStyleImage; - if (imgRequest) { + nsIURI *imgURI = GetStyleList()->mListStyleImage; + if (imgURI) { + nsCOMPtr il(do_GetService("@mozilla.org/image/loader;1", &rv)); + if (NS_FAILED(rv)) + return rv; + + nsCOMPtr loadGroup; + GetLoadGroup(aPresContext, getter_AddRefs(loadGroup)); + + // Get the document URI for the referrer... + nsIURI *documentURI = nsnull; + nsCOMPtr doc; + if (mContent) { + doc = mContent->GetDocument(); + if (doc) { + documentURI = doc->GetDocumentURI(); + } + } + if (!mListener) { nsBulletListener *listener; NS_NEWXPCOM(listener, nsBulletListener); @@ -138,7 +153,10 @@ nsBulletFrame::Init(nsIPresContext* aPresContext, NS_RELEASE(listener); } - imgRequest->Clone(mListener, getter_AddRefs(mImageRequest)); + if (nsContentUtils::CanLoadImage(imgURI, doc, doc)) { + // XXX: initialDocumentURI is NULL ! + il->LoadImage(imgURI, nsnull, documentURI, loadGroup, mListener, aPresContext, nsIRequest::LOAD_NORMAL, nsnull, nsnull, getter_AddRefs(mImageRequest)); + } } return NS_OK; @@ -1567,9 +1585,9 @@ nsBulletFrame::Reflow(nsIPresContext* aPresContext, } if (isStyleChange) { - imgIRequest *newRequest = GetStyleList()->mListStyleImage; + nsIURI *newURI = GetStyleList()->mListStyleImage; - if (newRequest) { + if (newURI) { if (!mListener) { nsBulletListener *listener; @@ -1587,9 +1605,7 @@ nsBulletFrame::Reflow(nsIPresContext* aPresContext, // Reload the image, maybe... nsCOMPtr oldURI; mImageRequest->GetURI(getter_AddRefs(oldURI)); - nsCOMPtr newURI; - newRequest->GetURI(getter_AddRefs(newURI)); - if (oldURI && newURI) { + if (oldURI) { PRBool same; newURI->Equals(oldURI, &same); if (same) { @@ -1602,7 +1618,29 @@ nsBulletFrame::Reflow(nsIPresContext* aPresContext, } if (needNewRequest) { - newRequest->Clone(mListener, getter_AddRefs(mImageRequest)); + nsresult rv; + nsCOMPtr il(do_GetService("@mozilla.org/image/loader;1", &rv)); + if (NS_FAILED(rv)) + return rv; + + nsCOMPtr loadGroup; + GetLoadGroup(aPresContext, getter_AddRefs(loadGroup)); + + // Get the document URI for the referrer... + nsIURI* documentURI = nsnull; + nsCOMPtr doc; + if (mContent) { + doc = mContent->GetDocument(); + if (doc) { + documentURI = doc->GetDocumentURI(); + } + } + + + // XXX: initialDocumentURI is NULL ! + il->LoadImage(newURI, nsnull, documentURI, loadGroup, mListener, doc, + nsIRequest::LOAD_NORMAL, nsnull, nsnull, + getter_AddRefs(mImageRequest)); } } } diff --git a/mozilla/layout/html/base/src/nsBulletFrame.cpp b/mozilla/layout/html/base/src/nsBulletFrame.cpp index 6e0485e3cc6..58ff078b6ce 100644 --- a/mozilla/layout/html/base/src/nsBulletFrame.cpp +++ b/mozilla/layout/html/base/src/nsBulletFrame.cpp @@ -123,11 +123,26 @@ nsBulletFrame::Init(nsIPresContext* aPresContext, mPresContext = aPresContext; nsresult rv = nsFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow); - if (NS_FAILED(rv)) - return rv; - imgIRequest *imgRequest = GetStyleList()->mListStyleImage; - if (imgRequest) { + nsIURI *imgURI = GetStyleList()->mListStyleImage; + if (imgURI) { + nsCOMPtr il(do_GetService("@mozilla.org/image/loader;1", &rv)); + if (NS_FAILED(rv)) + return rv; + + nsCOMPtr loadGroup; + GetLoadGroup(aPresContext, getter_AddRefs(loadGroup)); + + // Get the document URI for the referrer... + nsIURI *documentURI = nsnull; + nsCOMPtr doc; + if (mContent) { + doc = mContent->GetDocument(); + if (doc) { + documentURI = doc->GetDocumentURI(); + } + } + if (!mListener) { nsBulletListener *listener; NS_NEWXPCOM(listener, nsBulletListener); @@ -138,7 +153,10 @@ nsBulletFrame::Init(nsIPresContext* aPresContext, NS_RELEASE(listener); } - imgRequest->Clone(mListener, getter_AddRefs(mImageRequest)); + if (nsContentUtils::CanLoadImage(imgURI, doc, doc)) { + // XXX: initialDocumentURI is NULL ! + il->LoadImage(imgURI, nsnull, documentURI, loadGroup, mListener, aPresContext, nsIRequest::LOAD_NORMAL, nsnull, nsnull, getter_AddRefs(mImageRequest)); + } } return NS_OK; @@ -1567,9 +1585,9 @@ nsBulletFrame::Reflow(nsIPresContext* aPresContext, } if (isStyleChange) { - imgIRequest *newRequest = GetStyleList()->mListStyleImage; + nsIURI *newURI = GetStyleList()->mListStyleImage; - if (newRequest) { + if (newURI) { if (!mListener) { nsBulletListener *listener; @@ -1587,9 +1605,7 @@ nsBulletFrame::Reflow(nsIPresContext* aPresContext, // Reload the image, maybe... nsCOMPtr oldURI; mImageRequest->GetURI(getter_AddRefs(oldURI)); - nsCOMPtr newURI; - newRequest->GetURI(getter_AddRefs(newURI)); - if (oldURI && newURI) { + if (oldURI) { PRBool same; newURI->Equals(oldURI, &same); if (same) { @@ -1602,7 +1618,29 @@ nsBulletFrame::Reflow(nsIPresContext* aPresContext, } if (needNewRequest) { - newRequest->Clone(mListener, getter_AddRefs(mImageRequest)); + nsresult rv; + nsCOMPtr il(do_GetService("@mozilla.org/image/loader;1", &rv)); + if (NS_FAILED(rv)) + return rv; + + nsCOMPtr loadGroup; + GetLoadGroup(aPresContext, getter_AddRefs(loadGroup)); + + // Get the document URI for the referrer... + nsIURI* documentURI = nsnull; + nsCOMPtr doc; + if (mContent) { + doc = mContent->GetDocument(); + if (doc) { + documentURI = doc->GetDocumentURI(); + } + } + + + // XXX: initialDocumentURI is NULL ! + il->LoadImage(newURI, nsnull, documentURI, loadGroup, mListener, doc, + nsIRequest::LOAD_NORMAL, nsnull, nsnull, + getter_AddRefs(mImageRequest)); } } } diff --git a/mozilla/layout/style/nsCSSDataBlock.cpp b/mozilla/layout/style/nsCSSDataBlock.cpp index e84a30768d6..41196561916 100644 --- a/mozilla/layout/style/nsCSSDataBlock.cpp +++ b/mozilla/layout/style/nsCSSDataBlock.cpp @@ -185,8 +185,7 @@ nsCSSCompressedDataBlock::MapRuleInfoInto(nsRuleData *aRuleData) const if (target->GetUnit() == eCSSUnit_Null) { const nsCSSValue *val = ValueAtCursor(cursor); NS_ASSERTION(val->GetUnit() != eCSSUnit_Null, "oops"); - if ((iProp == eCSSProperty_background_image || - iProp == eCSSProperty_list_style_image) && + if (iProp == eCSSProperty_background_image && val->GetUnit() == eCSSUnit_URL) { val->StartImageLoad(aRuleData->mPresContext->GetDocument()); } diff --git a/mozilla/layout/style/nsComputedDOMStyle.cpp b/mozilla/layout/style/nsComputedDOMStyle.cpp index 0812c7e9fe2..5dfdb339ed1 100644 --- a/mozilla/layout/style/nsComputedDOMStyle.cpp +++ b/mozilla/layout/style/nsComputedDOMStyle.cpp @@ -1411,11 +1411,7 @@ nsComputedDOMStyle::GetListStyleImage(nsIFrame *aFrame, if (!list->mListStyleImage) { val->SetIdent(nsLayoutAtoms::none); } else { - nsCOMPtr uri; - if (list->mListStyleImage) { - list->mListStyleImage->GetURI(getter_AddRefs(uri)); - } - val->SetURI(uri); + val->SetURI(list->mListStyleImage); } } diff --git a/mozilla/layout/style/nsRuleNode.cpp b/mozilla/layout/style/nsRuleNode.cpp index 61d13b35d10..ba4d0181f1b 100644 --- a/mozilla/layout/style/nsRuleNode.cpp +++ b/mozilla/layout/style/nsRuleNode.cpp @@ -3517,8 +3517,8 @@ nsRuleNode::ComputeListData(nsStyleStruct* aStartStruct, } // list-style-image: url, none, inherit - if (eCSSUnit_Image == listData.mImage.GetUnit()) { - list->mListStyleImage = listData.mImage.GetImageValue(); + if (eCSSUnit_URL == listData.mImage.GetUnit()) { + list->mListStyleImage = listData.mImage.GetURLValue(); } else if (eCSSUnit_None == listData.mImage.GetUnit()) { list->mListStyleImage = nsnull; diff --git a/mozilla/layout/style/nsStyleStruct.cpp b/mozilla/layout/style/nsStyleStruct.cpp index 49d427797e0..9ff48068335 100644 --- a/mozilla/layout/style/nsStyleStruct.cpp +++ b/mozilla/layout/style/nsStyleStruct.cpp @@ -680,7 +680,7 @@ nsStyleList::nsStyleList(const nsStyleList& aSource) nsChangeHint nsStyleList::CalcDifference(const nsStyleList& aOther) const { if (mListStylePosition == aOther.mListStylePosition && - EqualImages(mListStyleImage, aOther.mListStyleImage) && + EqualURIs(mListStyleImage, aOther.mListStyleImage) && mListStyleType == aOther.mListStyleType) { if (mImageRegion == aOther.mImageRegion) return NS_STYLE_HINT_NONE; diff --git a/mozilla/layout/style/nsStyleStruct.h b/mozilla/layout/style/nsStyleStruct.h index 359954c82ad..034d3c27e4f 100644 --- a/mozilla/layout/style/nsStyleStruct.h +++ b/mozilla/layout/style/nsStyleStruct.h @@ -578,7 +578,7 @@ struct nsStyleList : public nsStyleStruct { PRUint8 mListStyleType; // [inherited] See nsStyleConsts.h PRUint8 mListStylePosition; // [inherited] - nsCOMPtr mListStyleImage; // [inherited] + nsCOMPtr mListStyleImage; // [inherited] nsRect mImageRegion; // [inherited] the rect to use within an image }; diff --git a/mozilla/layout/xul/base/src/nsImageBoxFrame.cpp b/mozilla/layout/xul/base/src/nsImageBoxFrame.cpp index 7edeeffe8d4..3ce5ca1dd46 100644 --- a/mozilla/layout/xul/base/src/nsImageBoxFrame.cpp +++ b/mozilla/layout/xul/base/src/nsImageBoxFrame.cpp @@ -261,13 +261,12 @@ nsImageBoxFrame::AttributeChanged(nsIPresContext* aPresContext, { nsresult rv = nsLeafBoxFrame::AttributeChanged(aPresContext, aChild, aNameSpaceID, aAttribute, aModType); - if (aAttribute == nsHTMLAtoms::src) { - UpdateImage(); + PRBool aResize = UpdateAttributes(aAttribute); + + if (aResize) { nsBoxLayoutState state(aPresContext); MarkDirty(state); } - else if (aAttribute == nsXULAtoms::validate) - UpdateLoadFlags(); return rv; } @@ -275,6 +274,8 @@ nsImageBoxFrame::AttributeChanged(nsIPresContext* aPresContext, nsImageBoxFrame::nsImageBoxFrame(nsIPresShell* aShell) : nsLeafBoxFrame(aShell), mUseSrcAttr(PR_FALSE), + mSizeFrozen(PR_FALSE), + mHasImage(PR_FALSE), mSuppressStyleCheck(PR_FALSE), mIntrinsicSize(0,0), mLoadFlags(nsIRequest::LOAD_NORMAL) @@ -328,21 +329,17 @@ nsImageBoxFrame::Init(nsIPresContext* aPresContext, nsresult rv = nsLeafBoxFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow); mSuppressStyleCheck = PR_FALSE; + GetImageSource(); UpdateLoadFlags(); + UpdateImage(); return rv; } void -nsImageBoxFrame::UpdateImage() +nsImageBoxFrame::GetImageSource() { - if (mImageRequest) { - mImageRequest->Cancel(NS_ERROR_FAILURE); - mImageRequest = nsnull; - mIntrinsicSize.SizeTo(0, 0); - } - // get the new image src nsAutoString src; mContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::src, src); @@ -353,37 +350,33 @@ nsImageBoxFrame::UpdateImage() baseURI = mContent->GetBaseURI(); } // XXX origin charset needed - nsCOMPtr uri; - NS_NewURI(getter_AddRefs(uri), src, nsnull, baseURI); - - nsresult rv; - nsCOMPtr il(do_GetService("@mozilla.org/image/loader;1", &rv)); - if (uri && NS_SUCCEEDED(rv)) { - nsCOMPtr loadGroup = GetLoadGroup(); - - // Get the document URI for the referrer... - nsIDocument* doc = mContent ? mContent->GetDocument() : nsnull; - nsIURI *documentURI = doc ? doc->GetDocumentURI() : nsnull; - - // XXX: initialDocumentURI is NULL! - il->LoadImage(uri, nsnull, documentURI, loadGroup, mListener, doc, - mLoadFlags, nsnull, nsnull, getter_AddRefs(mImageRequest)); - } + NS_NewURI(getter_AddRefs(mURI), src, nsnull, baseURI); } else { // Only get the list-style-image if we aren't being drawn // by a native theme. - PRUint8 appearance = GetStyleDisplay()->mAppearance; - if (!(appearance && nsBox::gTheme && - nsBox::gTheme->ThemeSupportsWidget(nsnull, this, appearance))) { - // get the list-style-image - imgIRequest *styleRequest = GetStyleList()->mListStyleImage; - if (styleRequest) { - styleRequest->Clone(mListener, getter_AddRefs(mImageRequest)); - } - } + const nsStyleDisplay* disp = GetStyleDisplay(); + if (disp->mAppearance && nsBox::gTheme && + nsBox::gTheme->ThemeSupportsWidget(nsnull, this, disp->mAppearance)) + return; + + // get the list-style-image + mURI = GetStyleList()->mListStyleImage; } } +PRBool +nsImageBoxFrame::UpdateAttributes(nsIAtom* aAttribute) +{ + if (aAttribute == nsnull || aAttribute == nsHTMLAtoms::src) { + GetImageSource(); + return UpdateImage(); + } + else if (aAttribute == nsXULAtoms::validate) + UpdateLoadFlags(); + + return PR_FALSE; +} + void nsImageBoxFrame::UpdateLoadFlags() { @@ -397,6 +390,66 @@ nsImageBoxFrame::UpdateLoadFlags() mLoadFlags = nsIRequest::LOAD_NORMAL; } +PRBool +nsImageBoxFrame::UpdateImage() +{ + // get the new image src + if (!mURI) { + mSizeFrozen = PR_TRUE; + mHasImage = PR_FALSE; + + if (mImageRequest) { + mImageRequest->Cancel(NS_ERROR_FAILURE); + mImageRequest = nsnull; + } + + return PR_TRUE; + } + + nsresult rv; + if (mImageRequest) { + nsCOMPtr requestURI; + rv = mImageRequest->GetURI(getter_AddRefs(requestURI)); + NS_ASSERTION(NS_SUCCEEDED(rv) && requestURI,"no request URI"); + if (NS_FAILED(rv) || !requestURI) return PR_FALSE; + + PRBool eq; + // if the source uri and the current one are the same, return + if (NS_SUCCEEDED(requestURI->Equals(mURI, &eq)) && eq) + return PR_FALSE; + } + + mSizeFrozen = PR_FALSE; + mHasImage = PR_TRUE; + + // otherwise, we need to load the new uri + if (mImageRequest) { + mImageRequest->Cancel(NS_ERROR_FAILURE); + mImageRequest = nsnull; + } + + nsCOMPtr il(do_GetService("@mozilla.org/image/loader;1", &rv)); + if (NS_FAILED(rv)) return PR_FALSE; + + nsCOMPtr loadGroup = GetLoadGroup(); + + // Get the document URI for the referrer... + nsIURI *documentURI = nsnull; + nsCOMPtr doc; + if (mContent) { + doc = mContent->GetDocument(); + if (doc) { + documentURI = doc->GetDocumentURI(); + } + } + + // XXX: initialDocumentURI is NULL! + il->LoadImage(mURI, nsnull, documentURI, loadGroup, mListener, doc, + mLoadFlags, nsnull, nsnull, getter_AddRefs(mImageRequest)); + + return PR_TRUE; +} + NS_IMETHODIMP nsImageBoxFrame::Paint(nsIPresContext* aPresContext, nsIRenderingContext& aRenderingContext, @@ -437,7 +490,7 @@ nsImageBoxFrame::PaintImage(nsIRenderingContext& aRenderingContext, return; // don't draw if the image is not dirty - if (!aDirtyRect.Intersects(rect)) + if (!mHasImage || !aDirtyRect.Intersects(rect)) return; nsCOMPtr imgCon; @@ -495,17 +548,14 @@ nsImageBoxFrame::DidSetStyleContext( nsIPresContext* aPresContext ) return NS_OK; // If list-style-image changes, we have a new image. - nsCOMPtr oldURI, newURI; - if (mImageRequest) - mImageRequest->GetURI(getter_AddRefs(oldURI)); - if (myList->mListStyleImage) - myList->mListStyleImage->GetURI(getter_AddRefs(newURI)); + nsIURI *newURI = myList->mListStyleImage; PRBool equal; - if (newURI == oldURI || // handles null==null - (newURI && oldURI && - NS_SUCCEEDED(newURI->Equals(oldURI, &equal)) && equal)) + if (newURI == mURI || // handles null==null + (newURI && mURI && NS_SUCCEEDED(newURI->Equals(mURI, &equal)) && equal)) return NS_OK; + mURI = newURI; + UpdateImage(); return NS_OK; } // DidSetStyleContext @@ -513,13 +563,36 @@ nsImageBoxFrame::DidSetStyleContext( nsIPresContext* aPresContext ) void nsImageBoxFrame::GetImageSize() { - if (mIntrinsicSize.width > 0 && mIntrinsicSize.height > 0) { - mImageSize.width = mIntrinsicSize.width; - mImageSize.height = mIntrinsicSize.height; - } else { - mImageSize.width = 0; - mImageSize.height = 0; - } + nsHTMLReflowMetrics desiredSize(PR_TRUE); + const PRInt32 kDefaultSize = 0; + // XXX constant zero? + const PRInt32 kDefaultSizeInTwips = + GetPresContext()->IntScaledPixelsToTwips(kDefaultSize); + +// not calculated? Get the intrinsic size + if (mHasImage) { + // get the size of the image and set the desired size + if (mSizeFrozen) { + mImageSize.width = kDefaultSizeInTwips; + mImageSize.height = kDefaultSizeInTwips; + return; + } else { + // Ask the image loader for the *intrinsic* image size + if (mIntrinsicSize.width > 0 && mIntrinsicSize.height > 0) { + mImageSize.width = mIntrinsicSize.width; + mImageSize.height = mIntrinsicSize.height; + return; + } else { + mImageSize.width = kDefaultSizeInTwips; + mImageSize.height = kDefaultSizeInTwips; + return; + } + } + } + + // XXX constant zero? + mImageSize.width = desiredSize.width; + mImageSize.height = desiredSize.height; } @@ -610,6 +683,9 @@ NS_IMETHODIMP nsImageBoxFrame::OnStartContainer(imgIRequest *request, // Ensure the animation (if any) is started image->StartAnimation(); + mHasImage = PR_TRUE; + mSizeFrozen = PR_FALSE; + nscoord w, h; image->GetWidth(&w); image->GetHeight(&h); diff --git a/mozilla/layout/xul/base/src/nsImageBoxFrame.h b/mozilla/layout/xul/base/src/nsImageBoxFrame.h index ccf802b51d5..bf15ca753ec 100644 --- a/mozilla/layout/xul/base/src/nsImageBoxFrame.h +++ b/mozilla/layout/xul/base/src/nsImageBoxFrame.h @@ -97,12 +97,19 @@ public: NS_IMETHOD GetFrameName(nsAString& aResult) const; #endif - /** - * Update mUseSrcAttr from appropriate content attributes or from - * style, throw away the current image, and load the appropriate + /** + * Update internal state when a given attribute changes. Does not reload the * image. + * @return Whether the size of the image (possibly) changed + */ + PRBool UpdateAttributes(nsIAtom* aAttribute); + + /** + * Load the image to which mURI points, or throw away the current image if + * mURI is nsnull. Usually, this is preceded by a call to GetImageSource. + * @return PR_TRUE if the image is (possibly) of a different size * */ - void UpdateImage(); + PRBool UpdateImage(); /** * Update mLoadFlags from content attributes. Does not attempt to reload the @@ -134,6 +141,12 @@ protected: nsImageBoxFrame(nsIPresShell* aShell); + /** + * Update mURI and mUseSrcAttr from appropriate content attributes or from + * style. Does not reload the image. + */ + void GetImageSource(); + /** * Get the load group for the current document, that should be used for * network requests. @@ -147,7 +160,11 @@ private: nsCOMPtr mImageRequest; nsCOMPtr mListener; + nsCOMPtr mURI; ///< The URI of the image. + PRPackedBool mUseSrcAttr; ///< Whether or not the image src comes from an attribute. + PRPackedBool mSizeFrozen; + PRPackedBool mHasImage; PRPackedBool mSuppressStyleCheck; nsRect mSubRect; ///< If set, indicates that only the portion of the image specified by the rect should be used. diff --git a/mozilla/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp b/mozilla/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp index 3af9e9c2413..1a01b265bbd 100644 --- a/mozilla/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp +++ b/mozilla/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp @@ -1627,18 +1627,15 @@ nsTreeBodyFrame::GetImage(PRInt32 aRowIndex, nsTreeColumn* aCol, PRBool aUseCont nsAutoString imageSrc; mView->GetImageSrc(aRowIndex, aCol, imageSrc); - nsCOMPtr styleRequest; if (!aUseContext && !imageSrc.IsEmpty()) { aAllowImageRegions = PR_FALSE; } else { // Obtain the URL from the style context. aAllowImageRegions = PR_TRUE; - styleRequest = aStyleContext->GetStyleList()->mListStyleImage; - if (!styleRequest) + nsIURI* uri = aStyleContext->GetStyleList()->mListStyleImage; + if (!uri) return NS_OK; - nsCOMPtr uri; - styleRequest->GetURI(getter_AddRefs(uri)); nsCAutoString spec; uri->GetSpec(spec); CopyUTF8toUTF16(spec, imageSrc); @@ -1679,35 +1676,30 @@ nsTreeBodyFrame::GetImage(PRInt32 aRowIndex, nsTreeColumn* aCol, PRBool aUseCont listener->AddCell(aRowIndex, aCol); nsCOMPtr imgDecoderObserver = listener; + nsCOMPtr baseURI; + nsCOMPtr doc = mContent->GetDocument(); + if (!doc) + // The page is currently being torn down. Why bother. + return NS_ERROR_FAILURE; + + baseURI = mContent->GetBaseURI(); + + nsCOMPtr srcURI; + // XXX origin charset needed + NS_NewURI(getter_AddRefs(srcURI), imageSrc, nsnull, baseURI); + if (!srcURI) + return NS_ERROR_FAILURE; nsCOMPtr imageRequest; - if (styleRequest) { - styleRequest->Clone(imgDecoderObserver, getter_AddRefs(imageRequest)); - } else { - nsCOMPtr baseURI; - nsCOMPtr doc = mContent->GetDocument(); - if (!doc) - // The page is currently being torn down. Why bother. - return NS_ERROR_FAILURE; - baseURI = mContent->GetBaseURI(); + nsresult rv; + nsCOMPtr il(do_GetService("@mozilla.org/image/loader;1", &rv)); + if (NS_FAILED(rv)) + return rv; - nsCOMPtr srcURI; - // XXX origin charset needed - NS_NewURI(getter_AddRefs(srcURI), imageSrc, nsnull, baseURI); - if (!srcURI) - return NS_ERROR_FAILURE; - - nsresult rv; - nsCOMPtr il = - do_GetService("@mozilla.org/image/loader;1", &rv); - if (NS_FAILED(rv)) - return rv; - - // XXX: initialDocumentURI is NULL! - rv = il->LoadImage(srcURI, nsnull, doc->GetDocumentURI(), nsnull, - imgDecoderObserver, doc, nsIRequest::LOAD_NORMAL, - nsnull, nsnull, getter_AddRefs(imageRequest)); - } + // XXX: initialDocumentURI is NULL! + rv = il->LoadImage(srcURI, nsnull, doc->GetDocumentURI(), nsnull, + imgDecoderObserver, doc, nsIRequest::LOAD_NORMAL, + nsnull, nsnull, getter_AddRefs(imageRequest)); listener->UnsuppressInvalidation(); if (!imageRequest)