From 9900e1bac0814ae578de9c9dc5214939e807f9a5 Mon Sep 17 00:00:00 2001 From: "pavlov%netscape.com" Date: Sat, 28 Aug 1999 07:49:39 +0000 Subject: [PATCH] honor width and height on the color picker and size intrinsically if thats what you want --- layout/xul/base/src/nsColorPickerFrame.cpp | 105 ++++++++------------- layout/xul/base/src/nsIColorPicker.h | 5 + layout/xul/base/src/nsStdColorPicker.cpp | 22 ++++- 3 files changed, 63 insertions(+), 69 deletions(-) diff --git a/layout/xul/base/src/nsColorPickerFrame.cpp b/layout/xul/base/src/nsColorPickerFrame.cpp index 8ccd029dbcb0..a0017973dc78 100644 --- a/layout/xul/base/src/nsColorPickerFrame.cpp +++ b/layout/xul/base/src/nsColorPickerFrame.cpp @@ -23,6 +23,7 @@ #include "nsIContent.h" #include "prtypes.h" #include "nsIAtom.h" +#include "nsHTMLAtoms.h" #include "nsIPresContext.h" #include "nsIStyleContext.h" #include "nsCSSRendering.h" @@ -57,12 +58,12 @@ static NS_DEFINE_IID(kDefColorPickerCID, NS_DEFCOLORPICKER_CID); // nsColorPickerFrame::nsColorPickerFrame() { - mColorPicker = new nsStdColorPicker(); + } nsColorPickerFrame::~nsColorPickerFrame() { - + delete mColorPicker; } @@ -77,26 +78,18 @@ nsColorPickerFrame::Init(nsIPresContext& aPresContext, nsresult rv = nsLeafFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow); -#if 0 - // get the value - nsAutoString value; - if ((NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::value, value)) && - (value.Length() > 0)) { - setProgress(value); + + nsAutoString type; + mContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::type, type); + + if (type.EqualsIgnoreCase("swatch") || type.Equals("")) + mColorPicker = new nsStdColorPicker(); + if (type.EqualsIgnoreCase("nose")) + { + printf("nose picker!\n"); + mColorPicker = new nsStdColorPicker(); } - - // get the alignment - nsAutoString align; - mContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::align, align); - setAlignment(align); - - // get the mode - nsAutoString mode; - mContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::mode, mode); - setMode(mode); -#endif - return rv; } @@ -166,27 +159,25 @@ nsColorPickerFrame::Paint(nsIPresContext& aPresContext, aWhichLayer); // get our border - const nsStyleSpacing* spacing = - (const nsStyleSpacing*)mStyleContext->GetStyleData(eStyleStruct_Spacing); + const nsStyleSpacing* spacing = (const nsStyleSpacing*)mStyleContext->GetStyleData(eStyleStruct_Spacing); nsMargin border(0,0,0,0); spacing->CalcBorderFor(this, border); - const nsStyleColor* colorStyle = - (const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color); - - nscolor color = colorStyle->mColor; + /* + const nsStyleColor* colorStyle = (const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color); + nscolor color = colorStyle->mColor; + */ aRenderingContext.PushState(); + // set the clip region PRInt32 width, height; - mColorPicker->GetSize(&width, &height); nsRect rect(0, 0, width*p2t, height*p2t); PRBool clipState; // Clip so we don't render outside the inner rect - aRenderingContext.PushState(); aRenderingContext.SetClipRect(rect, nsClipCombine_kIntersect, clipState); // call the color picker's paint method @@ -207,52 +198,36 @@ nsColorPickerFrame::Paint(nsIPresContext& aPresContext, void nsColorPickerFrame::GetDesiredSize(nsIPresContext* aPresContext, const nsHTMLReflowState& aReflowState, - nsHTMLReflowMetrics& aDesiredLayoutSize) + nsHTMLReflowMetrics& aDesiredSize) { float p2t; aPresContext->GetScaledPixelsToTwips(&p2t); - const int CSS_NOTSET = -1; - // const int ATTR_NOTSET = -1; - nsSize styleSize; - if (NS_UNCONSTRAINEDSIZE != aReflowState.mComputedWidth) { - styleSize.width = aReflowState.mComputedWidth; - } - else { - styleSize.width = CSS_NOTSET; - } - if (NS_UNCONSTRAINEDSIZE != aReflowState.mComputedHeight) { - styleSize.height = aReflowState.mComputedHeight; - } - else { - styleSize.height = CSS_NOTSET; - } + // if the width is set use it + if (NS_INTRINSICSIZE != aReflowState.mComputedWidth) + aDesiredSize.width = aReflowState.mComputedWidth; + else + aDesiredSize.width = -1; - // subclasses should always override this method, but if not and no css, make it small - // XXX ??? - /* - aDesiredLayoutSize.width = (styleSize.width > CSS_NOTSET) ? styleSize.width : 200; - aDesiredLayoutSize.height = (styleSize.height > CSS_NOTSET) ? styleSize.height : 200; - aDesiredLayoutSize.ascent = aDesiredLayoutSize.height; - aDesiredLayoutSize.descent = 0; - if (aDesiredLayoutSize.maxElementSize) { - aDesiredLayoutSize.maxElementSize->width = aDesiredLayoutSize.width; - aDesiredLayoutSize.maxElementSize->height = aDesiredLayoutSize.height; - } - */ + // if the height is set use it + if (NS_INTRINSICSIZE != aReflowState.mComputedHeight) + aDesiredSize.height = aReflowState.mComputedHeight; + else + aDesiredSize.height = -1; - PRInt32 width, height; + mColorPicker->SetSize((aDesiredSize.width == -1) ? -1 : aDesiredSize.width/p2t, + (aDesiredSize.height == -1) ? -1 : aDesiredSize.height/p2t); + + int width, height; + mColorPicker->GetSize(&width, &height); - - // convert to twips - - aDesiredLayoutSize.width = nscoord(width * p2t); - aDesiredLayoutSize.height = nscoord(height * p2t); - aDesiredLayoutSize.ascent = nscoord(height * p2t); - aDesiredLayoutSize.descent = 0; - + + aDesiredSize.width = nscoord(width * p2t); + aDesiredSize.height = nscoord(height * p2t); + aDesiredSize.ascent = nscoord(height * p2t); + aDesiredSize.descent = 0; } // GetDesiredSize diff --git a/layout/xul/base/src/nsIColorPicker.h b/layout/xul/base/src/nsIColorPicker.h index a1abcb6132b9..6a5e72672782 100644 --- a/layout/xul/base/src/nsIColorPicker.h +++ b/layout/xul/base/src/nsIColorPicker.h @@ -47,6 +47,9 @@ class nsIColorPicker : public nsISupports { /* void GetColor (in PRInt32 aX, in PRInt32 aY, out string aColor); */ NS_IMETHOD GetColor(PRInt32 aX, PRInt32 aY, char **aColor) = 0; + /* void SetColor (in PRInt32 aWidth, in PRInt32 aHeight); */ + NS_IMETHOD SetSize(PRInt32 aWidth, PRInt32 aHeight) = 0; + /* void GetSize (out PRInt32 aWidth, out PRInt32 aHeight); */ NS_IMETHOD GetSize(PRInt32 *aWidth, PRInt32 *aHeight) = 0; }; @@ -55,12 +58,14 @@ class nsIColorPicker : public nsISupports { #define NS_DECL_NSICOLORPICKER \ NS_IMETHOD Paint(nsIPresContext * aPresContext, nsIRenderingContext * aRenderingContext); \ NS_IMETHOD GetColor(PRInt32 aX, PRInt32 aY, char **aColor); \ + NS_IMETHOD SetSize(PRInt32 aWidth, PRInt32 aHeight); \ NS_IMETHOD GetSize(PRInt32 *aWidth, PRInt32 *aHeight); /* Use this macro to declare functions that forward the behavior of this interface to another object. */ #define NS_FORWARD_NSICOLORPICKER(_to) \ NS_IMETHOD Paint(nsIPresContext * aPresContext, nsIRenderingContext * aRenderingContext) { return _to ## Paint(aPresContext, aRenderingContext); } \ NS_IMETHOD GetColor(PRInt32 aX, PRInt32 aY, char **aColor) { return _to ## GetColor(aX, aY, aColor); } \ + NS_IMETHOD SetSize(PRInt32 aWidth, PRInt32 aHeight) { return _to ## SetSize(aWidth, aHeight); } \ NS_IMETHOD GetSize(PRInt32 *aWidth, PRInt32 *aHeight) { return _to ## GetSize(aWidth, aHeight); } diff --git a/layout/xul/base/src/nsStdColorPicker.cpp b/layout/xul/base/src/nsStdColorPicker.cpp index 47cfd011f5d1..9d86b75b6465 100644 --- a/layout/xul/base/src/nsStdColorPicker.cpp +++ b/layout/xul/base/src/nsStdColorPicker.cpp @@ -50,10 +50,12 @@ NS_IMPL_ISUPPORTS1(nsStdColorPicker, nsIColorPicker) nsStdColorPicker::nsStdColorPicker() { - mNumRows = 0; - mNumCols = 0; + mNumCols = 10; // NSToIntRound(sqrt(nColors)); + mNumRows = NSToIntRound(nColors/mNumCols); + mFrameWidth = 0; mFrameHeight = 0; + mBlockWidth = 20; mBlockHeight = 20; } @@ -117,10 +119,22 @@ NS_IMETHODIMP nsStdColorPicker::GetColor(PRInt32 aX, PRInt32 aY, char **aColor) return NS_OK; } +NS_IMETHODIMP nsStdColorPicker::SetSize(PRInt32 aWidth, PRInt32 aHeight) +{ + mFrameWidth = aWidth; + mFrameHeight = aHeight; + + if (aWidth != -1) + mBlockWidth = NSToIntRound(mFrameWidth / mNumCols); + + if (aWidth != -1) + mBlockHeight = NSToIntRound(mFrameHeight / mNumRows); + + return NS_OK; +} + NS_IMETHODIMP nsStdColorPicker::GetSize(PRInt32 *aWidth, PRInt32 *aHeight) { - mNumCols = 10; // NSToIntRound(sqrt(nColors)); - mNumRows = NSToIntRound(nColors/mNumCols); mFrameWidth = NSToIntRound((mNumCols) * mBlockWidth); mFrameHeight = NSToIntRound((mNumRows) * mBlockHeight);