From e361d199bff586741dcf063ce9c168abff510e17 Mon Sep 17 00:00:00 2001 From: "evaughan%netscape.com" Date: Tue, 2 Mar 1999 05:00:51 +0000 Subject: [PATCH] Made the image accessible from CSS via list-style-image. git-svn-id: svn://10.0.0.236/trunk@22532 18797224-902f-48f8-a5cc-f745e15eee43 --- .../layout/forms/nsButtonFrameRenderer.cpp | 4 +- .../html/forms/src/nsButtonFrameRenderer.cpp | 4 +- .../xul/base/src/nsTitledButtonFrame.cpp | 178 +++++++++--------- .../layout/xul/base/src/nsTitledButtonFrame.h | 1 + mozilla/xpfe/browser/src/xul.css | 19 -- 5 files changed, 97 insertions(+), 109 deletions(-) diff --git a/mozilla/layout/forms/nsButtonFrameRenderer.cpp b/mozilla/layout/forms/nsButtonFrameRenderer.cpp index ece25ea583d..c1abe7a0efb 100644 --- a/mozilla/layout/forms/nsButtonFrameRenderer.cpp +++ b/mozilla/layout/forms/nsButtonFrameRenderer.cpp @@ -317,7 +317,7 @@ nsButtonFrameRenderer::PaintButton (nsIPresContext& aPresContext, nsFramePaintLayer aWhichLayer, const nsRect& aRect) { - printf("painted width='%d' height='%d'\n",aRect.width, aRect.height); + //printf("painted width='%d' height='%d'\n",aRect.width, aRect.height); // draw the border and background inside the focus and outline borders PaintBorderAndBackground(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer, aRect); @@ -585,7 +585,7 @@ nsButtonFrameRenderer::AddFocusBordersAndPadding(nsIPresContext& aPresContext, aMetrics.width += aBorderPadding.left + aBorderPadding.right; aMetrics.height += aBorderPadding.top + aBorderPadding.bottom; - printf("requested width='%d' height='%d'\n",aMetrics.width, aMetrics.height); + // printf("requested width='%d' height='%d'\n",aMetrics.width, aMetrics.height); } diff --git a/mozilla/layout/html/forms/src/nsButtonFrameRenderer.cpp b/mozilla/layout/html/forms/src/nsButtonFrameRenderer.cpp index ece25ea583d..c1abe7a0efb 100644 --- a/mozilla/layout/html/forms/src/nsButtonFrameRenderer.cpp +++ b/mozilla/layout/html/forms/src/nsButtonFrameRenderer.cpp @@ -317,7 +317,7 @@ nsButtonFrameRenderer::PaintButton (nsIPresContext& aPresContext, nsFramePaintLayer aWhichLayer, const nsRect& aRect) { - printf("painted width='%d' height='%d'\n",aRect.width, aRect.height); + //printf("painted width='%d' height='%d'\n",aRect.width, aRect.height); // draw the border and background inside the focus and outline borders PaintBorderAndBackground(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer, aRect); @@ -585,7 +585,7 @@ nsButtonFrameRenderer::AddFocusBordersAndPadding(nsIPresContext& aPresContext, aMetrics.width += aBorderPadding.left + aBorderPadding.right; aMetrics.height += aBorderPadding.top + aBorderPadding.bottom; - printf("requested width='%d' height='%d'\n",aMetrics.width, aMetrics.height); + // printf("requested width='%d' height='%d'\n",aMetrics.width, aMetrics.height); } diff --git a/mozilla/layout/xul/base/src/nsTitledButtonFrame.cpp b/mozilla/layout/xul/base/src/nsTitledButtonFrame.cpp index 897baac9d73..d4bccf60cf3 100644 --- a/mozilla/layout/xul/base/src/nsTitledButtonFrame.cpp +++ b/mozilla/layout/xul/base/src/nsTitledButtonFrame.cpp @@ -192,6 +192,7 @@ nsTitledButtonFrame::DeleteFrame(nsIPresContext& aPresContext) return nsLeafFrame::DeleteFrame(aPresContext); } + NS_IMETHODIMP nsTitledButtonFrame::Init(nsIPresContext& aPresContext, nsIContent* aContent, @@ -201,7 +202,7 @@ nsTitledButtonFrame::Init(nsIPresContext& aPresContext, { nsresult rv = nsLeafFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow); - mRenderer.SetNameSpace(nsXULAtoms::nameSpaceID); + mRenderer.SetNameSpace(kNameSpaceID_None); mRenderer.SetFrame(this,aPresContext); @@ -230,25 +231,24 @@ nsTitledButtonFrame::Init(nsIPresContext& aPresContext, } if (mHasImage == PR_TRUE) { - mImageLoader.SetURLSpec(src); - nsIURL* baseURL = nsnull; - nsIHTMLContent* htmlContent; - if (NS_SUCCEEDED(mContent->QueryInterface(kIHTMLContentIID, (void**)&htmlContent))) { - htmlContent->GetBaseURL(baseURL); - NS_RELEASE(htmlContent); - } - else { - nsIDocument* doc; - if (NS_SUCCEEDED(mContent->GetDocument(doc))) { - doc->GetBaseURL(baseURL); - NS_RELEASE(doc); - } - } - mImageLoader.SetBaseURL(baseURL); - NS_IF_RELEASE(baseURL); - } else { - mHasImage = PR_FALSE; - } + mImageLoader.SetURLSpec(src); + nsIURL* baseURL = nsnull; + nsIHTMLContent* htmlContent; + if (NS_SUCCEEDED(mContent->QueryInterface(kIHTMLContentIID, (void**)&htmlContent))) { + htmlContent->GetBaseURL(baseURL); + NS_RELEASE(htmlContent); + } + else { + nsIDocument* doc; + if (NS_SUCCEEDED(mContent->GetDocument(doc))) { + doc->GetBaseURL(baseURL); + NS_RELEASE(doc); + } + } + mImageLoader.SetBaseURL(baseURL); + NS_IF_RELEASE(baseURL); + } else + mHasImage = PR_FALSE; // get the alignment nsAutoString value; @@ -304,72 +304,7 @@ nsTitledButtonFrame::AttributeChanged(nsIPresContext* aPresContext, return rv; } if (nsHTMLAtoms::src == aAttribute) { - nsAutoString oldSRC; - mImageLoader.GetURLSpec(oldSRC); - nsAutoString newSRC; - - aChild->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::src, newSRC); - - if (newSRC.Equals("")) { - // if no src then get the list style image - const nsStyleList* myList = - (const nsStyleList*)mStyleContext->GetStyleData(eStyleStruct_List); - - if (myList->mListStyleImage.Length() > 0) { - newSRC = myList->mListStyleImage; - } - } - - if (!oldSRC.Equals(newSRC)) { - if (newSRC.Length() == 0) - { - mHasImage = PR_FALSE; - mNeedsLayout = PR_TRUE; - mSizeFrozen = PR_TRUE; - } else { - -#ifdef NS_DEBUG - char oldcbuf[100], newcbuf[100]; - oldSRC.ToCString(oldcbuf, sizeof(oldcbuf)); - newSRC.ToCString(newcbuf, sizeof(newcbuf)); - NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS, - ("nsTitledButtonFrame::AttributeChanged: new image source; old='%s' new='%s'", - oldcbuf, newcbuf)); -#endif - - // Get rid of old image loader and start a new image load going - mImageLoader.DestroyLoader(); - - // Fire up a new image load request - PRIntn loadStatus; - - mImageLoader.SetURLSpec(newSRC); - mImageLoader.StartLoadImage(aPresContext, this, nsnull, - PR_FALSE, loadStatus); - - NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS, - ("nsTitledButtonFrame::AttributeChanged: loadImage status=%x", - loadStatus)); - - // If the image is already ready then we need to trigger a - // redraw because the image loader won't. - if (loadStatus & NS_IMAGE_LOAD_STATUS_IMAGE_READY) { - // XXX Stuff this into a method on nsIPresShell/Context - nsRect bounds; - nsPoint offset; - nsIView* view; - GetOffsetFromView(offset, &view); - nsIViewManager* vm; - view->GetViewManager(vm); - bounds.x = offset.x; - bounds.y = offset.y; - bounds.width = mRect.width; - bounds.height = mRect.height; - vm->UpdateView(view, bounds, 0); - NS_RELEASE(vm); - } - } - } + ImageMayHaveChanged(aPresContext); } else if (nsHTMLAtoms::value == aAttribute) { nsAutoString value; aChild->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::value, value); @@ -727,6 +662,9 @@ nsTitledButtonFrame::Reflow(nsIPresContext& aPresContext, const nsHTMLReflowState& aReflowState, nsReflowStatus& aStatus) { + // the list-style-image may have changed. + ImageMayHaveChanged(&aPresContext); + mNeedsLayout = PR_TRUE; nsresult result = nsLeafFrame::Reflow(aPresContext, aMetrics, aReflowState, aStatus); mRenderer.AddFocusBordersAndPadding(aPresContext, aReflowState, aMetrics, mBorderPadding); @@ -1100,6 +1038,74 @@ nsTitledButtonFrame :: ReResolveStyleContext ( nsIPresContext* aPresContext, nsI } // ReResolveStyleContext +void +nsTitledButtonFrame::ImageMayHaveChanged(nsIPresContext* aPresContext) +{ + // see if the source changed + // get the old image src + nsString oldSrc =""; + mImageLoader.GetURLSpec(oldSrc); + + // get the new image src + nsString src = ""; + mContent->GetAttribute(nsXULAtoms::nameSpaceID, nsHTMLAtoms::src, src); + + // if the new image is empty + if (src.Equals("")) { + // get the list-style-image + const nsStyleList* myList = + (const nsStyleList*)mStyleContext->GetStyleData(eStyleStruct_List); + + if (myList->mListStyleImage.Length() > 0) { + src = myList->mListStyleImage; + } + } + + // see if the images are different + if (PR_FALSE == oldSrc.Equals(src)) { + // if they are and the new image is not empty set it and reload + if (PR_FALSE == src.Equals("")) + { + // Get rid of old image loader and start a new image load going + mImageLoader.DestroyLoader(); + + // Fire up a new image load request + PRIntn loadStatus; + + mImageLoader.SetURLSpec(src); + mImageLoader.StartLoadImage(aPresContext, this, nsnull, + PR_FALSE, loadStatus); + + mSizeFrozen = PR_FALSE; + mHasImage = PR_TRUE; + + // If the image is already ready then we need to trigger a + // redraw because the image loader won't. + if (loadStatus & NS_IMAGE_LOAD_STATUS_IMAGE_READY) { + // XXX Stuff this into a method on nsIPresShell/Context + nsRect bounds; + nsPoint offset; + nsIView* view; + GetOffsetFromView(offset, &view); + nsIViewManager* vm; + view->GetViewManager(vm); + bounds.x = offset.x; + bounds.y = offset.y; + bounds.width = mRect.width; + bounds.height = mRect.height; + vm->UpdateView(view, bounds, 0); + NS_RELEASE(vm); + } + } else { + // other wise unset the image. + mSizeFrozen = PR_TRUE; + mHasImage = PR_FALSE; + } + mNeedsLayout = PR_TRUE; + } + +} + /* //---------------------------------------- NS_IMETHODIMP nsTitledButtonFrame::CreateMenu(nsIPopUpMenu * aPopUpMenu, diff --git a/mozilla/layout/xul/base/src/nsTitledButtonFrame.h b/mozilla/layout/xul/base/src/nsTitledButtonFrame.h index a68a5711799..df909b5b274 100644 --- a/mozilla/layout/xul/base/src/nsTitledButtonFrame.h +++ b/mozilla/layout/xul/base/src/nsTitledButtonFrame.h @@ -121,6 +121,7 @@ protected: virtual void setTitle(nsAutoString aTitle); virtual void setAlignment(nsAutoString aAlign); virtual void SetDisabled(nsAutoString aDisabled); + virtual void ImageMayHaveChanged(nsIPresContext* aPresContext); private: diff --git a/mozilla/xpfe/browser/src/xul.css b/mozilla/xpfe/browser/src/xul.css index c122d12ec61..8ef1abd1c1e 100644 --- a/mozilla/xpfe/browser/src/xul.css +++ b/mozilla/xpfe/browser/src/xul.css @@ -61,25 +61,6 @@ observes { display: none; } -titledbutton { - display: inline; - border: 2px outset rgb(156, 154, 156); - background-color: rgb(206, 207, 206); - color:black; -} - -titledbutton.rollover { - border-style: inset; -} - -titledbutton.pressed { - background-color: rgb(220, 207, 206); -} - -titledbutton.disabled { - border-style: solid; -} - progressmeter { display:block; border: black thin groove;