From af62af08a0f9a9042dd3fd2a3f9172c79ce62aaf Mon Sep 17 00:00:00 2001 From: "cbiesinger%web.de" Date: Thu, 19 Feb 2004 18:56:13 +0000 Subject: [PATCH] 233890, misc cleanup in some layout files, r+sr=bz git-svn-id: svn://10.0.0.236/trunk@152949 18797224-902f-48f8-a5cc-f745e15eee43 --- .../events/src/nsEventStateManager.cpp | 4 +- .../html/content/src/nsImageMapUtils.cpp | 26 +-- .../html/content/src/nsImageMapUtils.h | 8 +- .../content/shared/public/nsImageMapUtils.h | 8 +- .../content/shared/src/nsImageMapUtils.cpp | 26 +-- mozilla/layout/base/nsImageLoader.h | 2 +- mozilla/layout/base/nsPresContext.cpp | 19 +- mozilla/layout/base/src/nsImageLoader.h | 2 +- mozilla/layout/base/src/nsPresContext.cpp | 19 +- mozilla/layout/generic/nsImageFrame.cpp | 4 +- mozilla/layout/html/base/src/nsImageFrame.cpp | 4 +- .../layout/xul/base/src/nsImageBoxFrame.cpp | 187 +++++------------- mozilla/layout/xul/base/src/nsImageBoxFrame.h | 57 +++--- 13 files changed, 139 insertions(+), 227 deletions(-) diff --git a/mozilla/content/events/src/nsEventStateManager.cpp b/mozilla/content/events/src/nsEventStateManager.cpp index d6523a91a3f..c306e0ba859 100644 --- a/mozilla/content/events/src/nsEventStateManager.cpp +++ b/mozilla/content/events/src/nsEventStateManager.cpp @@ -3473,8 +3473,8 @@ nsEventStateManager::GetNextTabbableContent(nsIContent* aRootContent, nsCOMPtr doc = child->GetDocument(); if (doc) { nextImage->GetAttribute(NS_LITERAL_STRING("usemap"), usemap); - nsCOMPtr imageMap; - if (NS_SUCCEEDED(nsImageMapUtils::FindImageMap(doc,usemap,getter_AddRefs(imageMap))) && imageMap) { + nsCOMPtr imageMap = nsImageMapUtils::FindImageMap(doc,usemap); + if (imageMap) { nsCOMPtr map(do_QueryInterface(imageMap)); if (map) { nsIContent *childArea; diff --git a/mozilla/content/html/content/src/nsImageMapUtils.cpp b/mozilla/content/html/content/src/nsImageMapUtils.cpp index 2e66aca8371..6ef092a6e76 100644 --- a/mozilla/content/html/content/src/nsImageMapUtils.cpp +++ b/mozilla/content/html/content/src/nsImageMapUtils.cpp @@ -48,20 +48,19 @@ #include "nsImageMapUtils.h" /*static*/ -nsresult nsImageMapUtils::FindImageMap(nsIDocument *aDocument, - const nsAString &aUsemap, - nsIDOMHTMLMapElement **aMap) +already_AddRefed +nsImageMapUtils::FindImageMap(nsIDocument *aDocument, + const nsAString &aUsemap) { - NS_ENSURE_ARG_POINTER(aDocument); - NS_ENSURE_ARG_POINTER(aMap); - *aMap = nsnull; + if (!aDocument) + return nsnull; // We used to strip the whitespace from the usemap value as a Quirk, // but it was too quirky and didn't really work correctly - see bug // 87050 if (aUsemap.IsEmpty()) - return NS_OK; + return nsnull; nsAString::const_iterator start, end; aUsemap.BeginReading(start); @@ -73,7 +72,7 @@ nsresult nsImageMapUtils::FindImageMap(nsIDocument *aDocument, start.advance(hash + 1); if (start == end) { - return NS_OK; // aUsemap == "#" + return nsnull; // aUsemap == "#" } } @@ -81,8 +80,9 @@ nsresult nsImageMapUtils::FindImageMap(nsIDocument *aDocument, nsCOMPtr htmlDoc(do_QueryInterface(aDocument)); if (htmlDoc) { - *aMap = htmlDoc->GetImageMap(usemap); - NS_IF_ADDREF(*aMap); + nsIDOMHTMLMapElement* map = htmlDoc->GetImageMap(usemap); + NS_IF_ADDREF(map); + return map; } else { // For XHTML elements embedded in non-XHTML documents we get the // map by id since XHTML requires that where a "name" attribute @@ -96,10 +96,12 @@ nsresult nsImageMapUtils::FindImageMap(nsIDocument *aDocument, domDoc->GetElementById(usemap, getter_AddRefs(element)); if (element) { - CallQueryInterface(element, aMap); + nsIDOMHTMLMapElement* map; + CallQueryInterface(element, &map); + return map; } } } - return NS_OK; + return nsnull; } diff --git a/mozilla/content/html/content/src/nsImageMapUtils.h b/mozilla/content/html/content/src/nsImageMapUtils.h index b98f930ab53..991fe69e701 100644 --- a/mozilla/content/html/content/src/nsImageMapUtils.h +++ b/mozilla/content/html/content/src/nsImageMapUtils.h @@ -60,12 +60,10 @@ public: * * @param aDocument [in] The document to be searched. * @param aUsemap [in] The value of the usemap attribute. - * @param aMap [out] The first found (if any) map element. - * @return XPCOM return values. + * @return The first found (if any) map element, addrefed. */ - static nsresult FindImageMap(nsIDocument *aDocument, - const nsAString &aUsemap, - nsIDOMHTMLMapElement **aMap); + static already_AddRefed + FindImageMap(nsIDocument *aDocument, const nsAString &aUsemap); }; #endif diff --git a/mozilla/content/shared/public/nsImageMapUtils.h b/mozilla/content/shared/public/nsImageMapUtils.h index b98f930ab53..991fe69e701 100644 --- a/mozilla/content/shared/public/nsImageMapUtils.h +++ b/mozilla/content/shared/public/nsImageMapUtils.h @@ -60,12 +60,10 @@ public: * * @param aDocument [in] The document to be searched. * @param aUsemap [in] The value of the usemap attribute. - * @param aMap [out] The first found (if any) map element. - * @return XPCOM return values. + * @return The first found (if any) map element, addrefed. */ - static nsresult FindImageMap(nsIDocument *aDocument, - const nsAString &aUsemap, - nsIDOMHTMLMapElement **aMap); + static already_AddRefed + FindImageMap(nsIDocument *aDocument, const nsAString &aUsemap); }; #endif diff --git a/mozilla/content/shared/src/nsImageMapUtils.cpp b/mozilla/content/shared/src/nsImageMapUtils.cpp index 2e66aca8371..6ef092a6e76 100644 --- a/mozilla/content/shared/src/nsImageMapUtils.cpp +++ b/mozilla/content/shared/src/nsImageMapUtils.cpp @@ -48,20 +48,19 @@ #include "nsImageMapUtils.h" /*static*/ -nsresult nsImageMapUtils::FindImageMap(nsIDocument *aDocument, - const nsAString &aUsemap, - nsIDOMHTMLMapElement **aMap) +already_AddRefed +nsImageMapUtils::FindImageMap(nsIDocument *aDocument, + const nsAString &aUsemap) { - NS_ENSURE_ARG_POINTER(aDocument); - NS_ENSURE_ARG_POINTER(aMap); - *aMap = nsnull; + if (!aDocument) + return nsnull; // We used to strip the whitespace from the usemap value as a Quirk, // but it was too quirky and didn't really work correctly - see bug // 87050 if (aUsemap.IsEmpty()) - return NS_OK; + return nsnull; nsAString::const_iterator start, end; aUsemap.BeginReading(start); @@ -73,7 +72,7 @@ nsresult nsImageMapUtils::FindImageMap(nsIDocument *aDocument, start.advance(hash + 1); if (start == end) { - return NS_OK; // aUsemap == "#" + return nsnull; // aUsemap == "#" } } @@ -81,8 +80,9 @@ nsresult nsImageMapUtils::FindImageMap(nsIDocument *aDocument, nsCOMPtr htmlDoc(do_QueryInterface(aDocument)); if (htmlDoc) { - *aMap = htmlDoc->GetImageMap(usemap); - NS_IF_ADDREF(*aMap); + nsIDOMHTMLMapElement* map = htmlDoc->GetImageMap(usemap); + NS_IF_ADDREF(map); + return map; } else { // For XHTML elements embedded in non-XHTML documents we get the // map by id since XHTML requires that where a "name" attribute @@ -96,10 +96,12 @@ nsresult nsImageMapUtils::FindImageMap(nsIDocument *aDocument, domDoc->GetElementById(usemap, getter_AddRefs(element)); if (element) { - CallQueryInterface(element, aMap); + nsIDOMHTMLMapElement* map; + CallQueryInterface(element, &map); + return map; } } } - return NS_OK; + return nsnull; } diff --git a/mozilla/layout/base/nsImageLoader.h b/mozilla/layout/base/nsImageLoader.h index 4bda491e9d9..c61dc3bfd97 100644 --- a/mozilla/layout/base/nsImageLoader.h +++ b/mozilla/layout/base/nsImageLoader.h @@ -46,7 +46,7 @@ public: void Destroy(); nsIFrame *GetFrame() { return mFrame; } - void GetRequest(imgIRequest **aRequest) { *aRequest = mRequest; NS_IF_ADDREF(*aRequest); } + imgIRequest *GetRequest() { return mRequest; } private: void RedrawDirtyFrame(const nsRect* aDamageRect); diff --git a/mozilla/layout/base/nsPresContext.cpp b/mozilla/layout/base/nsPresContext.cpp index a40cde0768c..c5f69f99936 100644 --- a/mozilla/layout/base/nsPresContext.cpp +++ b/mozilla/layout/base/nsPresContext.cpp @@ -782,8 +782,7 @@ PR_STATIC_CALLBACK(PRBool) set_animation_mode(nsHashKey *aKey, void *aData, void { nsISupports *sup = NS_REINTERPRET_CAST(nsISupports*, aData); nsImageLoader *loader = NS_REINTERPRET_CAST(nsImageLoader*, sup); - nsCOMPtr imgReq; - loader->GetRequest(getter_AddRefs(imgReq)); + imgIRequest* imgReq = loader->GetRequest(); SetImgAnimModeOnImgReq(imgReq, (PRUint16)NS_PTR_TO_INT32(closure)); return PR_TRUE; } @@ -1012,25 +1011,19 @@ nsPresContext::LoadImage(nsIURI* aURL, } } - nsImageLoader *newLoader = new nsImageLoader(); - if (!newLoader) + loader = new nsImageLoader(); + if (!loader) return NS_ERROR_OUT_OF_MEMORY; - NS_ADDREF(newLoader); // new - - nsCOMPtr sup; - newLoader->QueryInterface(NS_GET_IID(nsISupports), getter_AddRefs(sup)); - - loader = NS_REINTERPRET_CAST(nsImageLoader*, sup.get()); + NS_ADDREF(loader); // new loader->Init(aTargetFrame, this); - - mImageLoaders.Put(&key, sup); + mImageLoaders.Put(&key, loader); } loader->Load(aURL); - loader->GetRequest(aRequest); + NS_IF_ADDREF(*aRequest = loader->GetRequest()); NS_RELEASE(loader); diff --git a/mozilla/layout/base/src/nsImageLoader.h b/mozilla/layout/base/src/nsImageLoader.h index 4bda491e9d9..c61dc3bfd97 100644 --- a/mozilla/layout/base/src/nsImageLoader.h +++ b/mozilla/layout/base/src/nsImageLoader.h @@ -46,7 +46,7 @@ public: void Destroy(); nsIFrame *GetFrame() { return mFrame; } - void GetRequest(imgIRequest **aRequest) { *aRequest = mRequest; NS_IF_ADDREF(*aRequest); } + imgIRequest *GetRequest() { return mRequest; } private: void RedrawDirtyFrame(const nsRect* aDamageRect); diff --git a/mozilla/layout/base/src/nsPresContext.cpp b/mozilla/layout/base/src/nsPresContext.cpp index a40cde0768c..c5f69f99936 100644 --- a/mozilla/layout/base/src/nsPresContext.cpp +++ b/mozilla/layout/base/src/nsPresContext.cpp @@ -782,8 +782,7 @@ PR_STATIC_CALLBACK(PRBool) set_animation_mode(nsHashKey *aKey, void *aData, void { nsISupports *sup = NS_REINTERPRET_CAST(nsISupports*, aData); nsImageLoader *loader = NS_REINTERPRET_CAST(nsImageLoader*, sup); - nsCOMPtr imgReq; - loader->GetRequest(getter_AddRefs(imgReq)); + imgIRequest* imgReq = loader->GetRequest(); SetImgAnimModeOnImgReq(imgReq, (PRUint16)NS_PTR_TO_INT32(closure)); return PR_TRUE; } @@ -1012,25 +1011,19 @@ nsPresContext::LoadImage(nsIURI* aURL, } } - nsImageLoader *newLoader = new nsImageLoader(); - if (!newLoader) + loader = new nsImageLoader(); + if (!loader) return NS_ERROR_OUT_OF_MEMORY; - NS_ADDREF(newLoader); // new - - nsCOMPtr sup; - newLoader->QueryInterface(NS_GET_IID(nsISupports), getter_AddRefs(sup)); - - loader = NS_REINTERPRET_CAST(nsImageLoader*, sup.get()); + NS_ADDREF(loader); // new loader->Init(aTargetFrame, this); - - mImageLoaders.Put(&key, sup); + mImageLoaders.Put(&key, loader); } loader->Load(aURL); - loader->GetRequest(aRequest); + NS_IF_ADDREF(*aRequest = loader->GetRequest()); NS_RELEASE(loader); diff --git a/mozilla/layout/generic/nsImageFrame.cpp b/mozilla/layout/generic/nsImageFrame.cpp index 4bad8c270a9..2302574fa27 100644 --- a/mozilla/layout/generic/nsImageFrame.cpp +++ b/mozilla/layout/generic/nsImageFrame.cpp @@ -1434,8 +1434,8 @@ nsImageFrame::GetImageMap(nsIPresContext* aPresContext) nsAutoString usemap; mContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::usemap, usemap); - nsCOMPtr map; - if (NS_SUCCEEDED(nsImageMapUtils::FindImageMap(doc,usemap,getter_AddRefs(map))) && map) { + nsCOMPtr map = nsImageMapUtils::FindImageMap(doc,usemap); + if (map) { mImageMap = new nsImageMap(); if (mImageMap) { NS_ADDREF(mImageMap); diff --git a/mozilla/layout/html/base/src/nsImageFrame.cpp b/mozilla/layout/html/base/src/nsImageFrame.cpp index 4bad8c270a9..2302574fa27 100644 --- a/mozilla/layout/html/base/src/nsImageFrame.cpp +++ b/mozilla/layout/html/base/src/nsImageFrame.cpp @@ -1434,8 +1434,8 @@ nsImageFrame::GetImageMap(nsIPresContext* aPresContext) nsAutoString usemap; mContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::usemap, usemap); - nsCOMPtr map; - if (NS_SUCCEEDED(nsImageMapUtils::FindImageMap(doc,usemap,getter_AddRefs(map))) && map) { + nsCOMPtr map = nsImageMapUtils::FindImageMap(doc,usemap); + if (map) { mImageMap = new nsImageMap(); if (mImageMap) { NS_ADDREF(mImageMap); diff --git a/mozilla/layout/xul/base/src/nsImageBoxFrame.cpp b/mozilla/layout/xul/base/src/nsImageBoxFrame.cpp index 3e45927c738..7385109d7b5 100644 --- a/mozilla/layout/xul/base/src/nsImageBoxFrame.cpp +++ b/mozilla/layout/xul/base/src/nsImageBoxFrame.cpp @@ -260,16 +260,11 @@ nsImageBoxFrame::AttributeChanged(nsIPresContext* aPresContext, { nsresult rv = nsLeafBoxFrame::AttributeChanged(aPresContext, aChild, aNameSpaceID, aAttribute, aModType); - PRBool aResize; - PRBool aRedraw; - UpdateAttributes(aPresContext, aAttribute, aResize, aRedraw); - - nsBoxLayoutState state(aPresContext); + PRBool aResize = UpdateAttributes(aAttribute); if (aResize) { + nsBoxLayoutState state(aPresContext); MarkDirty(state); - } else if (aRedraw) { - Redraw(state); } return rv; @@ -282,15 +277,13 @@ nsImageBoxFrame::nsImageBoxFrame(nsIPresShell* aShell) : mHasImage(PR_FALSE), mSuppressStyleCheck(PR_FALSE), mIntrinsicSize(0,0), - mLoadFlags(nsIRequest::LOAD_NORMAL), - mPresContext(nsnull) + mLoadFlags(nsIRequest::LOAD_NORMAL) { NeedsRecalc(); } nsImageBoxFrame::~nsImageBoxFrame() { - NS_PRECONDITION(!mPresContext, "Never got destroyed properly!"); } @@ -311,9 +304,6 @@ nsImageBoxFrame::Destroy(nsIPresContext* aPresContext) if (mListener) NS_REINTERPRET_CAST(nsImageBoxListener*, mListener.get())->SetFrame(nsnull); // set the frame to null so we don't send messages to a dead object. - // Clear out weak ptr to prescontext - mPresContext = nsnull; - return nsLeafBoxFrame::Destroy(aPresContext); } @@ -334,8 +324,6 @@ nsImageBoxFrame::Init(nsIPresContext* aPresContext, NS_RELEASE(listener); } - mPresContext = aPresContext; - mSuppressStyleCheck = PR_TRUE; nsresult rv = nsLeafBoxFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow); mSuppressStyleCheck = PR_FALSE; @@ -343,8 +331,7 @@ nsImageBoxFrame::Init(nsIPresContext* aPresContext, GetImageSource(); UpdateLoadFlags(); - PRBool aResize; - UpdateImage(aPresContext, aResize); + UpdateImage(); return rv; } @@ -376,18 +363,17 @@ nsImageBoxFrame::GetImageSource() } } -void -nsImageBoxFrame::UpdateAttributes(nsIPresContext* aPresContext, nsIAtom* aAttribute, PRBool& aResize, PRBool& aRedraw) +PRBool +nsImageBoxFrame::UpdateAttributes(nsIAtom* aAttribute) { - aResize = PR_FALSE; - aRedraw = PR_FALSE; - if (aAttribute == nsnull || aAttribute == nsHTMLAtoms::src) { GetImageSource(); - UpdateImage(aPresContext, aResize); + return UpdateImage(); } else if (aAttribute == nsXULAtoms::validate) UpdateLoadFlags(); + + return PR_FALSE; } void @@ -403,23 +389,20 @@ nsImageBoxFrame::UpdateLoadFlags() mLoadFlags = nsIRequest::LOAD_NORMAL; } -void -nsImageBoxFrame::UpdateImage(nsIPresContext* aPresContext, PRBool& aResize) +PRBool +nsImageBoxFrame::UpdateImage() { - aResize = PR_FALSE; - // get the new image src if (!mURI) { mSizeFrozen = PR_TRUE; mHasImage = PR_FALSE; - aResize = PR_TRUE; if (mImageRequest) { mImageRequest->Cancel(NS_ERROR_FAILURE); mImageRequest = nsnull; } - return; + return PR_TRUE; } nsresult rv; @@ -427,12 +410,12 @@ nsImageBoxFrame::UpdateImage(nsIPresContext* aPresContext, PRBool& aResize) nsCOMPtr requestURI; rv = mImageRequest->GetURI(getter_AddRefs(requestURI)); NS_ASSERTION(NS_SUCCEEDED(rv) && requestURI,"no request URI"); - if (NS_FAILED(rv) || !requestURI) return; + 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; + return PR_FALSE; } mSizeFrozen = PR_FALSE; @@ -445,10 +428,9 @@ nsImageBoxFrame::UpdateImage(nsIPresContext* aPresContext, PRBool& aResize) } nsCOMPtr il(do_GetService("@mozilla.org/image/loader;1", &rv)); - if (NS_FAILED(rv)) return; + if (NS_FAILED(rv)) return PR_FALSE; - nsCOMPtr loadGroup; - GetLoadGroup(aPresContext, getter_AddRefs(loadGroup)); + nsCOMPtr loadGroup = GetLoadGroup(); // Get the document URI for the referrer... nsIURI *documentURI = nsnull; @@ -464,7 +446,7 @@ nsImageBoxFrame::UpdateImage(nsIPresContext* aPresContext, PRBool& aResize) il->LoadImage(mURI, nsnull, documentURI, loadGroup, mListener, doc, mLoadFlags, nsnull, nsnull, getter_AddRefs(mImageRequest)); - aResize = PR_TRUE; + return PR_TRUE; } NS_IMETHODIMP @@ -479,36 +461,36 @@ nsImageBoxFrame::Paint(nsIPresContext* aPresContext, nsresult rv = nsLeafBoxFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer); - PaintImage(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer); + PaintImage(aRenderingContext, aDirtyRect, aWhichLayer); return rv; } -NS_IMETHODIMP -nsImageBoxFrame::PaintImage(nsIPresContext* aPresContext, - nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect, - nsFramePaintLayer aWhichLayer) +void +nsImageBoxFrame::PaintImage(nsIRenderingContext& aRenderingContext, + const nsRect& aDirtyRect, + nsFramePaintLayer aWhichLayer) { if ((0 == mRect.width) || (0 == mRect.height)) { // Do not render when given a zero area. This avoids some useless // scaling work while we wait for our image dimensions to arrive // asynchronously. - return NS_OK; + return; } nsRect rect; GetClientRect(rect); + if (NS_FRAME_PAINT_LAYER_FOREGROUND != aWhichLayer) + return; + + if (!mImageRequest) + return; + // don't draw if the image is not dirty if (!mHasImage || !aDirtyRect.Intersects(rect)) - return NS_OK; - - if (NS_FRAME_PAINT_LAYER_FOREGROUND != aWhichLayer) - return NS_OK; - - if (!mImageRequest) return NS_ERROR_UNEXPECTED; + return; nsCOMPtr imgCon; mImageRequest->GetImage(getter_AddRefs(imgCon)); @@ -540,8 +522,6 @@ nsImageBoxFrame::PaintImage(nsIPresContext* aPresContext, aRenderingContext.DrawScaledImage(imgCon, &src, &rect); } } - - return NS_OK; } @@ -575,18 +555,18 @@ nsImageBoxFrame::DidSetStyleContext( nsIPresContext* aPresContext ) mURI = newURI; - PRBool aResize; - UpdateImage(aPresContext, aResize); + UpdateImage(); return NS_OK; } // DidSetStyleContext void -nsImageBoxFrame::GetImageSize(nsIPresContext* aPresContext) +nsImageBoxFrame::GetImageSize() { nsHTMLReflowMetrics desiredSize(PR_TRUE); const PRInt32 kDefaultSize = 0; float p2t; - aPresContext->GetScaledPixelsToTwips(&p2t); + GetPresContext()->GetScaledPixelsToTwips(&p2t); + // XXX constant zero? const PRInt32 kDefaultSizeInTwips = NSIntPixelsToTwips(kDefaultSize, p2t); // not calculated? Get the intrinsic size @@ -610,20 +590,12 @@ nsImageBoxFrame::GetImageSize(nsIPresContext* aPresContext) } } + // XXX constant zero? mImageSize.width = desiredSize.width; mImageSize.height = desiredSize.height; } -/** - * Ok return our dimensions - */ -NS_IMETHODIMP -nsImageBoxFrame::DoLayout(nsBoxLayoutState& aState) -{ - return nsLeafBoxFrame::DoLayout(aState); -} - /** * Ok return our dimensions */ @@ -631,7 +603,7 @@ NS_IMETHODIMP nsImageBoxFrame::GetPrefSize(nsBoxLayoutState& aState, nsSize& aSize) { if (DoesNeedRecalc(mImageSize)) { - CacheImageSize(aState); + GetImageSize(); } if (!mUseSrcAttr && (mSubRect.width > 0 || mSubRect.height > 0)) @@ -672,16 +644,6 @@ nsImageBoxFrame::GetAscent(nsBoxLayoutState& aState, nscoord& aCoord) return NS_OK; } -/** - * Ok return our dimensions - */ -void -nsImageBoxFrame::CacheImageSize(nsBoxLayoutState& aState) -{ - nsIPresContext* presContext = aState.GetPresContext(); - GetImageSize(presContext); -} - #ifdef DEBUG NS_IMETHODIMP nsImageBoxFrame::GetFrameName(nsAString& aResult) const @@ -691,36 +653,27 @@ nsImageBoxFrame::GetFrameName(nsAString& aResult) const #endif -void -nsImageBoxFrame::GetLoadGroup(nsIPresContext *aPresContext, nsILoadGroup **aLoadGroup) +already_AddRefed +nsImageBoxFrame::GetLoadGroup() { - nsIPresShell *shell = aPresContext->GetPresShell(); - + nsIPresShell *shell = GetPresContext()->GetPresShell(); if (!shell) - return; + return nsnull; nsCOMPtr doc; shell->GetDocument(getter_AddRefs(doc)); if (!doc) - return; + return nsnull; - *aLoadGroup = doc->GetDocumentLoadGroup().get(); // already_AddRefed + return doc->GetDocumentLoadGroup(); // already_AddRefed } -NS_IMETHODIMP nsImageBoxFrame::OnStartDecode(imgIRequest *request) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - NS_IMETHODIMP nsImageBoxFrame::OnStartContainer(imgIRequest *request, imgIContainer *image) { NS_ENSURE_ARG_POINTER(image); - // If we have no prescontext, what's going on? - NS_ENSURE_TRUE(mPresContext, NS_ERROR_UNEXPECTED); - // Ensure the animation (if any) is started image->StartAnimation(); @@ -731,44 +684,21 @@ NS_IMETHODIMP nsImageBoxFrame::OnStartContainer(imgIRequest *request, image->GetWidth(&w); image->GetHeight(&h); - float p2t; - p2t = mPresContext->PixelsToTwips(); + nsIPresContext* presContext = GetPresContext(); + float p2t = presContext->PixelsToTwips(); mIntrinsicSize.SizeTo(NSIntPixelsToTwips(w, p2t), NSIntPixelsToTwips(h, p2t)); - nsBoxLayoutState state(mPresContext); - + nsBoxLayoutState state(presContext); this->MarkDirty(state); return NS_OK; } -NS_IMETHODIMP nsImageBoxFrame::OnStartFrame(imgIRequest *request, - gfxIImageFrame *frame) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP nsImageBoxFrame::OnDataAvailable(imgIRequest *request, - gfxIImageFrame *frame, - const nsRect * rect) -{ - return NS_OK; -} - -NS_IMETHODIMP nsImageBoxFrame::OnStopFrame(imgIRequest *request, - gfxIImageFrame *frame) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - NS_IMETHODIMP nsImageBoxFrame::OnStopContainer(imgIRequest *request, imgIContainer *image) { - // If we have no prescontext, what's going on? - NS_ENSURE_TRUE(mPresContext, NS_ERROR_UNEXPECTED); - - nsBoxLayoutState state(mPresContext); + nsBoxLayoutState state(GetPresContext()); this->Redraw(state); return NS_OK; @@ -791,10 +721,7 @@ NS_IMETHODIMP nsImageBoxFrame::FrameChanged(imgIContainer *container, gfxIImageFrame *newframe, nsRect * dirtyRect) { - // If we have no prescontext, what's going on? - NS_ENSURE_TRUE(mPresContext, NS_ERROR_UNEXPECTED); - - nsBoxLayoutState state(mPresContext); + nsBoxLayoutState state(GetPresContext()); this->Redraw(state); return NS_OK; @@ -812,10 +739,7 @@ nsImageBoxListener::~nsImageBoxListener() NS_IMETHODIMP nsImageBoxListener::OnStartDecode(imgIRequest *request) { - if (!mFrame) - return NS_ERROR_FAILURE; - - return mFrame->OnStartDecode(request); + return NS_OK; } NS_IMETHODIMP nsImageBoxListener::OnStartContainer(imgIRequest *request, @@ -830,29 +754,20 @@ NS_IMETHODIMP nsImageBoxListener::OnStartContainer(imgIRequest *request, NS_IMETHODIMP nsImageBoxListener::OnStartFrame(imgIRequest *request, gfxIImageFrame *frame) { - if (!mFrame) - return NS_ERROR_FAILURE; - - return mFrame->OnStartFrame(request, frame); + return NS_OK; } NS_IMETHODIMP nsImageBoxListener::OnDataAvailable(imgIRequest *request, gfxIImageFrame *frame, const nsRect * rect) { - if (!mFrame) - return NS_ERROR_FAILURE; - - return mFrame->OnDataAvailable(request, frame, rect); + return NS_OK; } NS_IMETHODIMP nsImageBoxListener::OnStopFrame(imgIRequest *request, gfxIImageFrame *frame) { - if (!mFrame) - return NS_ERROR_FAILURE; - - return mFrame->OnStopFrame(request, frame); + return NS_OK; } NS_IMETHODIMP nsImageBoxListener::OnStopContainer(imgIRequest *request, diff --git a/mozilla/layout/xul/base/src/nsImageBoxFrame.h b/mozilla/layout/xul/base/src/nsImageBoxFrame.h index faa06453159..34a6c495be1 100644 --- a/mozilla/layout/xul/base/src/nsImageBoxFrame.h +++ b/mozilla/layout/xul/base/src/nsImageBoxFrame.h @@ -70,7 +70,6 @@ public: NS_IMETHOD GetPrefSize(nsBoxLayoutState& aBoxLayoutState, nsSize& aSize); NS_IMETHOD GetMinSize(nsBoxLayoutState& aBoxLayoutState, nsSize& aSize); NS_IMETHOD GetAscent(nsBoxLayoutState& aBoxLayoutState, nscoord& aAscent); - NS_IMETHOD DoLayout(nsBoxLayoutState& aBoxLayoutState); NS_IMETHOD NeedsRecalc(); friend nsresult NS_NewImageBoxFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame); @@ -97,8 +96,24 @@ public: NS_IMETHOD GetFrameName(nsAString& aResult) const; #endif - void UpdateAttributes(nsIPresContext* aPresContext, nsIAtom* aAttribute, PRBool& aResize, PRBool& aRedraw); - void UpdateImage(nsIPresContext* aPresContext, PRBool& aResize); + /** + * 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 + * */ + PRBool UpdateImage(); + + /** + * Update mLoadFlags from content attributes. Does not attempt to reload the + * image using the new load flags. + */ void UpdateLoadFlags(); NS_IMETHOD Paint(nsIPresContext* aPresContext, @@ -107,13 +122,7 @@ public: nsFramePaintLayer aWhichLayer, PRUint32 aFlags = 0); - NS_IMETHOD OnStartDecode(imgIRequest *request); NS_IMETHOD OnStartContainer(imgIRequest *request, imgIContainer *image); - NS_IMETHOD OnStartFrame(imgIRequest *request, gfxIImageFrame *frame); - NS_IMETHOD OnDataAvailable(imgIRequest *request, - gfxIImageFrame *frame, - const nsRect * rect); - NS_IMETHOD OnStopFrame(imgIRequest *request, gfxIImageFrame *frame); NS_IMETHOD OnStopContainer(imgIRequest *request, imgIContainer *image); NS_IMETHOD OnStopDecode(imgIRequest *request, nsresult status, @@ -125,42 +134,44 @@ public: virtual ~nsImageBoxFrame(); protected: - void CacheImageSize(nsBoxLayoutState& aBoxLayoutState); - - - NS_IMETHOD PaintImage(nsIPresContext* aPresContext, - nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect, - nsFramePaintLayer aWhichLayer); + void PaintImage(nsIRenderingContext& aRenderingContext, + const nsRect& aDirtyRect, + nsFramePaintLayer aWhichLayer); nsImageBoxFrame(nsIPresShell* aShell); + /** + * Update mURI and mUseSrcAttr from appropriate content attributes or from + * style. Does not reload the image. + */ void GetImageSource(); - void GetLoadGroup(nsIPresContext *aPresContext, nsILoadGroup **group); + /** + * Get the load group for the current document, that should be used for + * network requests. + */ + already_AddRefed GetLoadGroup(); - virtual void GetImageSize(nsIPresContext* aPresContext); + virtual void GetImageSize(); private: nsCOMPtr mImageRequest; nsCOMPtr mListener; - nsCOMPtr mURI; // The URI of the image. + nsCOMPtr mURI; ///< The URI of the image. - PRPackedBool mUseSrcAttr; // Whether or not the image src comes from an attribute. + 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. + nsRect mSubRect; ///< If set, indicates that only the portion of the image specified by the rect should be used. nsSize mIntrinsicSize; PRInt32 mLoadFlags; nsSize mImageSize; - - nsIPresContext* mPresContext; // weak ptr }; // class nsImageBoxFrame #endif /* nsImageBoxFrame_h___ */