honor width and height on the color picker and size intrinsically if thats what you want

This commit is contained in:
pavlov%netscape.com 1999-08-28 07:49:39 +00:00
Родитель 22456ab859
Коммит 9900e1bac0
3 изменённых файлов: 63 добавлений и 69 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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); }

Просмотреть файл

@ -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);